// This request if for a certain gallery, list all sub-galleries
// and images.
$gallery_id = end($parts);
- $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleries(array($gallery_id));
- if (!isset($galleries[$gallery_id]) ||
- !$galleries[$gallery_id]->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
-
- throw new Horde_Exception_NotFound(_("Invalid gallery specified."));
- }
$galleries = $storage->listGalleries(array('parent' => $gallery_id,
- 'all_levels' => false));
+ 'all_levels' => false,
+ 'perm' => Horde_Perms::SHOW));
$images = $this->listImages(null, $gallery_id, Horde_Perms::SHOW, 'mini');
} elseif (count($parts) > 2 &&
}
// We can't just return the results of the getGalleries call - we need
- // to ensure the caller has at least Horde_Perms::READ on the galleries.
+ // to build the non-object return structure.
$galleries = array();
foreach ($results as $gallery) {
- if ($gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
- $galleries[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData()));
- }
+ $galleries[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData()));
}
return $galleries;
* @return array of Ansel_Gallery objects
* @throws Ansel_Exception
*/
- public function getGalleriesBySlugs($slugs)
+ public function getGalleriesBySlugs(array $slugs, $perms = Horde_Perms::SHOW)
{
- $sql = 'SELECT share_id FROM ' . $this->_shares->getTable()
- . ' WHERE attribute_slug IN (' . str_repeat('?, ', count($slugs) - 1) . '?)';
-
- $stmt = $this->_shares->getReadDb()->prepare($sql);
- if ($stmt instanceof PEAR_Error) {
- throw new Horde_Exception($stmt->getMessage());
- }
- $result = $stmt->execute($slugs);
- if ($result instanceof PEAR_Error) {
- throw new Ansel_Exception($result);
+ try {
+ return $this->_shares->listShares(
+ $GLOBALS['registry']->getAuth(),
+ array('perm' => $perms, 'attribtues' => array('slugs' => $slugs)));
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
}
- $ids = array_values($result->fetchCol());
- $shares = $this->_shares->getShares($ids);
-
- $stmt->free();
- $result->free();
-
- return $shares;
}
/**
* Retrieve an array of Ansel_Gallery objects for the requested ids
*
+ * @param array $ids Gallery ids to fetch
+ * @param integer $perms Horde_Perms constant for the perms required.
+ *
* @return array of Ansel_Gallery objects
+ * @throws Ansel_Exception
*/
- public function getGalleries($ids)
+ public function getGalleries(array $ids, $perms = Horde_Perms::SHOW)
{
- return $this->_shares->getShares($ids);
+ try {
+ $shares = $this->_shares->getShares($ids);
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
+ }
+ $galleries = array();
+ foreach ($shares as $id => $gallery) {
+ if ($gallery->hasPermission($GLOBALS['registry']->getAuth(), $perms)) {
+ $galleries[$id] = $gallery;
+ }
+ }
+
+ return $galleries;
}
/**
$this->_numGalleries = count($this->_params['gallery_ids']);
if ($this->_numGalleries > $this->_start) {
$getThese = array_slice($this->_params['gallery_ids'], $this->_start, $this->_g_perPage);
- $try = $ansel_storage->getGalleries($getThese);
- $this->_galleryList = array();
- foreach ($try as $id => $gallery) {
- if ($gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) {
- $this->_galleryList[$id] = $gallery;
- }
- }
+ $this->_galleryList = $ansel_storage->getGalleries($getThese);
} else {
$this->_galleryList = array();
}