5
5
*/
6
6
class DownloadController extends AppController
7
7
{
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 ();
11
11
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)
18
18
*/
19
19
public function indexAction ()
20
20
{
21
21
set_time_limit (0 );
22
22
$ 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 ))
26
26
{
27
27
throw new Zend_Exception ("No parameters " );
28
28
}
29
- $ folderIds= explode ('- ' ,$ folderIds );
30
- $ folders= array ();
29
+ $ folderIds = explode ('- ' , $ folderIds );
30
+ $ folders = array ();
31
31
foreach ($ folderIds as $ folderId )
32
32
{
33
- $ tmp= explode (', ' , $ folderId );
33
+ $ tmp = explode (', ' , $ folderId );
34
34
if (empty ($ tmp [0 ]))
35
35
{
36
36
continue ;
37
37
}
38
- $ folder= $ this ->Folder ->load ($ tmp [0 ]);
39
- if ($ folder== false )
38
+ $ folder = $ this ->Folder ->load ($ tmp [0 ]);
39
+ if ($ folder == false )
40
40
{
41
41
continue ;
42
42
}
43
- if (!isset ($ tmp [0 ])|| $ tmp [0 ]== 1 )
43
+ if (!isset ($ tmp [0 ]) || $ tmp [0 ] == 1 )
44
44
{
45
- $ folder ->recursive = true ;
45
+ $ folder ->recursive = true ;
46
46
}
47
47
else
48
48
{
49
- $ folder ->recursive = false ;
49
+ $ folder ->recursive = false ;
50
50
}
51
51
}
52
- $ folders = $ this ->Folder ->load ($ folderIds );
52
+ $ folders = $ this ->Folder ->load ($ folderIds );
53
53
54
- $ itemIds= explode ('- ' ,$ itemIds );
55
- $ revisions= array ();
54
+ $ itemIds = explode ('- ' , $ itemIds );
55
+ $ revisions = array ();
56
56
if (!empty ($ itemIds ))
57
57
{
58
58
foreach ($ itemIds as $ itemId )
59
59
{
60
60
// check revision
61
- $ tmp= explode (', ' , $ itemId );
61
+ $ tmp = explode (', ' , $ itemId );
62
62
if (empty ($ tmp [0 ]))
63
63
{
64
64
continue ;
65
65
}
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 ))
68
68
{
69
69
continue ;
70
70
}
71
71
$ this ->Item ->incrementDownloadCount ($ item );
72
72
if (isset ($ tmp [1 ]))
73
73
{
74
- $ tmp= $ this ->Item ->getRevision ($ item ,$ tmp [1 ]);
75
- if ($ tmp !==false )
74
+ $ tmp = $ this ->Item ->getRevision ($ item , $ tmp [1 ]);
75
+ if ($ tmp !== false )
76
76
{
77
- $ revisions []= $ tmp ;
77
+ $ revisions [] = $ tmp ;
78
78
}
79
79
}
80
80
else
81
81
{
82
- $ tmp= $ this ->Item ->getLastRevision ($ item );
83
- if ($ tmp !==false )
82
+ $ tmp = $ this ->Item ->getLastRevision ($ item );
83
+ if ($ tmp !== false )
84
84
{
85
- $ revisions []= $ tmp ;
85
+ $ revisions [] = $ tmp ;
86
86
}
87
87
}
88
88
}
89
89
}
90
90
91
- if (empty ($ folders )&& empty ($ revisions ))
91
+ if (empty ($ folders ) && empty ($ revisions ))
92
92
{
93
- exit ( );
93
+ throw new Zend_Exception ( " No element " );
94
94
}
95
- if (empty ($ folders )&& count ($ revisions )== 1 )
95
+ if (empty ($ folders ) && count ($ revisions ) == 1 )
96
96
{
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 )
100
100
{
101
101
throw new Zend_Exception ("Empty item " );
102
102
}
103
- elseif (count ($ bitstreams )== 1 )
103
+ elseif (count ($ bitstreams ) == 1 )
104
104
{
105
- $ bitstream= $ bitstreams [0 ];
105
+ $ bitstream = $ bitstreams [0 ];
106
106
$ this ->view ->mimetype = $ bitstream ->getMimetype ();
107
107
$ this ->view ->path = $ bitstream ->getAssetstore ()->getPath ().'/ ' .$ bitstream ->getPath ();
108
- $ this ->view ->name =$ bitstream ->getName ();
108
+ $ this ->view ->name = $ bitstream ->getName ();
109
109
if (!file_exists ($ this ->view ->path ))
110
110
{
111
111
throw new Zend_Exception ("Unable to find file on the disk " );
@@ -114,12 +114,12 @@ public function indexAction()
114
114
}
115
115
else
116
116
{
117
- Zend_Loader::loadClass ("ZipStream " ,BASE_PATH .'/library/ZipStream/ ' );
117
+ Zend_Loader::loadClass ("ZipStream " , BASE_PATH .'/library/ZipStream/ ' );
118
118
$ 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 );
121
121
$ zip = new ZipStream ($ name .'.zip ' );
122
- foreach ($ bitstreams as $ bitstream )
122
+ foreach ($ bitstreams as $ bitstream )
123
123
{
124
124
$ zip ->add_file_from_path ($ bitstream ->getName (), $ bitstream ->getAssetstore ()->getPath ().'/ ' .$ bitstream ->getPath ());
125
125
}
@@ -128,69 +128,69 @@ public function indexAction()
128
128
}
129
129
else
130
130
{
131
- Zend_Loader::loadClass ("ZipStream " ,BASE_PATH .'/library/ZipStream/ ' );
131
+ Zend_Loader::loadClass ("ZipStream " , BASE_PATH .'/library/ZipStream/ ' );
132
132
$ this ->_helper ->viewRenderer ->setNoRender ();
133
- if (count ($ folders )== 1 && empty ($ revisions ))
133
+ if (count ($ folders ) == 1 && empty ($ revisions ))
134
134
{
135
- $ name= $ folders [0 ]->getName ();
136
- $ name= substr ($ name , 0 ,50 );
135
+ $ name = $ folders [0 ]->getName ();
136
+ $ name = substr ($ name , 0 , 50 );
137
137
}
138
138
else
139
139
{
140
- $ name= "Custom " ;
140
+ $ name = "Custom " ;
141
141
}
142
142
$ zip = new ZipStream ($ name .'.zip ' );
143
- $ zip= $ this ->createZipRecursive ($ zip ,'' ,$ folders ,$ revisions );
143
+ $ zip = $ this ->_createZipRecursive ($ zip , '' , $ folders , $ revisions );
144
144
$ zip ->finish ();
145
145
}
146
- }//end index
146
+ }//end index
147
147
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 )
155
155
{
156
156
$ zip ->add_file_from_path ($ path .'/ ' .$ bitstream ->getName (), $ bitstream ->getAssetstore ()->getPath ().'/ ' .$ bitstream ->getPath ());
157
157
}
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 ))
168
162
{
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 ))
170
170
{
171
171
continue ;
172
172
}
173
- $ tmp= $ this ->Item ->getLastRevision ($ item );
174
- if ($ tmp !==false )
173
+ $ tmp = $ this ->Item ->getLastRevision ($ item );
174
+ if ($ tmp !== false )
175
175
{
176
- $ subRevisions []= $ tmp ;
177
- if (isset ($ folder ->recursive )&& $ folder ->recursive == false )
176
+ $ subRevisions [] = $ tmp ;
177
+ if (isset ($ folder ->recursive ) && $ folder ->recursive == false )
178
178
{
179
- $ bitstreams= $ subRevisions ->getBitstreams ();
180
- foreach ($ bitstreams as $ bitstream )
179
+ $ bitstreams = $ subRevisions ->getBitstreams ();
180
+ foreach ($ bitstreams as $ bitstream )
181
181
{
182
182
$ zip ->add_file_from_path ($ path .'/ ' .$ bitstream ->getName (), $ bitstream ->getAssetstore ()->getPath ().'/ ' . $ bitstream ->getPath ());
183
183
}
184
184
}
185
185
}
186
186
}
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
+ }
194
194
} // end class
195
195
196
196
0 commit comments