|
1 |
| -<?php |
2 |
| - |
3 |
| -/** |
4 |
| - * AJAX request for the admin Controller |
5 |
| - */ |
6 |
| -class BrowseController extends AppController |
7 |
| -{ |
8 |
| - public $_models=array('Folder','User','Community','Folder','Item'); |
9 |
| - public $_daos=array('Folder','User','Community','Folder','Item'); |
10 |
| - public $_components=array(); |
11 |
| - |
12 |
| - /** Init Controller */ |
13 |
| - function init() |
14 |
| - { |
15 |
| - $this->view->activemenu = 'browse'; // set the active menu |
16 |
| - } // end init() |
17 |
| - |
18 |
| - /** Index Action*/ |
19 |
| - public function indexAction() |
20 |
| - { |
21 |
| - $communities=array(); |
22 |
| - $items=array(); |
23 |
| - $header=""; |
24 |
| - |
25 |
| - $communities=$this->User->getUserCommunities($this->userSession->Dao); |
26 |
| - $header.="> Data"; |
27 |
| - |
28 |
| - $this->view->communities=$communities; |
29 |
| - $this->view->header=substr($header,2); |
30 |
| - |
31 |
| - $javascriptText=array(); |
32 |
| - $javascriptText['view']=$this->t('View'); |
33 |
| - $javascriptText['edit']=$this->t('Edit'); |
34 |
| - $javascriptText['delete']=$this->t('Delete'); |
35 |
| - $javascriptText['share']=$this->t('Share'); |
36 |
| - $javascriptText['rename']=$this->t('Rename'); |
37 |
| - $javascriptText['move']=$this->t('Move'); |
38 |
| - $javascriptText['copy']=$this->t('Copy'); |
39 |
| - |
40 |
| - $javascriptText['community']['invit']=$this->t('Invite collaborators'); |
41 |
| - $javascriptText['community']['advanced']=$this->t('Advanced properties'); |
42 |
| - $this->view->json['browse']=$javascriptText; |
43 |
| - } |
44 |
| - |
45 |
| - /** get getfolders content (ajax function for the treetable) */ |
46 |
| - public function getfolderscontentAction() |
47 |
| - { |
48 |
| - if(!$this->getRequest()->isXmlHttpRequest()) |
49 |
| - { |
50 |
| - throw new Zend_Exception("Why are you here ? Should be ajax."); |
51 |
| - } |
52 |
| - $this->_helper->layout->disableLayout(); |
53 |
| - $this->_helper->viewRenderer->setNoRender(); |
54 |
| - $folderIds=$this->_getParam('folders'); |
55 |
| - if(!isset($folderIds)) |
56 |
| - { |
57 |
| - throw new Zend_Exception("Please set the folder Id"); |
58 |
| - } |
59 |
| - $folderIds=explode('-',$folderIds); |
60 |
| - $parents= $this->Folder->load($folderIds); |
61 |
| - if(empty($parents)) |
62 |
| - { |
63 |
| - throw new Zend_Exception("Folder doesn't exist"); |
64 |
| - } |
65 |
| - $folders=$this->Folder->getChildrenFoldersFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ); |
66 |
| - $items=$this->Folder->getItemsFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ); |
67 |
| - $jsonContent=array(); |
68 |
| - foreach ($folders as $folder) |
69 |
| - { |
70 |
| - $tmp=array(); |
71 |
| - $tmp['folder_id']=$folder->getFolderId(); |
72 |
| - $tmp['name']=$folder->getName(); |
73 |
| - $jsonContent[$folder->getParentId()]['folders'][]=$tmp; |
74 |
| - unset($tmp); |
75 |
| - } |
76 |
| - foreach ($items as $item) |
77 |
| - { |
78 |
| - $tmp=array(); |
79 |
| - $tmp['item_id']=$item->getItemId(); |
80 |
| - $tmp['name']=$item->getName(); |
81 |
| - $tmp['parent_id']=$item->parent_id; |
82 |
| - $jsonContent[$item->parent_id]['items'][]=$tmp; |
83 |
| - unset($tmp); |
84 |
| - } |
85 |
| - echo JsonComponent::encode($jsonContent); |
86 |
| - }//end getfolderscontent |
87 |
| - |
88 |
| - /** get element info (ajax function for the treetable) */ |
89 |
| - public function getelementinfoAction() |
90 |
| - { |
91 |
| - if(!$this->getRequest()->isXmlHttpRequest()) |
92 |
| - { |
93 |
| - throw new Zend_Exception("Why are you here ? Should be ajax."); |
94 |
| - } |
95 |
| - $this->_helper->layout->disableLayout(); |
96 |
| - $this->_helper->viewRenderer->setNoRender(); |
97 |
| - $element=$this->_getParam('type'); |
98 |
| - $id=$this->_getParam('id'); |
99 |
| - if(!isset($id)||!isset($element)) |
100 |
| - { |
101 |
| - throw new Zend_Exception("Please double check the parameters"); |
102 |
| - } |
103 |
| - $jsonContent=array('type'=>$element); |
104 |
| - switch ($element) |
105 |
| - { |
106 |
| - case 'community': |
107 |
| - $community=$this->Community->load($id); |
108 |
| - $jsonContent=array_merge($jsonContent,$community->_toArray()); |
109 |
| - break; |
110 |
| - case 'folder': |
111 |
| - $folder=$this->Folder->load($id); |
112 |
| - $jsonContent=array_merge($jsonContent,$folder->_toArray()); |
113 |
| - $jsonContent['creation']=$jsonContent['date']; |
114 |
| - break; |
115 |
| - case 'item': |
116 |
| - $item=$this->Item->load($id); |
117 |
| - $jsonContent=array_merge($jsonContent,$item->_toArray()); |
118 |
| - $itemRevision=$this->Item->getLastRevision($item); |
119 |
| - $jsonContent['creation']=$itemRevision->getDate(); |
120 |
| - break; |
121 |
| - default: |
122 |
| - throw new Zend_Exception("Please select the right type of element."); |
123 |
| - break; |
124 |
| - } |
125 |
| - $jsonContent['translation']['Created']=$this->t('Created'); |
126 |
| - echo JsonComponent::encode($jsonContent); |
127 |
| - }//end getElementInfo |
128 |
| - |
129 |
| - |
130 |
| - /** review (browse) uploaded files*/ |
131 |
| - public function uploadedAction() |
132 |
| - { |
133 |
| - if(empty($this->userSession->uploaded)||!$this->logged) |
134 |
| - { |
135 |
| - $this->_redirect('/'); |
136 |
| - } |
137 |
| - $this->view->items=array(); |
138 |
| - foreach($this->userSession->uploaded as $item) |
139 |
| - { |
140 |
| - $this->view->items[]=$this->Item->load($item); |
141 |
| - } |
142 |
| - } |
143 |
| -} // end class |
144 |
| - |
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * AJAX request for the admin Controller |
| 5 | + */ |
| 6 | +class BrowseController extends AppController |
| 7 | +{ |
| 8 | + public $_models=array('Folder','User','Community','Folder','Item'); |
| 9 | + public $_daos=array('Folder','User','Community','Folder','Item'); |
| 10 | + public $_components=array('Date','Utility'); |
| 11 | + |
| 12 | + /** Init Controller */ |
| 13 | + function init() |
| 14 | + { |
| 15 | + $this->view->activemenu = 'browse'; // set the active menu |
| 16 | + } // end init() |
| 17 | + |
| 18 | + /** Index Action*/ |
| 19 | + public function indexAction() |
| 20 | + { |
| 21 | + $communities=array(); |
| 22 | + $items=array(); |
| 23 | + $header=""; |
| 24 | + |
| 25 | + $communities=$this->User->getUserCommunities($this->userSession->Dao); |
| 26 | + $header.="> Data"; |
| 27 | + |
| 28 | + $this->view->Date=$this->Component->Date; |
| 29 | + |
| 30 | + $this->view->communities=$communities; |
| 31 | + $this->view->header=substr($header,2); |
| 32 | + |
| 33 | + $javascriptText=array(); |
| 34 | + $javascriptText['view']=$this->t('View'); |
| 35 | + $javascriptText['edit']=$this->t('Edit'); |
| 36 | + $javascriptText['delete']=$this->t('Delete'); |
| 37 | + $javascriptText['share']=$this->t('Share'); |
| 38 | + $javascriptText['rename']=$this->t('Rename'); |
| 39 | + $javascriptText['move']=$this->t('Move'); |
| 40 | + $javascriptText['copy']=$this->t('Copy'); |
| 41 | + |
| 42 | + $javascriptText['community']['invit']=$this->t('Invite collaborators'); |
| 43 | + $javascriptText['community']['advanced']=$this->t('Advanced properties'); |
| 44 | + $this->view->json['browse']=$javascriptText; |
| 45 | + } |
| 46 | + |
| 47 | + /** get getfolders content (ajax function for the treetable) */ |
| 48 | + public function getfolderscontentAction() |
| 49 | + { |
| 50 | + if(!$this->getRequest()->isXmlHttpRequest()) |
| 51 | + { |
| 52 | + throw new Zend_Exception("Why are you here ? Should be ajax."); |
| 53 | + } |
| 54 | + $this->_helper->layout->disableLayout(); |
| 55 | + $this->_helper->viewRenderer->setNoRender(); |
| 56 | + $folderIds=$this->_getParam('folders'); |
| 57 | + if(!isset($folderIds)) |
| 58 | + { |
| 59 | + throw new Zend_Exception("Please set the folder Id"); |
| 60 | + } |
| 61 | + $folderIds=explode('-',$folderIds); |
| 62 | + $parents= $this->Folder->load($folderIds); |
| 63 | + if(empty($parents)) |
| 64 | + { |
| 65 | + throw new Zend_Exception("Folder doesn't exist"); |
| 66 | + } |
| 67 | + $folders=$this->Folder->getChildrenFoldersFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ); |
| 68 | + $items=$this->Folder->getItemsFiltered($parents,$this->userSession->Dao,MIDAS_POLICY_READ); |
| 69 | + $jsonContent=array(); |
| 70 | + foreach ($folders as $folder) |
| 71 | + { |
| 72 | + $tmp=array(); |
| 73 | + $tmp['folder_id']=$folder->getFolderId(); |
| 74 | + $tmp['name']=$folder->getName(); |
| 75 | + $tmp['creation']=$this->Component->Date->ago($folder->getDate(),true); |
| 76 | + $jsonContent[$folder->getParentId()]['folders'][]=$tmp; |
| 77 | + unset($tmp); |
| 78 | + } |
| 79 | + foreach ($items as $item) |
| 80 | + { |
| 81 | + $tmp=array(); |
| 82 | + $tmp['item_id']=$item->getItemId(); |
| 83 | + $tmp['name']=$item->getName(); |
| 84 | + $tmp['parent_id']=$item->parent_id; |
| 85 | + $itemRevision=$this->Item->getLastRevision($item); |
| 86 | + $tmp['creation']=$this->Component->Date->ago($itemRevision->getDate(),true); |
| 87 | + $tmp['size']=$this->Component->Utility->formatSize($item->getSizebytes()); |
| 88 | + $jsonContent[$item->parent_id]['items'][]=$tmp; |
| 89 | + unset($tmp); |
| 90 | + } |
| 91 | + echo JsonComponent::encode($jsonContent); |
| 92 | + }//end getfolderscontent |
| 93 | + |
| 94 | + /** get getfolders Items' size */ |
| 95 | + public function getfolderssizeAction() |
| 96 | + { |
| 97 | + if(!$this->getRequest()->isXmlHttpRequest()) |
| 98 | + { |
| 99 | + throw new Zend_Exception("Why are you here ? Should be ajax."); |
| 100 | + } |
| 101 | + |
| 102 | + $this->_helper->layout->disableLayout(); |
| 103 | + $this->_helper->viewRenderer->setNoRender(); |
| 104 | + $folderIds=$this->_getParam('folders'); |
| 105 | + if(!isset($folderIds)) |
| 106 | + { |
| 107 | + throw new Zend_Exception("Please set the folder Id"); |
| 108 | + } |
| 109 | + $folderIds=explode('-',$folderIds); |
| 110 | + $folders= $this->Folder->load($folderIds); |
| 111 | + $folders=$this->Folder->getSizeFiltered($folders,$this->userSession->Dao); |
| 112 | + $return=array(); |
| 113 | + foreach($folders as $folder) |
| 114 | + { |
| 115 | + $return[]=array('id'=>$folder->getKey(),'count'=>$folder->count,'size'=>$this->Component->Utility->formatSize($folder->size)); |
| 116 | + } |
| 117 | + echo JsonComponent::encode($return); |
| 118 | + }//end getfolderscontent |
| 119 | + |
| 120 | + /** get element info (ajax function for the treetable) */ |
| 121 | + public function getelementinfoAction() |
| 122 | + { |
| 123 | + if(!$this->getRequest()->isXmlHttpRequest()) |
| 124 | + { |
| 125 | + throw new Zend_Exception("Why are you here ? Should be ajax."); |
| 126 | + } |
| 127 | + $this->_helper->layout->disableLayout(); |
| 128 | + $this->_helper->viewRenderer->setNoRender(); |
| 129 | + $element=$this->_getParam('type'); |
| 130 | + $id=$this->_getParam('id'); |
| 131 | + if(!isset($id)||!isset($element)) |
| 132 | + { |
| 133 | + throw new Zend_Exception("Please double check the parameters"); |
| 134 | + } |
| 135 | + $jsonContent=array('type'=>$element); |
| 136 | + switch ($element) |
| 137 | + { |
| 138 | + case 'community': |
| 139 | + $community=$this->Community->load($id); |
| 140 | + $jsonContent=array_merge($jsonContent,$community->_toArray()); |
| 141 | + break; |
| 142 | + case 'folder': |
| 143 | + $folder=$this->Folder->load($id); |
| 144 | + $jsonContent=array_merge($jsonContent,$folder->_toArray()); |
| 145 | + $jsonContent['creation']=$jsonContent['date']; |
| 146 | + break; |
| 147 | + case 'item': |
| 148 | + $item=$this->Item->load($id); |
| 149 | + $jsonContent=array_merge($jsonContent,$item->_toArray()); |
| 150 | + $itemRevision=$this->Item->getLastRevision($item); |
| 151 | + $jsonContent['creation']=$itemRevision->getDate(); |
| 152 | + break; |
| 153 | + default: |
| 154 | + throw new Zend_Exception("Please select the right type of element."); |
| 155 | + break; |
| 156 | + } |
| 157 | + $jsonContent['translation']['Created']=$this->t('Created'); |
| 158 | + echo JsonComponent::encode($jsonContent); |
| 159 | + }//end getElementInfo |
| 160 | + |
| 161 | + |
| 162 | + /** review (browse) uploaded files*/ |
| 163 | + public function uploadedAction() |
| 164 | + { |
| 165 | + if(empty($this->userSession->uploaded)||!$this->logged) |
| 166 | + { |
| 167 | + $this->_redirect('/'); |
| 168 | + } |
| 169 | + $this->view->items=array(); |
| 170 | + foreach($this->userSession->uploaded as $item) |
| 171 | + { |
| 172 | + $this->view->items[]=$this->Item->load($item); |
| 173 | + } |
| 174 | + } |
| 175 | +} // end class |
| 176 | + |
0 commit comments