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

Commit

Permalink
ENH: refs #236. Add midas.community.children method to core web API
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen committed Oct 4, 2011
1 parent f619b70 commit 6922389
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions modules/api/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,41 @@ function communityGet($args)
return $community->toArray();
}

/**
* Get the immediate children of a community (non-recursive)
* @param token (Optional) Authentication token
* @param id The id of the community
* @return The folders in the community
*/
function communityChildren($args)
{
$this->_validateParams($args, array('id'));

$id = $args['id'];

$modelLoader = new MIDAS_ModelLoader();
$communityModel = $modelLoader->loadModel('Community');
$folderModel = $modelLoader->loadModel('Folder');
$community = $communityModel->load($id);
if(!$community)
{
throw new Exception('Invalid community id', MIDAS_INVALID_PARAMETER);
}
$folder = $folderModel->load($community->getFolderId());

$userDao = $this->_getUser($args);
try
{
$folders = $folderModel->getChildrenFoldersFiltered($folder, $userDao);
}
catch(Exception $e)
{
throw new Exception($e->getMessage(), MIDAS_INTERNAL_ERROR);
}

return array('folders' => $folders);
}

/**
* Return a list of all communities visible to a user
* @param token (Optional) Authentication token
Expand Down

0 comments on commit 6922389

Please sign in to comment.