}
$query = 'SELECT DISTINCT s.* '
- . $this->getShareCriteria($userid, $perm, $attributes,
- $parent, $allLevels, $ignorePerms)
- . ' ORDER BY ' . $sortfield
- . (($direction == 0) ? ' ASC' : ' DESC');
+ . $this->getShareCriteria($userid, $perm, $attributes,
+ $parent, $allLevels, $ignorePerms)
+ . ' ORDER BY ' . $sortfield
+ . (($direction == 0) ? ' ASC' : ' DESC');
if ($from > 0 || $count > 0) {
$this->_db->setLimit($count, $from);
}
* @throws Horde_Share_Exception
*/
public function getShareCriteria($userid, $perm = Horde_Perms::SHOW, $attributes = null,
- $parent = null, $allLevels = true,
- $ignorePerms = false)
+ $parent = null, $allLevels = true,
+ $ignorePerms = false)
{
- static $criteria;
+ static $criteria = array();
if ($parent instanceof Horde_Share_Object) {
$parent_id = $parent->getId();
} else {
$parent_id = $parent;
}
- $key = $userid . $perm . $parent_id . $allLevels
- . (is_array($attributes) ? serialize($attributes) : $attributes);
+
+ $key = hash('sha1', serialize(array($userid, $perm, $parent_id, $allLevels, $attributes, $ignorePerms)));
if (isset($criteria[$key])) {
return $criteria[$key];
}
$parents = $parent->get('parents') . ':' . $parent->getId();
if ($allLevels) {
$where_parent = '(share_parents = ' . $this->_db->quote($parents)
- . ' OR share_parents LIKE ' . $this->_db->quote($parents . ':%') . ')';
+ . ' OR share_parents LIKE ' . $this->_db->quote($parents . ':%') . ')';
} else {
$where_parent = 's.share_parents = ' . $this->_db->quote($parents);
}
$from = 0, $count = 0)
{
$sql = 'SELECT DISTINCT(s.share_owner) '
- . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null,
- $parent, $allLevels);
+ . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null,
+ $parent, $allLevels);
if ($count) {
$this->_db->setLimit($count, $from);
$allowners = $this->_db->queryCol($sql);
if ($allowners instanceof PEAR_Error) {
- Horde::logMessage($allowners, 'ERR');
- throw new Horde_Share_Exception($allowners->getMessage());
+ Horde::logMessage($allowners, 'ERR');
+ throw new Horde_Share_Exception($allowners->getMessage());
}
$owners = array();
foreach ($allowners as $owner) {
- if ($this->countShares($GLOBALS['registry']->getAuth(), $perm, $owner, $parent,
- $allLevels)) {
-
+ if ($this->countShares($GLOBALS['registry']->getAuth(), $perm, $owner, $parent, $allLevels)) {
$owners[] = $owner;
}
}
public function countOwners($perm = Horde_Perms::SHOW, $parent = null, $allLevels = true)
{
$sql = 'SELECT COUNT(DISTINCT(s.share_owner)) '
- . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null, $parent,
- $allLevels);
+ . $this->getShareCriteria($GLOBALS['registry']->getAuth(), $perm, null, $parent,
+ $allLevels);
return $this->_db->queryOne($sql);
}
$parent = null, $allLevels = true)
{
$query = 'SELECT COUNT(DISTINCT s.share_id) '
- . $this->getShareCriteria($userid, $perm, $attributes,
- $parent, $allLevels);
-
+ . $this->getShareCriteria($userid, $perm, $attributes,
+ $parent, $allLevels);
return $this->_db->queryOne($query);
}
-
}