10 namespace Fossology\Reuser;
15 use Symfony\Component\HttpFoundation\JsonResponse;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
19 include_once(__DIR__ .
"/../agent/version.php");
27 const NAME =
"plugin_reuser";
42 public function __construct()
44 parent::__construct(self::NAME, array(
45 self::TITLE => _(
"Automatic Clearing Decision Reuser"),
49 $this->folderDao = $this->
getObject(
'dao.folder');
61 $allFolder = $this->folderDao->getAllFolderIds();
63 for ($i=0; $i <
sizeof($allFolder); $i++) {
65 foreach ($listObject as $key => $value) {
66 $result[explode(
",",$key)[0]] = $value;
76 protected function handle(Request $request)
78 $this->folderDao->ensureTopLevelFolder();
80 $ajaxMethodName = $request->get(
'do');
82 if ($ajaxMethodName ==
"getUploads") {
84 if (empty($folderId) || empty($trustGroupId)) {
89 return new JsonResponse($uploadsById, JsonResponse::HTTP_OK);
92 return new Response(
'called without valid method', Response::HTTP_METHOD_NOT_ALLOWED);
102 $folderGroupPair = explode(
',', $folderGroup,2);
103 if (count($folderGroupPair) == 2) {
104 list($folder, $trustGroup) = $folderGroupPair;
105 $folderId = intval($folder);
106 $trustGroupId = intval($trustGroup);
111 return array($folderId, $trustGroupId);
121 if (!array_key_exists(
'folderStructure', $vars)) {
122 $rootFolderId = $this->folderDao->getRootFolder(
Auth::getUserId())->getId();
123 $vars[
'folderStructure'] = $this->folderDao->getFolderStructure($rootFolderId);
125 if ($this->folderDao->isWithoutReusableFolders($vars[
'folderStructure'])) {
131 if (empty($folderId) && !empty($vars[
'folderStructure'])) {
132 $folderId = $vars[
'folderStructure'][0][FolderDao::FOLDER_KEY]->getId();
140 $renderer = $this->
getObject(
'twig.environment');
141 return $renderer->load(
'agent_reuser.html.twig')->render($vars);
154 $renderer = $this->
getObject(
'twig.environment');
155 return $renderer->load(
'agent_reuser.js.twig')->render($vars);
169 if (empty($trustGroupId)) {
172 $folderUploads = $this->folderDao->getFolderUploads($folderId, $trustGroupId);
174 $uploadsById = array();
175 foreach ($folderUploads as $uploadProgress) {
176 $key = $uploadProgress->getId().
','.$uploadProgress->getGroupId();
177 $display = $uploadProgress->getFilename() . _(
" from ")
179 .
' ('. $uploadProgress->getStatusString() .
')';
180 $uploadsById[$key] = $display;
186 register_plugin(
new ReuserPlugin());
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
getFolderIdAndTrustGroup($folderGroup)
For a given folder group, extract forder id and trust group id.
renderFoot(&$vars)
Render footer template.
const REUSE_FOLDER_SELECTOR_NAME
Reuse upload folder element name.
renderContent(&$vars)
Load the data in array and render twig template.
const FOLDER_PARAMETER_NAME
Folder parameter HTML element name.
prepareFolderUploads($folderId, $trustGroupId=null)
For a given folder id, collect all uploads.
getAllUploads()
Get all uploads accessible to curent user.
const UPLOAD_TO_REUSE_SELECTOR_NAME
Upload to reuse HTML element name.
Convert2BrowserTime($server_time)
Convert the server time to browser time.
list_t type structure used to keep various lists. (e.g. there are multiple lists).