23
23
class Api_IndexController extends Api_AppController
24
24
{
25
25
public $ _moduleModels = array ('Userapi ' );
26
- public $ _models = array ('Community ' , 'ItemRevision ' , 'Item ' , 'User ' , " Folderpolicyuser " , 'Folderpolicygroup ' , 'Folder ' );
26
+ public $ _models = array ('Community ' , 'ItemRevision ' , 'Item ' , 'User ' , ' Folderpolicyuser ' , 'Folderpolicygroup ' , 'Folder ' );
27
27
public $ _components = array ('Upload ' , 'Search ' , 'Uuid ' , 'Sortdao ' );
28
28
29
29
var $ kwWebApiCore = null ;
@@ -98,16 +98,16 @@ private function _setApiCallbacks($apiMethodPrefix)
98
98
$ help ['example ' ] = array ();
99
99
$ help ['return ' ] = 'String version ' ;
100
100
$ help ['description ' ] = 'Return the version of MIDAS ' ;
101
- $ this ->helpContent [$ apiMethodPrefix .'version ' ] = $ help ;
102
- $ this ->apicallbacks [$ apiMethodPrefix .'version ' ] = array (&$ this , 'version ' );
101
+ $ this ->helpContent [$ apiMethodPrefix .'version ' ] = $ help ;
102
+ $ this ->apicallbacks [$ apiMethodPrefix .'version ' ] = array (&$ this , 'version ' );
103
103
104
104
$ help = array ();
105
105
$ help ['params ' ] = array ();
106
106
$ help ['example ' ] = array ();
107
107
$ help ['return ' ] = 'MIDAS info ' ;
108
108
$ help ['description ' ] = 'Get information about this MIDAS instance ' ;
109
- $ this ->helpContent [$ apiMethodPrefix .'info ' ] = $ help ;
110
- $ this ->apicallbacks [$ apiMethodPrefix .'info ' ] = array (&$ this , 'info ' );
109
+ $ this ->helpContent [$ apiMethodPrefix .'info ' ] = $ help ;
110
+ $ this ->apicallbacks [$ apiMethodPrefix .'info ' ] = array (&$ this , 'info ' );
111
111
112
112
$ help = array ();
113
113
$ help ['params ' ] = array ();
@@ -120,7 +120,7 @@ private function _setApiCallbacks($apiMethodPrefix)
120
120
$ help ['example ' ]['?method=midas.login&appname=test&email=user@test.com&apikey=YourKey ' ] = 'Authenticate using key ' ;
121
121
$ help ['return ' ] = 'Token ' ;
122
122
$ help ['description ' ] = 'Authenticate an user ' ;
123
- $ this ->helpContent [$ apiMethodPrefix .'login ' ] = $ help ;
123
+ $ this ->helpContent [$ apiMethodPrefix .'login ' ] = $ help ;
124
124
$ this ->apicallbacks [$ apiMethodPrefix .'login ' ] = array (&$ this , 'login ' );
125
125
126
126
$ help = array ();
@@ -151,7 +151,7 @@ private function _setApiCallbacks($apiMethodPrefix)
151
151
$ help ['return ' ] = 'Array of resource) ' ;
152
152
$ help ['description ' ] = 'Global search ' ;
153
153
$ this ->helpContent [$ apiMethodPrefix .'resource.search ' ] = $ help ;
154
- $ this ->apicallbacks [$ apiMethodPrefix .'resource.search ' ] = array (&$ this , 'resourcesSearch ' );
154
+ $ this ->apicallbacks [$ apiMethodPrefix .'resource.search ' ] = array (&$ this , 'resourcesSearch ' );
155
155
156
156
$ help = array ();
157
157
$ help ['params ' ] = array ();
@@ -199,10 +199,18 @@ private function _setApiCallbacks($apiMethodPrefix)
199
199
$ help ['return ' ] = 'Item information ' ;
200
200
$ help ['description ' ] = 'Upload a file (using put or post method) ' ;
201
201
$ this ->helpContent [$ apiMethodPrefix .'upload.file ' ] = $ help ;
202
- $ this ->apicallbacks [$ apiMethodPrefix .'upload.file ' ] = array (&$ this , 'uploadFile ' );
203
-
202
+ $ this ->apicallbacks [$ apiMethodPrefix .'upload.file ' ] = array (&$ this , 'uploadFile ' );
204
203
205
204
/* ----- Community ------*/
205
+ $ help = array ();
206
+ $ help ['params ' ] = array ();
207
+ $ help ['params ' ]['token ' ] = '(Optional) Authentification token ' ;
208
+ $ help ['example ' ] = array ();
209
+ $ help ['return ' ] = 'List of communities ' ;
210
+ $ help ['description ' ] = 'Get the list of all communities visible to the given user ' ;
211
+ $ this ->helpContent [$ apiMethodPrefix .'community.list ' ] = $ help ;
212
+ $ this ->apicallbacks [$ apiMethodPrefix .'community.list ' ] = array (&$ this , 'communityList ' );
213
+
206
214
$ help = array ();
207
215
$ help ['params ' ] = array ();
208
216
$ help ['params ' ]['token ' ] = 'Authentification token ' ;
@@ -249,7 +257,7 @@ private function _setApiCallbacks($apiMethodPrefix)
249
257
$ help ['return ' ] = 'Folder information ' ;
250
258
$ help ['description ' ] = 'Create or edit a folder ' ;
251
259
$ this ->helpContent [$ apiMethodPrefix .'folder.create ' ] = $ help ;
252
- $ this ->apicallbacks [$ apiMethodPrefix .'folder.create ' ] = array (&$ this , 'folderCreate ' );
260
+ $ this ->apicallbacks [$ apiMethodPrefix .'folder.create ' ] = array (&$ this , 'folderCreate ' );
253
261
254
262
$ help = array ();
255
263
$ help ['params ' ] = array ();
@@ -259,7 +267,7 @@ private function _setApiCallbacks($apiMethodPrefix)
259
267
$ help ['return ' ] = '' ;
260
268
$ help ['description ' ] = 'Delete a folder ' ;
261
269
$ this ->helpContent [$ apiMethodPrefix .'folder.delete ' ] = $ help ;
262
- $ this ->apicallbacks [$ apiMethodPrefix .'folder.delete ' ] = array (&$ this , 'folderDelete ' );
270
+ $ this ->apicallbacks [$ apiMethodPrefix .'folder.delete ' ] = array (&$ this , 'folderDelete ' );
263
271
264
272
$ help = array ();
265
273
$ help ['params ' ] = array ();
@@ -269,7 +277,7 @@ private function _setApiCallbacks($apiMethodPrefix)
269
277
$ help ['return ' ] = 'Folder Information ' ;
270
278
$ help ['description ' ] = 'Get a folder ' ;
271
279
$ this ->helpContent [$ apiMethodPrefix .'folder.get ' ] = $ help ;
272
- $ this ->apicallbacks [$ apiMethodPrefix .'folder.get ' ] = array (&$ this , 'folderGet ' );
280
+ $ this ->apicallbacks [$ apiMethodPrefix .'folder.get ' ] = array (&$ this , 'folderGet ' );
273
281
274
282
$ help = array ();
275
283
$ help ['params ' ] = array ();
@@ -279,15 +287,15 @@ private function _setApiCallbacks($apiMethodPrefix)
279
287
$ help ['return ' ] = 'File ' ;
280
288
$ help ['description ' ] = 'Download a folder ' ;
281
289
$ this ->helpContent [$ apiMethodPrefix .'folder.download ' ] = $ help ;
282
- $ this ->apicallbacks [$ apiMethodPrefix .'folder.download ' ] = array (&$ this , 'folderDownload ' );
290
+ $ this ->apicallbacks [$ apiMethodPrefix .'folder.download ' ] = array (&$ this , 'folderDownload ' );
283
291
284
292
$ help = array ();
285
293
$ help ['params ' ] = array ();
286
294
$ help ['params ' ]['token ' ] = '(Optional) Authentification token ' ;
287
295
$ help ['params ' ]['id ' ] = 'Id of the folder ' ;
288
296
$ help ['example ' ] = array ();
289
297
$ help ['return ' ] = 'Array of Items and Folders ' ;
290
- $ help ['description ' ] = 'Get folder Content ' ;
298
+ $ help ['description ' ] = 'Get folder content ' ;
291
299
$ this ->helpContent [$ apiMethodPrefix .'folder.content ' ] = $ help ;
292
300
$ this ->apicallbacks [$ apiMethodPrefix .'folder.content ' ] = array (&$ this , 'folderContent ' );
293
301
@@ -297,9 +305,18 @@ private function _setApiCallbacks($apiMethodPrefix)
297
305
$ help ['params ' ]['id ' ] = 'Id of the folder ' ;
298
306
$ help ['example ' ] = array ();
299
307
$ help ['return ' ] = 'Array of Folders ' ;
300
- $ help ['description ' ] = 'Get folder Tree ' ;
308
+ $ help ['description ' ] = 'Get folder tree ' ;
301
309
$ this ->helpContent [$ apiMethodPrefix .'folder.tree ' ] = $ help ;
302
- $ this ->apicallbacks [$ apiMethodPrefix .'folder.tree ' ] = array (&$ this , 'folderTree ' );
310
+ $ this ->apicallbacks [$ apiMethodPrefix .'folder.tree ' ] = array (&$ this , 'folderTree ' );
311
+
312
+ $ help = array ();
313
+ $ help ['params ' ] = array ();
314
+ $ help ['params ' ]['token ' ] = '(Optional) Authentification token ' ;
315
+ $ help ['example ' ] = array ();
316
+ $ help ['return ' ] = 'List of Folders ' ;
317
+ $ help ['description ' ] = 'Get the list of top level folders belonging to a given user ' ;
318
+ $ this ->helpContent [$ apiMethodPrefix .'user.folders ' ] = $ help ;
319
+ $ this ->apicallbacks [$ apiMethodPrefix .'user.folders ' ] = array (&$ this , 'userFolders ' );
303
320
304
321
/** ------ ITEM --- */
305
322
$ help = array ();
@@ -342,7 +359,7 @@ private function _setApiCallbacks($apiMethodPrefix)
342
359
$ help ['return ' ] = '' ;
343
360
$ help ['description ' ] = 'Get metadata ' ;
344
361
$ this ->helpContent [$ apiMethodPrefix .'item.getmetadata ' ] = $ help ;
345
- $ this ->apicallbacks [$ apiMethodPrefix .'item.getmetadata ' ] = array (&$ this , 'itemGetMetadata ' );
362
+ $ this ->apicallbacks [$ apiMethodPrefix .'item.getmetadata ' ] = array (&$ this , 'itemGetMetadata ' );
346
363
}
347
364
348
365
/** Initialize property allowing to generate XML */
@@ -1279,10 +1296,51 @@ function itemDelete($args)
1279
1296
1280
1297
if ($ item === false || !$ this ->Item ->policyCheck ($ item , $ userDao , MIDAS_POLICY_ADMIN ))
1281
1298
{
1282
- throw new Exception ("This item doesn't exist or you don't have the permissions. " , MIDAS_INVALID_POLICY );
1299
+ throw new Exception ("This item doesn't exist or you don't have the permissions. " , MIDAS_INVALID_POLICY );
1283
1300
}
1284
1301
1285
1302
$ this ->Item ->delete ($ item );
1286
1303
}
1304
+
1305
+ /**
1306
+ * Return a list of all communities visible to a user
1307
+ */
1308
+ function communityList ($ args )
1309
+ {
1310
+ $ userDao = $ this ->_getUser ($ args );
1311
+
1312
+ if ($ userDao && $ userDao ->isAdmin ())
1313
+ {
1314
+ $ communities = $ this ->Community ->getAll ();
1315
+ }
1316
+ else
1317
+ {
1318
+ $ communities = $ this ->Community ->getPublicCommunities ();
1319
+ if ($ userDao )
1320
+ {
1321
+ $ communities = array_merge ($ communities , $ this ->User ->getUserCommunities ($ userDao ));
1322
+ }
1323
+ }
1324
+
1325
+ $ this ->Component ->Sortdao ->field = 'name ' ;
1326
+ $ this ->Component ->Sortdao ->order = 'asc ' ;
1327
+ usort ($ communities , array ($ this ->Component ->Sortdao , 'sortByName ' ));
1328
+ return $ this ->Component ->Sortdao ->arrayUniqueDao ($ communities );
1329
+ }
1330
+
1331
+ /**
1332
+ * Return a list of top level folders belonging to the user
1333
+ */
1334
+ function userFolders ($ args )
1335
+ {
1336
+ $ userDao = $ this ->_getUser ($ args );
1337
+ if ($ userDao == false )
1338
+ {
1339
+ return array ();
1340
+ }
1341
+
1342
+ $ userRootFolder = $ userDao ->getFolder ();
1343
+ return $ this ->Folder ->getChildrenFoldersFiltered ($ userRootFolder , $ userDao , MIDAS_POLICY_READ );
1344
+ }
1287
1345
} // end class
1288
1346
?>
0 commit comments