30 include_once(__DIR__ .
"/../agent/version.php");
38 const NAME =
"plugin_reuser";
53 public function __construct()
55 parent::__construct(self::NAME, array(
56 self::TITLE => _(
"Automatic Clearing Decision Reuser"),
60 $this->folderDao = $this->
getObject(
'dao.folder');
72 $allFolder = $this->folderDao->getAllFolderIds();
74 for ($i=0; $i <
sizeof($allFolder); $i++) {
76 foreach ($listObject as $key => $value) {
77 $result[explode(
",",$key)[0]] = $value;
87 protected function handle(Request $request)
89 $this->folderDao->ensureTopLevelFolder();
91 $ajaxMethodName = $request->get(
'do');
93 if ($ajaxMethodName ==
"getUploads") {
95 if (empty($folderId) || empty($trustGroupId)) {
100 return new JsonResponse($uploadsById, JsonResponse::HTTP_OK);
103 return new Response(
'called without valid method', Response::HTTP_METHOD_NOT_ALLOWED);
113 $folderGroupPair = explode(
',', $folderGroup,2);
114 if (count($folderGroupPair) == 2) {
115 list($folder, $trustGroup) = $folderGroupPair;
116 $folderId = intval($folder);
117 $trustGroupId = intval($trustGroup);
122 return array($folderId, $trustGroupId);
132 if (!array_key_exists(
'folderStructure', $vars)) {
133 $rootFolderId = $this->folderDao->getRootFolder(
Auth::getUserId())->getId();
134 $vars[
'folderStructure'] = $this->folderDao->getFolderStructure($rootFolderId);
136 if ($this->folderDao->isWithoutReusableFolders($vars[
'folderStructure'])) {
139 $pair = array_key_exists(self::FOLDER_PARAMETER_NAME, $vars) ? $vars[self::FOLDER_PARAMETER_NAME] :
'';
142 if (empty($folderId) && !empty($vars[
'folderStructure'])) {
143 $folderId = $vars[
'folderStructure'][0][FolderDao::FOLDER_KEY]->getId();
146 $vars[
'reuseFolderSelectorName'] = self::REUSE_FOLDER_SELECTOR_NAME;
147 $vars[
'folderParameterName'] = self::FOLDER_PARAMETER_NAME;
148 $vars[
'uploadToReuseSelectorName'] = self::UPLOAD_TO_REUSE_SELECTOR_NAME;
151 $renderer = $this->
getObject(
'twig.environment');
152 return $renderer->loadTemplate(
'agent_reuser.html.twig')->render($vars);
162 $vars[
'reuseFolderSelectorName'] = self::REUSE_FOLDER_SELECTOR_NAME;
163 $vars[
'folderParameterName'] = self::FOLDER_PARAMETER_NAME;
164 $vars[
'uploadToReuseSelectorName'] = self::UPLOAD_TO_REUSE_SELECTOR_NAME;
165 $renderer = $this->
getObject(
'twig.environment');
166 return $renderer->loadTemplate(
'agent_reuser.js.twig')->render($vars);
180 if (empty($trustGroupId)) {
183 $folderUploads = $this->folderDao->getFolderUploads($folderId, $trustGroupId);
185 $uploadsById = array();
186 foreach ($folderUploads as $uploadProgress) {
187 $key = $uploadProgress->getId().
','.$uploadProgress->getGroupId();
188 $display = $uploadProgress->getFilename() . _(
" from ")
190 .
' ('. $uploadProgress->getStatusString() .
')';
191 $uploadsById[$key] = $display;
getAllUploads()
Get all uploads accessible to curent user.
static getUserId()
Get the current user's id.
renderContent(&$vars)
Load the data in array and render twig template.
renderFoot(&$vars)
Render footer template.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
const FOLDER_PARAMETER_NAME
Folder parameter HTML element name.
const UPLOAD_TO_REUSE_SELECTOR_NAME
Upload to reuse HTML element name.
prepareFolderUploads($folderId, $trustGroupId=null)
For a given folder id, collect all uploads.
const REUSE_FOLDER_SELECTOR_NAME
Reuse upload folder element name.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
static getGroupId()
Get the current user's group id.
getFolderIdAndTrustGroup($folderGroup)
For a given folder group, extract forder id and trust group id.