Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Encapsulate new listRepositoriesWithCriteria() methods in ConfService…
Browse files Browse the repository at this point in the history
…. Use in ajxp_conf
  • Loading branch information
cdujeu committed May 1, 2014
1 parent 1047aa8 commit a1f388b
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion core/src/core/classes/class.ConfService.php
Expand Up @@ -490,6 +490,51 @@ public function getCurrentRootDirDisplayInst()
return "";
}

public static function filterRepositoryListWithCriteria($repoList, $criteria){
$repositories = array();
$searchableKeys = array("uuid", "parent_uuid", "owner_user_id", "display", "accessType", "isTemplate", "slug", "groupPath");
foreach ($repoList as $repoId => $repoObject) {
foreach($criteria as $key => $value){
if(!in_array($key, $searchableKeys)) continue;
if($key == "uuid") $comp = $repoObject->getUniqueId();
else if($key == "parent_uuid") $comp = $repoObject->getParentId();
else if($key == "owner_user_id") $comp = $repoObject->getUniqueUser();
else if($key == "display") $comp = $repoObject->getDisplay();
else if($key == "accessType") $comp = $repoObject->getAccessType();
else if($key == "isTemplate") $comp = $repoObject->isTemplate;
else if($key == "slug") $comp = $repoObject->getSlug();
else if($key == "groupPath") $comp = $repoObject->getGroupPath();
if(is_array($value) && in_array($comp, $value)){
$repositories[$repoId] = $repoObject;
}else if($value == AJXP_FILTER_EMPTY && empty($comp)){
$repositories[$repoId] = $repoObject;
}else if($value == AJXP_FILTER_NOT_EMPTY && !empty($comp)){
$repositories[$repoId] = $repoObject;
}else if(strpos($value, "regexp:")===0 && preg_match(str_replace("regexp:", "", $value), $comp)){
$repositories[$repoId] = $repoObject;
}else if($value == $comp){
$repositories[$repoId] = $repoObject;
}
}
}
return $repositories;
}

public static function listRepositoriesWithCriteria($criteria, &$count){

$statics = array();
foreach (self::getInstance()->configs["DEFAULT_REPOSITORIES"] as $index=>$repository) {
$repo = self::createRepositoryFromArray($index, $repository);
$repo->setWriteable(false);
$statics[$repo->getId()] = $repo;
}
$statics = self::filterRepositoryListWithCriteria($statics, $criteria);
$dyna = self::getInstance()->getConfStorageImpl()->listRepositoriesWithCriteria($criteria, $count);
$count += count($statics);
return array_merge($statics, $dyna);

}

/**
* @param $scope String "user", "all"
* @return array
Expand All @@ -506,7 +551,19 @@ protected function initRepositoriesListInst($scope = "user")
}
// LOAD FROM DRIVER
$confDriver = self::getConfStorageImpl();
$drvList = $confDriver->listRepositories($scope == "user" ? AuthService::getLoggedUser() : null);
if($scope == "user"){
$acls = AuthService::getLoggedUser()->mergedRole->listAcls();
if(!count($acls)) {
$drvList = array();
}else{
$criteria = array(
"uuid" => array_keys($acls)
);
$drvList = $confDriver->listRepositoriesWithCriteria($criteria);
}
}else{
$drvList = $confDriver->listRepositories();
}
if (is_array($drvList)) {
foreach ($drvList as $repoId=>$repoObject) {
$driver = AJXP_PluginsService::getInstance()->getPluginByTypeName("access", $repoObject->getAccessType());
Expand Down

0 comments on commit a1f388b

Please sign in to comment.