FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
AjaxFolderContents.php
1 <?php
2 /***********************************************************
3  * Copyright (C) 2015 Siemens AG
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
19 namespace Fossology\UI\Ajax;
20 
27 
29 {
30  const NAME = "foldercontents";
31 
32  function __construct()
33  {
34  parent::__construct(self::NAME, array(
35  self::PERMISSION => Auth::PERM_WRITE
36  ));
37  }
38 
39  protected function handle(Request $request)
40  {
41  $folderId = intval($request->get('folder'));
42  /* @var $folderDao FolderDao */
43  $folderDao = $this->getObject('dao.folder');
44  $results = array();
45  $childFolders = $folderDao->getFolderChildFolders($folderId);
46  foreach ($childFolders as $folder) {
47  $results[$folder['foldercontents_pk']] = '/'.$folder['folder_name'];
48  }
49  $childUploads = $folderDao->getFolderChildUploads($folderId, Auth::getGroupId());
50  foreach ($childUploads as $upload) {
51  $uploadStatus = new UploadStatus();
52  $uploadDate = explode(".",$upload['upload_ts'])[0];
53  $uploadStatus = " (" . $uploadStatus->getTypeName($upload['status_fk']) . ")";
54  $results[$upload['foldercontents_pk']] = $upload['upload_filename'] . _(" from ") . Convert2BrowserTime($uploadDate) . $uploadStatus;
55  }
56 
57  if (!$request->get('removable')) {
58  return new JsonResponse($results);
59  }
60 
61  $filterResults = array();
62  foreach ($folderDao->getRemovableContents($folderId) as $content) {
63  $filterResults[$content] = $results[$content];
64  }
65  if (empty($filterResults)) {
66  $filterResults["-1"] = "No removable content found";
67  }
68  return new JsonResponse($filterResults);
69  }
70 }
71 
72 register_plugin(new AjaxFolderContents());
Convert2BrowserTime($server_time)
Convert the server time to browser time.
Definition: common-ui.php:298
static getGroupId()
Get the current user&#39;s group id.
Definition: Auth.php:78