Here is the modified version of the loadChildList function.
(it takes place in determineIDs function)
I’ve kept the same number of parameters.
This one is faster than the old one.
It doesn’t do the same job twice as the old one did.
Hope that helps.
:-)
P.S: I haven’t had time to change the other one but it wasn’t too bad compared to this one.
<?php
function loadChildList(&$arbo,$start,$depth,$kids=array()){
$first = true;// we do not store the first in result array(); as we start from it
$done = array();//used to store the container to not browse twice
$r = array();
//the list of container from documentMap
//we could pass it as a param
$folderList = array_keys($arbo);
while($depth > 0){
if($first){
$first = false;
$c = array();
$r = $this->loadDocumentIDs($arbo,$start);
$c = $r;
}elseif(is_array($r)){
//the container from the current docList
$f = array();
$f = (is_array($s)) ? array_intersect($s,$folderList) : array_intersect($r,$folderList);
if(is_array($done)){
$f = array_diff($f,$done);
}else{
$done = array();
}
foreach($f as $id){
if(in_array($id,$folderList)){
// get the childs of the current container
$c = $this->loadDocumentIDs($arbo,$id);
// store them in an array
$s = array_merge($s,$c);
//merge results for later
$r = array_merge($r,$c);
}
}
//store the container id to avoid to browse them twice
$done = array_merge($done,$f);
}
$depth--;
}
$kids = array_merge($r,$kids);
return $kids;
}
function loadDocumentIDs(&$arbo,$parents){//,$docList=array()){
$folderList = array_keys($arbo);
// we could skip the if statement since we are ckecking in loadChildList
//but I've left them because the function is used outside from loadChildList
if(!is_array($parents)) $parents = explode(",",$parents);
foreach($parents as $parent){
//this one too, only container are sent to the function
if(in_array($parent,$folderList)){
$listItem = $arbo[$parent];
if(count($listItem) > 0) return $listItem;
}
}
}
?>