public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty = null, $filterValue = null, $recursive = true)
 {
     $this->connect();
     $ands = array();
     if (!empty($regexp)) {
         $select = "SELECT COUNT(*) FROM [" . $this->customTableName . "] WHERE %and";
         $ands[] = array("[" . $this->customTableUid . "] " . AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanRegexp($regexp));
         $res = dibi::query($select);
     } else {
         $select = "SELECT COUNT(*) FROM [" . $this->customTableName . "]";
         $res = dibi::query($select, $ands);
     }
     $this->close();
     return $res->fetchSingle();
 }
 /**
  * Returns a list of available repositories (dynamic ones only, not the ones defined in the config file).
  * @param Array $criteria
  * @param int $count possible total count
  * @return Repository[]
  */
 public function listRepositoriesWithCriteria($criteria, &$count = null)
 {
     $wheres = array();
     $limit = $groupBy = "";
     $order = "ORDER BY display ASC";
     if (isset($criteria["role"]) && is_a($criteria["role"], "AJXP_Role")) {
         return $this->listRepositoriesForRole($criteria["role"]);
     }
     $searchableKeys = array("uuid", "parent_uuid", "owner_user_id", "display", "accessType", "isTemplate", "slug", "groupPath");
     foreach ($criteria as $cName => $cValue) {
         if (in_array($cName, $searchableKeys) || in_array(substr($cName, 1), $searchableKeys)) {
             if (is_array($cValue)) {
                 if ($cName[0] == "!") {
                     $cName = substr($cName, 1);
                     $wheres[] = array("[{$cName}] NOT IN (%s)", $cValue);
                 } else {
                     $wheres[] = array("[{$cName}] IN (%s)", $cValue);
                 }
             } else {
                 if (strpos($cValue, "regexp:") === 0) {
                     $regexp = str_replace("regexp:", "", $cValue);
                     $wheres[] = array("[{$cName}] " . AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanRegexp($regexp));
                 } else {
                     if ($cValue == AJXP_FILTER_NOT_EMPTY) {
                         $wheres[] = array("[{$cName}] IS NOT NULL");
                     } else {
                         if ($cValue == AJXP_FILTER_EMPTY) {
                             $wheres[] = array("[{$cName}] IS NULL");
                         } else {
                             $type = "%s";
                             if ($cName == 'isTemplate') {
                                 $type = "%b";
                             }
                             $wheres[] = array("[{$cName}] = {$type}", $cValue);
                         }
                     }
                 }
             }
         } else {
             if ($cName == "CURSOR") {
                 $limit = $cValue;
             } else {
                 if ($cName == "ORDERBY") {
                     $order = "ORDER BY " . $cValue["KEY"] . " " . $cValue["DIR"];
                 } else {
                     if ($cName == "GROUPBY") {
                         $groupBy = "GROUP BY " . $cValue;
                     }
                 }
             }
         }
     }
     if (isset($criteria["CURSOR"])) {
         $res = dibi::query("SELECT COUNT(uuid) FROM [ajxp_repo] WHERE %and", $wheres);
         $count = $res->fetchSingle();
     }
     if (!empty($limit) && is_array($limit)) {
         $res = dibi::query("SELECT * FROM [ajxp_repo] WHERE %and {$groupBy} {$order} %lmt %ofs", $wheres, $limit["LIMIT"], $limit["OFFSET"]);
     } else {
         $res = dibi::query("SELECT * FROM [ajxp_repo] WHERE %and {$groupBy} {$order}", $wheres);
     }
     $all = $res->fetchAll();
     return $this->initRepoArrayFromDbFetch($all);
 }
 public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty = null, $filterValue = null, $recursive = true)
 {
     // WITH PARENT
     // SELECT COUNT(*) FROM ajxp_users AS u, ajxp_user_rights AS r WHERE u.groupPath LIKE '/%' AND r.login=u.login AND r.repo_uuid = 'ajxp.parent_user'
     // WITH SPECIFIC PARENT 'username'
     // SELECT COUNT(*) FROM ajxp_users AS u, ajxp_user_rights AS r WHERE u.groupPath LIKE '/%' AND r.login=u.login AND r.repo_uuid = 'ajxp.parent_user' AND r.rights = 'username'
     // WITHOUT PARENT
     // SELECT COUNT(*) FROM ajxp_users AS u WHERE NOT EXISTS (SELECT * FROM ajxp_user_rights AS c WHERE c.login=u.login AND c.repo_uuid='ajxp.parent_user')
     $ands = array();
     $select = "SELECT COUNT(*) FROM [ajxp_users] AS u WHERE %and";
     if (!empty($regexp)) {
         $ands[] = array("[u.login] " . AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanRegexp($regexp));
     }
     if ($recursive) {
         $ands[] = array("[u.groupPath] LIKE %like~", $baseGroup);
     } else {
         $ands[] = array("[u.groupPath] = %s", $baseGroup);
     }
     $ands[] = array("NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = 'ajxp.hidden')");
     if ($filterProperty !== null && $filterValue !== null) {
         if ($filterProperty == "parent") {
             $filterProperty = "ajxp.parent_user";
         } else {
             if ($filterProperty == "admin") {
                 $filterProperty = "ajxp.admin";
             }
         }
         if ($filterValue == AJXP_FILTER_EMPTY) {
             $ands[] = array("NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = %s)", $filterProperty);
         } else {
             if ($filterValue == AJXP_FILTER_NOT_EMPTY) {
                 $select = "SELECT COUNT(*) FROM [ajxp_users] AS u, [ajxp_user_rights] AS r WHERE %and";
                 $ands[] = array("[r.login]=[u.login]");
                 $ands[] = array("[r.repo_uuid] = %s", $filterProperty);
             } else {
                 $select = "SELECT COUNT(*) FROM [ajxp_users] AS u, [ajxp_user_rights] AS r WHERE %and";
                 $ands[] = array("[r.login]=[u.login]");
                 $ands[] = array("[r.repo_uuid] = %s", $filterProperty);
                 $ands[] = array("[r.rights] " . AJXP_Utils::likeToLike($filterValue), AJXP_Utils::cleanLike($filterValue));
             }
         }
     }
     $res = dibi::query($select, $ands);
     return $res->fetchSingle();
 }