[2010-08-16 17:42:12] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => 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 ’1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context_key` IN (’web’) OR EXISTS(S’ at line 1 )
Hi, great snippet, but for me the &resources parameter doesn’t work. Tried many combinatins. None worked.
Any ideas?

getResources 1.1.0-pl (July 30, 2010)
* - Added &toPlaceholder property for assigning results to a placeholder
* - Added &resources property for including/excluding specific resources
* - Added &showDeleted property
* - Allow multiple contexts to be passed into &context
* - Added &showUnpublish property
* - Added getresources.core_path reference for easier development
* - [#ADDON-135] Make output separator configurable via outputSeparator property
* - Add where property to allow ad hoc criteria in JSON format
My initial call: [[getResources]] or [[!getResources]]
[2010-08-16 17:42:12] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => 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 ’1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context_key` IN (’web’) OR EXISTS(S’ at line 1 )
[2010-08-17 10:59:18] (ERROR @ /[myLocalhostAddress]/index.php) Error 42000 executing statement: Array ( [0] => 42000 [1] => 1064 [2] => 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 ’3,1,2,3,4,5,6,7,11,8,9,10) AND (`modResource`.`context’ at line 1 )
<?php
/********* debug *********/
echo '<pre>';
print_r($parents);
echo '</pre>';
die();
/********* debug *********/
foreach ($parents as $parent) {
$pchildren = $modx->getChildIds($parent, $depth);
if (!empty($pchildren)) $children = array_merge($children, $pchildren);
}
if (!empty($children)) $parents = array_merge($parents, $children);
Array
(
[0] => 3
)
<?php
foreach ($parents as $parent) {
$pchildren = $modx->getChildIds($parent, $depth);
if (!empty($pchildren)) $children = array_merge($children, $pchildren);
}
if (!empty($children)) $parents = array_merge($parents, $children);
/********* debug *********/
echo '<pre>';
print_r($parents);
echo '</pre>';
die();
/********* debug *********/
Array
(
[0] => 3
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
[8] => 11
[9] => 8
[10] => 9
[11] => 10
)
&tvFilters=`EventStartDate><'2010-08-01'#DATETIME&'2010-10-01 23:59:59'#DATETIME`
if (!empty($tvFilters)) {
$tmplVarTbl = $modx->getTableName('modTemplateVar');
$tmplVarResourceTbl = $modx->getTableName('modTemplateVarResource');
$conditions = array();
foreach ($tvFilters as $fGroup => $tvFilter) {
$filterGroup = count($tvFilters) > 1 ? $fGroup + 1 : 0;
$filters = explode(',', $tvFilter);
foreach ($filters as $filter) {
if (strpos($filter, '==') !== false) {
$mode = 1 ;
} elseif (strpos($filter, '><') !== false) {
$mode = 2 ;
} else {
$mode = 0 ;
}
switch($mode) {
case 1:
$f = explode('==', $filter);
if (count($f) == 2) {
$tvName = $modx->quote($f[0]);
$tvValue = $modx->quote($f[1]);
$conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
} elseif (count($f) == 1) {
$tvValue = $modx->quote($f[0]);
$conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` LIKE {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
}
break ;
case 2:
$f = explode('><', $filter);
if (count($f) == 2) {
$tvName = $modx->quote($f[0]);
$ranges = $f[1];
$d = explode('&', $ranges);
if (count($d) == 2) {
for ($i = 0, $size = sizeof($d); $i <= $size; ++$i) {
$p = explode('#', $d[$i]);
$tvValue[$i] = "CAST(".$p[0]." as ".$p[1].")" ;
}
$conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` BETWEEN {$tvValue[0]} AND {$tvValue[1]} AND `tv`.`name` = {$tvName} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
}
} elseif (count($f) == 1) {
$tvValue = $modx->quote($f[0]);
$conditions[$filterGroup][] = "EXISTS (SELECT 1 FROM {$tmplVarResourceTbl} `tvr` JOIN {$tmplVarTbl} `tv` ON `tvr`.`value` BETWEEN {$tvValue} AND `tv`.`id` = `tvr`.`tmplvarid` WHERE `tvr`.`contentid` = `modResource`.`id`)";
}
}
}
}
if (!empty($conditions)) {
foreach ($conditions as $cGroup => $c) {
if ($cGroup > 0) {
$criteria->orCondition($c, null, $cGroup);
} else {
$criteria->andCondition($c);
}
}
}
}
I haven’t have time to debug the modX::getChildIds, but that method should be re-investigated again.
<?php
public function getChildIds($id= null, $depth= 10) {
$children= array ();
if ($id !== null && intval($depth) >= 1) {
$id= intval($id);
if (isset ($this->resourceMap["{$id}"])) {
if ($children= $this->resourceMap["{$id}"]) {
foreach ($children as $child) {
$processDepth = $depth - 1;
if ($c= $this->getChildIds($child, $processDepth)) {
$children= array_merge($children, $c);
}
}
}
}
}
return $children;
}