<![CDATA[ Listing Documents like A - D, E - J etc. - My Forums]]> https://forums.modx.com/thread/?thread=42374 <![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245392 ]]> anonymized-26931 Jun 22, 2010, 08:31 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245392 <![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245391 anonymized-26931 Jun 22, 2010, 07:42 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245391 <![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245390
$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.

]]>
Bruno17 Jun 22, 2010, 07:28 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245390
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245389

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
]]>
anonymized-26931 Jun 22, 2010, 05:15 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245389
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245388
$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]]>
anonymized-26931 Jun 06, 2010, 03:51 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245388
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245387 ]]> anonymized-26931 Jun 06, 2010, 01:23 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245387 <![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245386

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]]>
anonymized-26931 Jun 05, 2010, 11:22 PM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245386
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245385
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.

]]>
Bruno17 Jun 05, 2010, 05:25 PM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245385
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245384 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]]>
anonymized-26931 Jun 05, 2010, 01:33 PM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245384
<![CDATA[Re: Listing Documents like A - D, E - J etc.]]> https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245383
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

]]>
anonymized-26931 May 28, 2010, 10:33 AM https://forums.modx.com/thread/42374/listing-documents-like-a---d-e---j-etc?page=3#dis-post-245383