Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 52ce3e4

Browse files
author
Charles Marion
committed
STYLE: Fixed some coding style
1 parent 65866f7 commit 52ce3e4

36 files changed

+1799
-1666
lines changed

core/controllers/DownloadController.php

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,107 +5,107 @@
55
*/
66
class DownloadController extends AppController
77
{
8-
public $_models=array("Folder",'Item');
9-
public $_daos=array();
10-
public $_components=array();
8+
public $_models = array("Folder", 'Item');
9+
public $_daos = array();
10+
public $_components = array();
1111

12-
/*index
13-
* @param ?folders=12-13 (will download a zip of the folder 12 and 13 ,recusively)
14-
* @param ?folders=12,1-13,1 (will download a zip of the folder 12 and 13 ,recusively) //Need testing
15-
* @param ?items=12-13 (will download a zip containing the last revisions of the items 12 and 13)
16-
* @param ?items=12,1-13 (will download a zip containing the revision 1 of item 12 and last revision of item 13)
17-
* @param ?items=12,1 (will download the revision 1 of the item 12, a zip if there are multiple bitstream or simply the file)
12+
/** index
13+
* @param ?folders = 12-13 (will download a zip of the folder 12 and 13 ,recusively)
14+
* @param ?folders = 12, 1-13, 1 (will download a zip of the folder 12 and 13 ,recusively) //Need testing
15+
* @param ?items = 12-13 (will download a zip containing the last revisions of the items 12 and 13)
16+
* @param ?items = 12, 1-13 (will download a zip containing the revision 1 of item 12 and last revision of item 13)
17+
* @param ?items = 12, 1 (will download the revision 1 of the item 12, a zip ifthere are multiple bitstream or simply the file)
1818
*/
1919
public function indexAction()
2020
{
2121
set_time_limit(0);
2222
$this->_helper->layout->disableLayout();
23-
$itemIds=$this->_getParam('items');
24-
$folderIds=$this->_getParam('folders');
25-
if(!isset($itemIds)&&!isset($folderIds))
23+
$itemIds = $this->_getParam('items');
24+
$folderIds = $this->_getParam('folders');
25+
if(!isset($itemIds) && !isset($folderIds))
2626
{
2727
throw new Zend_Exception("No parameters");
2828
}
29-
$folderIds=explode('-',$folderIds);
30-
$folders=array();
29+
$folderIds = explode('-', $folderIds);
30+
$folders = array();
3131
foreach($folderIds as $folderId)
3232
{
33-
$tmp=explode(',', $folderId);
33+
$tmp = explode(', ', $folderId);
3434
if(empty($tmp[0]))
3535
{
3636
continue;
3737
}
38-
$folder=$this->Folder->load($tmp[0]);
39-
if($folder==false)
38+
$folder = $this->Folder->load($tmp[0]);
39+
if($folder == false)
4040
{
4141
continue;
4242
}
43-
if(!isset($tmp[0])||$tmp[0]==1)
43+
if(!isset($tmp[0]) || $tmp[0] == 1)
4444
{
45-
$folder->recursive=true;
45+
$folder->recursive = true;
4646
}
4747
else
4848
{
49-
$folder->recursive=false;
49+
$folder->recursive = false;
5050
}
5151
}
52-
$folders= $this->Folder->load($folderIds);
52+
$folders = $this->Folder->load($folderIds);
5353

54-
$itemIds=explode('-',$itemIds);
55-
$revisions=array();
54+
$itemIds = explode('-', $itemIds);
55+
$revisions = array();
5656
if(!empty($itemIds))
5757
{
5858
foreach($itemIds as $itemId)
5959
{
6060
// check revision
61-
$tmp=explode(',', $itemId);
61+
$tmp = explode(', ', $itemId);
6262
if(empty($tmp[0]))
6363
{
6464
continue;
6565
}
66-
$item=$this->Item->load($tmp[0]);
67-
if($item==false||!$this->Item->policyCheck($item,$this->userSession->Dao))
66+
$item = $this->Item->load($tmp[0]);
67+
if($item == false || !$this->Item->policyCheck($item, $this->userSession->Dao))
6868
{
6969
continue;
7070
}
7171
$this->Item->incrementDownloadCount($item);
7272
if(isset($tmp[1]))
7373
{
74-
$tmp=$this->Item->getRevision($item,$tmp[1]);
75-
if($tmp!==false)
74+
$tmp = $this->Item->getRevision($item, $tmp[1]);
75+
if($tmp !== false)
7676
{
77-
$revisions[]=$tmp;
77+
$revisions[] = $tmp;
7878
}
7979
}
8080
else
8181
{
82-
$tmp=$this->Item->getLastRevision($item);
83-
if($tmp!==false)
82+
$tmp = $this->Item->getLastRevision($item);
83+
if($tmp !== false)
8484
{
85-
$revisions[]=$tmp;
85+
$revisions[] = $tmp;
8686
}
8787
}
8888
}
8989
}
9090

91-
if(empty($folders)&&empty($revisions))
91+
if(empty($folders) && empty($revisions))
9292
{
93-
exit();
93+
throw new Zend_Exception("No element");
9494
}
95-
if(empty($folders)&&count($revisions)==1)
95+
if(empty($folders) && count($revisions) == 1)
9696
{
97-
$revision=$revisions[0];
98-
$bitstreams=$revision->getBitstreams();
99-
if(count($bitstreams)==0)
97+
$revision = $revisions[0];
98+
$bitstreams = $revision->getBitstreams();
99+
if(count($bitstreams) == 0)
100100
{
101101
throw new Zend_Exception("Empty item");
102102
}
103-
elseif(count($bitstreams)==1)
103+
elseif(count($bitstreams) == 1)
104104
{
105-
$bitstream=$bitstreams[0];
105+
$bitstream = $bitstreams[0];
106106
$this->view->mimetype = $bitstream->getMimetype();
107107
$this->view->path = $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath();
108-
$this->view->name =$bitstream->getName();
108+
$this->view->name = $bitstream->getName();
109109
if(!file_exists($this->view->path))
110110
{
111111
throw new Zend_Exception("Unable to find file on the disk");
@@ -114,12 +114,12 @@ public function indexAction()
114114
}
115115
else
116116
{
117-
Zend_Loader::loadClass("ZipStream",BASE_PATH.'/library/ZipStream/');
117+
Zend_Loader::loadClass("ZipStream", BASE_PATH.'/library/ZipStream/');
118118
$this->_helper->viewRenderer->setNoRender();
119-
$name=$revision->getItem()->getName();
120-
$name=substr($name, 0,50);
119+
$name = $revision->getItem()->getName();
120+
$name = substr($name, 0, 50);
121121
$zip = new ZipStream($name.'.zip');
122-
foreach ($bitstreams as $bitstream)
122+
foreach($bitstreams as $bitstream)
123123
{
124124
$zip->add_file_from_path($bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath());
125125
}
@@ -128,69 +128,69 @@ public function indexAction()
128128
}
129129
else
130130
{
131-
Zend_Loader::loadClass("ZipStream",BASE_PATH.'/library/ZipStream/');
131+
Zend_Loader::loadClass("ZipStream", BASE_PATH.'/library/ZipStream/');
132132
$this->_helper->viewRenderer->setNoRender();
133-
if(count($folders)==1&&empty($revisions))
133+
if(count($folders) == 1 && empty($revisions))
134134
{
135-
$name=$folders[0]->getName();
136-
$name=substr($name, 0,50);
135+
$name = $folders[0]->getName();
136+
$name = substr($name, 0, 50);
137137
}
138138
else
139139
{
140-
$name="Custom";
140+
$name = "Custom";
141141
}
142142
$zip = new ZipStream($name.'.zip');
143-
$zip=$this->createZipRecursive($zip,'',$folders,$revisions);
143+
$zip = $this->_createZipRecursive($zip, '', $folders, $revisions);
144144
$zip->finish();
145145
}
146-
}//end index
146+
}//end index
147147

148-
/** create zip recursive*/
149-
private function createZipRecursive($zip,$path,$folders,$revisions)
150-
{
151-
foreach($revisions as $revision)
152-
{
153-
$bitstreams=$revision->getBitstreams();
154-
foreach ($bitstreams as $bitstream)
148+
/** create zip recursive*/
149+
private function _createZipRecursive($zip, $path, $folders, $revisions)
150+
{
151+
foreach($revisions as $revision)
152+
{
153+
$bitstreams = $revision->getBitstreams();
154+
foreach($bitstreams as $bitstream)
155155
{
156156
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath());
157157
}
158-
}
159-
foreach($folders as $folder)
160-
{
161-
if(!$this->Folder->policyCheck($folder,$this->userSession->Dao))
162-
{
163-
continue;
164-
}
165-
$items=$folder->getItems();
166-
$subRevisions=array();
167-
foreach($items as $item)
158+
}
159+
foreach($folders as $folder)
160+
{
161+
if(!$this->Folder->policyCheck($folder, $this->userSession->Dao))
168162
{
169-
if(!$this->Item->policyCheck($item,$this->userSession->Dao))
163+
continue;
164+
}
165+
$items = $folder->getItems();
166+
$subRevisions = array();
167+
foreach($items as $item)
168+
{
169+
if(!$this->Item->policyCheck($item, $this->userSession->Dao))
170170
{
171171
continue;
172172
}
173-
$tmp=$this->Item->getLastRevision($item);
174-
if($tmp!==false)
173+
$tmp = $this->Item->getLastRevision($item);
174+
if($tmp !== false)
175175
{
176-
$subRevisions[]=$tmp;
177-
if(isset($folder->recursive)&&$folder->recursive==false)
176+
$subRevisions[] = $tmp;
177+
if(isset($folder->recursive) && $folder->recursive == false)
178178
{
179-
$bitstreams=$subRevisions->getBitstreams();
180-
foreach ($bitstreams as $bitstream)
179+
$bitstreams = $subRevisions->getBitstreams();
180+
foreach($bitstreams as $bitstream)
181181
{
182182
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'. $bitstream->getPath());
183183
}
184184
}
185185
}
186186
}
187-
if(!isset($folder->recursive)||$folder->recursive)
188-
{
189-
$zip=$this->createZipRecursive($zip,$path.'/'.$folder->getName(),$folder->getFolders(),$subRevisions);
190-
}
191-
}
192-
return $zip;
193-
}
187+
if(!isset($folder->recursive) || $folder->recursive)
188+
{
189+
$zip = $this->_createZipRecursive($zip, $path.'/'.$folder->getName(), $folder->getFolders(), $subRevisions);
190+
}
191+
}
192+
return $zip;
193+
}
194194
} // end class
195195

196196

0 commit comments

Comments
 (0)