Esempio n. 1
0
 /**
  * Return the count of galleries that the user has specified permissions to
  * and that match any of the requested attributes.
  *
  * @param string userid  The user to check access for.
  * @param array $params  Parameter array:
  *<pre>
  *  (integer)perm          The level of permissions to require for a
  *                         gallery to return it [Horde_Perms::SHOW]
  *  (mixed)attributes      Restrict the galleries counted to those
  *                         matching $attributes. An array of
  *                         attribute/values pairs or a gallery owner
  *                         username.
  * (Ansel_Gallery)parent   The parent share to start counting at.
  * (boolean)all_levels      Return all levels, or just the direct children of
  *                         $parent? [true]
  * (array)tags             Filter results by galleries tagged with tags.
  *</pre>
  *
  * @return integer  The count
  * @throws Ansel_Exception
  */
 public function countGalleries($userid, array $params = array())
 {
     static $counts;
     $oparams = new Horde_Support_Array($params);
     if ($oparams->parent) {
         $parent_id = $oparams->parent->id;
     } else {
         $parent_id = null;
     }
     $perm = $oparams->get('perm', Horde_Perms::SHOW);
     $key = "{$userid},{$perm},{$parent_id},{$oparams->all_levels}" . serialize($oparams->get('attributes', array())) . serialize($oparams->get('tags', array()));
     if (isset($counts[$key])) {
         return $counts[$key];
     }
     // Unfortunately, we need to go the long way around to count shares if
     // we are filtering by tags.
     if ($oparams->tags) {
         $count = count($this->listGalleries($params));
     } else {
         try {
             $count = $this->_shares->countShares($userid, $perm, $oparams->get('attributes', array()), $parent_id, $oparams->get('all_levels', true));
         } catch (Horde_Share_Exception $e) {
             throw new Ansel_Exception($e);
         }
     }
     $counts[$key] = $count;
     return $count;
 }