We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    *tiny bump*

    btw. this is an Evo 1.0.3 installation

    guess a (semi) workaround would be another snippet that lists the ids of all container ressources within ressource id2

    something like [!A2Z? &parents=`[[GetContainerIDs]]`!]

    does anyone know a snippet (or parts of a snippet) that lists all ressources which are containers ("isfolder")?

    thanks, j

      • 26931
      • 2,314 Posts
      hmmm smiley okay, i managed to write a Snippet that returns the IDs of all container ressources within a certain container:

      *edit*... cleaned up the Snippet code a bit. i know, i know commented too much & the obvious smiley // just for my record

      <?php
      
      /*
       * This Snippet will return a comma separated List of container IDs
       * within a declared container.
       * e.g. [[getChildContainer? &parent=`2` $depth=`2`]]
       * btw. "print" to return the value is used because i call the Snippet within 
       * another Snippet. you can change "print" to "return" if you're not.
       */
      
      // use parent ID if declared, otherwise default to 0 (site root)
      $parent=isset($parent) ? $parent : '0';
      
      // how many levels deep. i think it defaults to 10 levels if not set
      $depth=isset($depth) ? $depth : '';
      
      // get all children
      $childArray = $modx->getChildIds($parent, $depth);
      
      // get IDs from all children that are containers, published and not deleted
      $container = $modx->getDocuments($childArray, 1, 0, 'id', 'isfolder=1');
      
      // count the IDs
      $childrenCount = count($container); 
      
      // loop through the array if there are child containers
       if ($childrenCount!==0){
      		for($x=0; $x<$childrenCount; $x++) {
      		$folderids .= $container[$x]['id'].",";
      		}
      		// within another Snippet use print, instead of return
      		print $folderids;
      	} else {
      	// return empty string if there are no containers
      	print '';
      	}
      
      ?>


      but using it in combination with the A2Z Snippet [!A2Z? &parents=`[[GetContainerIDs]]16`!] i get a parser error:

      « MODx Parse Error »
      MODx encountered the following error while attempting to parse the requested resource:
      « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’[!getChildContainer!]16)) LIMIT 1’ at line 1 »
      SQL: SELECT `db12345`.`modx_site_content`.id, `db12345`.`modx_site_content`.pagetitle FROM `db12345`.`modx_site_content` WHERE ( `db12345`.`modx_site_content`.pagetitle LIKE ’A%’) AND (`db12345`.`modx_site_content`.parent IN ([!getChildContainer!]16)) LIMIT 1
      any ideas why? smiley thanks, j
        • 4172
        • 5,888 Posts
        can’t help with your issue, because I don’t know where this IN ([!getChildContainer!]16)) comes from??

        but have a solution with bloX which does the same and seems to work:

        the bloX-call:
        [!bloX? &parents=`0`&project=`tests`&task=`a2z`&depth=`2`&filter=`isfolder|0|eq`&perPage=`5`!]


        my getdatas.php for that task:

        <?php
        
        
        $perPage=$this->bloxconfig['perPage'];
        $pageStart=$this->bloxconfig['pageStart'];
        $this->bloxconfig['perPage']='500';
        $this->bloxconfig['pageStart']='1';
        $resultrows = $this->getrows();
        
        if (count($resultrows) > 0)
        {
        foreach ($resultrows as $resultrow){
        	
        	$lexicon[strtoupper(substr($resultrow['pagetitle'],0,1))][]=$resultrow;
        }
        }
        
        
        //-- Alphabet Letters
        $letter = array (
        	"A",
        	"B",
        	"C",
        	"D",
        	"E",
        	"F",
        	"G",
        	"H",
        	"I",
        	"J",
        	"K",
        	"L",
        	"M",
        	"N",
        	"O",
        	"P",
        	"Q",
        	"R",
        	"S",
        	"T",
        	"U",
        	"V",
        	"W",
        	"X",
        	"Y",
        	"Z"
        );
        
        foreach($letter as $l){
        
        	$letterarray=array();
        	if (array_key_exists($l,$lexicon)){
        		$letterarray['innerrows']['lexiconresource']=$lexicon[$l];
        		$letterarray['islink']='1';
        	}
        	else{
        		$letterarray['islink']='0';
        	}
        	$letterarray['letter']=$l;
        	$letters[]=$letterarray;
        	
        }
        
        if (isset($_GET['letter'])){
        $this->bloxconfig['perPage']=$perPage;
        $this->bloxconfig['pageStart']=$pageStart;
        $this->bloxconfig['filter']='pagetitle|'.$modx->db->escape($_GET['letter']).'%|LIKE++'.$this->bloxconfig['filter'];
        $resultrows = $this->getrows();	
        	$bloxdatas['innerrows']['resource'] = $resultrows;
        }
        
        
        //pagination
        $numRows = $this->totalCount;
        require_once ($GLOBALS['blox_path'].'inc/Pagination.php');
        $p = new Pagination( array ('per_page'=>$this->bloxconfig['perPage'],
        'num_links'=>$this->bloxconfig['numLinks'],
        'cur_item'=>$this->bloxconfig['pageStart'],
        'total_rows'=>$numRows));
        $bloxdatas['pagination'] = $p->create_links();
        
        
        
        $bloxdatas['innerrows']['letter'] = $letters;
        
        
        ?>


        and this are the templates for that task:

        bloxouterTpl.html:
        <div>
        <div class="ldb_pagination">[+pagination+]</div>
        <[+blox.config.htmlouter+] id="[+blox.config.htmlouter+]_[+blox.config.id+]" >
        
        [+innerrows.letter+]
        
        <ul>
        [+innerrows.resource+]
        </ul>
        
        </[+blox.config.htmlouter+]>
        </div>


        letterTpl.html:
        [+islink:is=`1`:then=`
        <a href="[~[*id*]~]?letter=[+letter+]">[+letter+]</a>
        `:else=`
        <span>[+letter+]</span>
        `+]


        resourceTpl.html:
        <li>[+pagetitle+]</li>


        would also be very easy to have a tooltip for each letter with all pagetitles for example with [+innerrows.lexiconresource+] in letterTpl and a new Template lexiconresourceTpl.html.

          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 26931
          • 2,314 Posts
          oh, wow - thanks Bruno, i def. need to check bloX! smiley

          I don’t know where this IN ([!getChildContainer!]16))
          that will return the comma separated list of container IDs (which may vary) from the Snippet code i posted above. "16" is just the ID from another container from which i know it only contains ressources and no other containers
            • 26931
            • 2,314 Posts
            just found out that if i "print" the result of [!getChildContainer!] instead of "return" it works smiley
              • 26931
              • 2,314 Posts
              btw. in order to prevent the A2Z Snippet from displaying an active Letter in the list even if the actual ressource is set unpublished, i needed to change that part from the Snippet code:
              $sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) LIMIT 1";
              to:
              $sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) AND (published=1) LIMIT 1";


              otherwise you got an active link (A) although the ressource is unpublished. see the screenshot below
                • 26931
                • 2,314 Posts
                haha, oh dear ...ran into another small problem smiley

                e.g. if i create a ressource with the pagetitle starting wit an Umlaut "Ü", the "Ü" will be displayed as an "U" (which is okay) and as an active Lexicon entry in the list of letters, but won’t show any entry if it is clicked ...does anyone know why?:

                <?php
                $docid = $modx->documentIdentifier;
                $parents = isset($parents) ? $parents : $docid;
                $dittoTpl = isset($tpl) ? $tpl : "a2z-template"; // ditto tpl to use
                $display = isset($display) ? $display : "all"; // number of items per page to return
                $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A";
                $filter = "pagetitle,".$filterBy.",11";
                
                //-- Alphabet Letters
                $letter = array (
                	"A",
                	"B",
                	"C",
                	"D",
                	"E",
                	"F",
                	"G",
                	"H",
                	"I",
                	"J",
                	"K",
                	"L",
                	"M",
                	"N",
                	"O",
                	"P",
                	"Q",
                	"R",
                	"S",
                	"T",
                	"U",
                	"V",
                	"W",
                	"X",
                	"Y",
                	"Z"
                );
                
                $table = $modx->getFullTableName("site_content");
                
                foreach($letter as $l){
                	$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) AND (published=1) LIMIT 1";
                	$results = $modx->db->query($sql);
                	$count = $modx->db->getRecordCount( $results );
                	if ($count > 0) {
                
                // adding active class
                	if($l === $_GET['letter'])
                	{
                	$active = 'active';
                	}else{
                	$active = '';
                	}
                
                		$letters .= "<a class=\"".$active."\" href=\"[~".$docid."~]?letter=".$l."\">".$l."</a>";
                	} else {
                		$letters .= "<span>" . $l . "</span>";
                	}
                }
                
                // get count for pagination
                // $v = '';
                // if($filterBy != ""){
                // $sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$filterBy%') AND ($table.parent IN ($parents))";
                // $results = $modx->db->query($sql);
                // $v = $modx->db->getRecordCount( $results );
                // }
                
                // run ditto snippet
                $output = $modx->runSnippet("Ditto", array(
                	"debug" => "0",
                	"parents" => $parents,
                	"depth" => "4",
                	"seeThruUnpub" => "1",
                	"hideFolders" => "1",
                	"display" => $display,
                	"paginate" => "0",
                	"paginateAlwaysShowLinks" => "0",
                	"sortBy" => "pagetitle",
                	"sortDir" => "ASC",
                	"tpl" => $dittoTpl,
                	"filter" => $filter,
                	"language" => "german",
                	"noResults" => "Es wurde kein Eintrag für den Buchstaben \"A\" gefunden.",
                	"tplPaginatePrevious" => "@CODE <li><a href='[+url+]'>Previous</a></li>\n",
                	"tplPaginateNext" => "@CODE <li><a href='[+url+]'>Next</a></li>\n",
                	"tplPaginateNextOff" => "@CODE <li><a href='[~[*id*]~]#'>Next</a></li>\n",
                	"tplPaginatePreviousOff" => "@CODE <li><a href='[~[*id*]~]#'>Previous</a></li>\n",
                	"tplPaginatePage" => "@CODE <li><a href='[+url+]'>[+page+]</a></li>\n",
                	"tplPaginateCurrentPage" => "@CODE <li class='selected'><a href='[~[*id*]~]#'>[+page+]</a></li>\n" ));
                
                //$v = count($output);
                
                // $modx->setPlaceholder('a2zletters', $letters);
                // $modx->setPlaceholder('a2z', $output);
                // $modx->setPlaceholder('pages', $pages);
                
                return "<p class=\"lexicon\">".$letters."</p> "."<div id=\"lexicon\">".$output."</div>";
                ?>
                guess line 41 to 45 is of importance

                thanks, j
                  • 4172
                  • 5,888 Posts
                  its because you filter only by the letter which comes with $_GET:

                  $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A";
                  $filter = "pagetitle,".$filterBy.",11";


                  if you have A,O,U you have to filter out all which do not begin with U OR do not begin with Ü (example for &letter=U).

                  in my a2z-bloX-project it does it with this getdatas.php:

                  <?php
                  
                  
                  $perPage=$this->bloxconfig['perPage'];
                  $pageStart=$this->bloxconfig['pageStart'];
                  $this->bloxconfig['perPage']='500';
                  $this->bloxconfig['pageStart']='1';
                  $resultrows = $this->getrows();
                  
                  if (count($resultrows) > 0)
                  {
                  foreach ($resultrows as $resultrow){
                  	mb_internal_encoding("UTF-8");
                  	$lexicon[strtoupper(mb_substr($resultrow['pagetitle'],0,1))][]=$resultrow;
                  }
                  }
                  
                  
                  
                  //-- Alphabet Letters
                  $letter = array (
                  	"A:Ä",
                  	"B",
                  	"C",
                  	"D",
                  	"E",
                  	"F",
                  	"G",
                  	"H",
                  	"I",
                  	"J",
                  	"K",
                  	"L",
                  	"M",
                  	"N",
                  	"O:Ö",
                  	"P",
                  	"Q",
                  	"R",
                  	"S",
                  	"T",
                  	"U:Ü",
                  	"V",
                  	"W",
                  	"X",
                  	"Y",
                  	"Z"
                  );
                  
                  foreach($letter as $l){
                  
                  	$letterarray=array();
                  	$letterarray['islink']='0';
                  	$l_a=explode(':',$l);
                  	$l=$l_a[0];
                  	$l_array[$l]=$l_a;
                  	foreach ($l_a as $l_){
                  	if (array_key_exists($l_,$lexicon)){
                  		$letterarray['innerows']['lexiconresource']=$lexicon[$l];
                  		$letterarray['islink']='1';
                  	}		
                  	}
                  
                  	$letterarray['letter']=$l;
                  	$letters[]=$letterarray;
                  	
                  }
                  
                  if (isset($_GET['letter'])){
                  $this->bloxconfig['perPage']=$perPage;
                  $this->bloxconfig['pageStart']=$pageStart;
                  
                  $or='';
                  $filter='';
                  foreach ($l_array[$modx->db->escape($_GET['letter'])] as $l_){
                  $filter.=$or.'pagetitle|'.$l_.'%|LIKE';
                  $or='||';	
                  }
                  
                  $this->bloxconfig['filter']='('.$filter.')++'.$this->bloxconfig['filter'];
                  $resultrows = $this->getrows();	
                  	$bloxdatas['innerrows']['resource'] = $resultrows;
                  }
                  
                  
                  //pagination
                  $numRows = $this->totalCount;
                  require_once ($GLOBALS['blox_path'].'inc/Pagination.php');
                  $p = new Pagination( array ('per_page'=>$this->bloxconfig['perPage'],
                  'num_links'=>$this->bloxconfig['numLinks'],
                  'cur_item'=>$this->bloxconfig['pageStart'],
                  'total_rows'=>$numRows));
                  $bloxdatas['pagination'] = $p->create_links();
                  
                  
                  
                  $bloxdatas['innerrows']['letter'] = $letters;
                  
                  
                  ?>


                  Perhaps you can rewrite some of that code to get the document-IDs and use it for dittos &documents if you still want to use Ditto.

                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 26931
                    • 2,314 Posts
                    thanks Bruno! ... i’ll look into that and report back
                      • 26931
                      • 2,314 Posts
                      ... instead of pagetitle i could SELECT & filter by the alias field grin