<?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 ''; } ?>
« MODx Parse Error »any ideas why? thanks, j
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
[!bloX? &parents=`0`&project=`tests`&task=`a2z`&depth=`2`&filter=`isfolder|0|eq`&perPage=`5`!]
<?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; ?>
<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>
[+islink:is=`1`:then=` <a href="[~[*id*]~]?letter=[+letter+]">[+letter+]</a> `:else=` <span>[+letter+]</span> `+]
<li>[+pagetitle+]</li>
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
$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) LIMIT 1";
$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) AND (published=1) LIMIT 1";
<?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>"; ?>
$filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "A"; $filter = "pagetitle,".$filterBy.",11";
<?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; ?>