FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
AdminContentMove.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 
24 
26 {
27  const NAME = 'content_move';
28 
30  private $folderDao;
31 
32  function __construct()
33  {
34  parent::__construct(self::NAME, array(
35  self::TITLE => _("Move upload or folder"),
36  self::MENU_LIST => "Organize::Folders::Move or Copy",
37  self::PERMISSION => Auth::PERM_WRITE,
38  self::REQUIRES_LOGIN => TRUE
39  ));
40  $this->folderDao = $this->getObject('dao.folder');
41  }
42 
43  protected function RegisterMenus()
44  {
45  parent::RegisterMenus();
46  if (!$this->isRequiresLogin() || $this->isLoggedIn()) {
47  menu_insert("Main::Organize::Uploads::Move or Copy", 0, $this->name, $this->name);
48  }
49  }
50 
55  protected function handle(Request $request)
56  {
57  $userId = Auth::getUserId();
58  $vars = array();
59 
60  $folderContentIds = $request->get('foldercontent', array());
61  $parentFolderId = intval($request->get('toFolder'));
62  $isCopyRequest = $request->get('copy');
63 
64  $vars['message'] = $this->performAction($folderContentIds, $parentFolderId, $isCopyRequest);
65 
66  $rootFolderId = $this->folderDao->getRootFolder($userId)->getId();
67  /* @var $uiFolderNav FolderNav */
68  $uiFolderNav = $this->getObject('ui.folder.nav');
69  $vars['folderTree'] = $uiFolderNav->showFolderTree($rootFolderId);
70  $vars['folderStructure'] = $this->folderDao->getFolderStructure($rootFolderId);
71  return $this->render('admin_content_move.html.twig', $this->mergeWithDefault($vars));
72  }
73 
81  private function performAction($folderContentIds, $parentFolderId, $isCopyRequest)
82  {
83  $message = "";
84  for ($i = 0; $i < sizeof($folderContentIds); $i++) {
85  $folderContentId = intval($folderContentIds[$i]);
86  if ($folderContentId && $parentFolderId && $isCopyRequest) {
87  try {
88  $this->folderDao->copyContent($folderContentId, $parentFolderId);
89  } catch (Exception $ex) {
90  $message .= $ex->getMessage();
91  }
92  } elseif ($folderContentId && $parentFolderId) {
93  try {
94  $this->folderDao->moveContent($folderContentId, $parentFolderId);
95  } catch (Exception $ex) {
96  $message .= $ex->getMessage();
97  }
98  }
99  }
100  return $message;
101  }
102 
111  public function copyContent($uploadIds, $parentFolderId, $isCopyRequest)
112  {
113  return $this->performAction($uploadIds, $parentFolderId, $isCopyRequest);
114  }
115 }
116 
117 register_plugin(new AdminContentMove());
performAction($folderContentIds, $parentFolderId, $isCopyRequest)
render($templateName, $vars=null, $headers=null)
handle(Request $request)
copyContent($uploadIds, $parentFolderId, $isCopyRequest)
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item...
#define PERM_WRITE
Read-Write permission.
Definition: libfossology.h:45