We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    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;	
    				}
    		
    			}
    		
    	}
    ?>
    
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 33114
      • 518 Posts
      Impressed by the new mechanisms and resulting figures I start to post some testing feedback too:)

      Mark btw is the ’dev code’ the one in the zip in first post? well if it is it gives me the following error

      Fatal error: Cannot redeclare class phxparser in d:\hst\yent-ru_fa6b5fc4\http\pam-pa\assets\snippets\ditto2\classes\phx.parser.class.inc.php on line 11

      while calling Ditto:
      [!Ditto2? &startID=`23` &tpl=`photo_album` &tplAltRows=`photo_alt` &tagData=`tvtags` &tagDelimiter=`,`  &summarize=`4` &dateFormat=`%d.%m.%Y` &paginate=`0` &sortBy=`createdon` &sortDir=`DESC`!]


      photo_album tpl:
      <div class="photo_album">
      	<a href="[~[+id+]~]" title="Смотреть альбом">
      [[MaxiGallery?  &galleryOuterTpl=`no_gallery` &galleryPictureTpl=`no_gallery_pic` &pics_per_page=`1` &pageNumberTpl=`numbers` &view_gallery=`[+id+]`]] [+pagetitle+]
      </a>
      <div class="date">[+date+]</div>
      </div>
      
      


      I use three Ditto versions on my site... maybe it has something to do with that.
        http://modx.ru - российская поддержка MODx
        http://newscup.ru - экспериментальный проект
        http://yentsun.com - персональный сайт
        • 11975
        • 2,542 Posts
        Hi yentsun,

        i’ve tried to fix this by adding some if statement in ditto snippet but none succeed.
        Finally, i’ve wrapped the PHxParser in classes/phx.parser.inc.php:
        if (!class_exists("PHxParser")){..class code..}


        :-)
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 18397
          • 3,250 Posts
          Remove the PHx class from the include files array in the snippet and that will fix the issue as well.