Salut,
dans le même post il y a cette fonction bien pratique.
<?php
function getDocumentChildrenTV($parentid=0, $published=1, $tvfields = "*", $docsort="pagetitle", $docsortdir="ASC", $limit="")
{
global $modx;
$variablesArray = $modx->getDocumentChildrenTVars($parentid, $tvfields, $published, $docsort, $docsortdir, $tvfields);
// Rewrite array to $variablesArray_r
$variablesArray_r = array();
for($a=0; $a<count($variablesArray); $a++) {
for($b=0; $b<count($variablesArray[$a]); $b++) {
$variablesArray_r[$a][$variablesArray[$a][$b]['name']] = $variablesArray[$a][$b]['value'];
foreach ($variablesArray[$a][$b] as $name => $value) {
if ($name!="name" && $name!="value")
$variablesArray_r[$a][$variablesArray[$a][$b]['name'].".$name"] =$value;
}
}
}
customSort($variablesArray_r, $docsort, $docsortdir);
return $variablesArray_r;
}
// Version 1.1
// Parameters:
// data: an array of MODx documents
// fields: comma separated list of fields to sort on
// order: 'ASC' or 'DESC'
function customSort(&$data, $fields, $order) {
// Covert $fields string to array
foreach(explode(',',$fields) as $s) $sortfields[]=trim($s);
$code="";
for($c=0;$c<count($sortfields); $c++)
$code .= "\$retval = strnatcmp(\$a['$sortfields[$c]'], \$b['$sortfields[$c]']); if(\$retval) return \$retval; ";
$code .= "return \$retval;";
$params = ($order=='ASC') ? '$a,$b' : '$b,$a';
usort($data, create_function($params, $code));
}
Elle retourne un tableau contenant tous les documents pour le parent passé en parametre avec pour chaque document les propriétés de ce denier et de toutes les TVs même vides pour ce document.
Exemple:
Array(
...
[3] => Array
(
[thumbImg] => logo
[thumbImg.id] => 1
[thumbImg.type] => image
[thumbImg.caption] => thumbImg
[thumbImg.description] =>
[thumbImg.editor_type] => 0
[thumbImg.category] => 0
[thumbImg.locked] => 0
[thumbImg.elements] =>
[thumbImg.rank] => 0
[thumbImg.display] => image
[thumbImg.display_params] => &align=none
[thumbImg.default_text] =>
[tagsPhoto] => Viandes
[tagsPhoto.id] => 2
[tagsPhoto.type] => listbox-multiple
[tagsPhoto.caption] => tagsPhoto
[tagsPhoto.description] =>
[tagsPhoto.editor_type] => 0
[tagsPhoto.category] => 0
[tagsPhoto.locked] => 0
[tagsPhoto.elements] => Poissons||Viandes||Légumes||Salades||Céréales
[tagsPhoto.rank] => 0
[tagsPhoto.display] => delim
[tagsPhoto.display_params] => &format=,
[tagsPhoto.default_text] =>
[star_rating] => 0
[star_rating.id] => 4
[star_rating.type] => text
[star_rating.caption] => star_rating
[star_rating.description] =>
[star_rating.editor_type] => 0
[star_rating.category] => 0
[star_rating.locked] => 1
[star_rating.elements] =>
[star_rating.rank] => 0
[star_rating.display] =>
[star_rating.display_params] =>
[star_rating.default_text] => 0
[starRatingMachine] => <h4>StarRater</h4>
[starRatingMachine.id] => 5
[starRatingMachine.type] => textarea
[starRatingMachine.caption] => starRatingMachine
[starRatingMachine.description] =>
[starRatingMachine.editor_type] => 0
[starRatingMachine.category] => 0
[starRatingMachine.locked] => 1
[starRatingMachine.elements] =>
[starRatingMachine.rank] => 0
[starRatingMachine.display] =>
[starRatingMachine.display_params] =>
[starRatingMachine.default_text] => <h4>StarRater</h4>
[timeStamp] => @EVAL return time();
[timeStamp.id] => 6
[timeStamp.type] => text
[timeStamp.caption] => timeStamp
[timeStamp.description] =>
[timeStamp.editor_type] => 0
[timeStamp.category] => 0
[timeStamp.locked] => 0
[timeStamp.elements] =>
[timeStamp.rank] => 0
[timeStamp.display] =>
[timeStamp.display_params] =>
[timeStamp.default_text] => @EVAL return time();
[colonneDroite] => @INHERIT
[colonneDroite.id] => 7
[colonneDroite.type] => checkbox
[colonneDroite.caption] => colonneDroite
[colonneDroite.description] => Gestion des blocs de la colonne de droite
[colonneDroite.editor_type] => 0
[colonneDroite.category] => 0
[colonneDroite.locked] => 1
[colonneDroite.elements] => Navigation recettes=={{navRecettes}}||Caddie=={{shopXCart}}
[colonneDroite.rank] => 0
[colonneDroite.display] =>
[colonneDroite.display_params] =>
[colonneDroite.default_text] => @INHERIT
[bigImg] => @INHERIT
[bigImg.id] => 8
[bigImg.type] => image
[bigImg.caption] => bigImg
[bigImg.description] => Image grand Format
[bigImg.editor_type] => 0
[bigImg.category] => 0
[bigImg.locked] => 0
[bigImg.elements] =>
[bigImg.rank] => 0
[bigImg.display] =>
[bigImg.display_params] =>
[bigImg.default_text] => @INHERIT
[categoriePlats] => Entrées
[categoriePlats.id] => 11
[categoriePlats.type] => checkbox
[categoriePlats.caption] => categoriePlats
[categoriePlats.description] =>
[categoriePlats.editor_type] => 0
[categoriePlats.category] => 2
[categoriePlats.locked] => 0
[categoriePlats.elements] => Entrées||Plats||Desserts
[categoriePlats.rank] => 0
[categoriePlats.display] =>
[categoriePlats.display_params] =>
[categoriePlats.default_text] =>
[Saisons] =>
[Saisons.id] => 13
[Saisons.type] => listbox
[Saisons.caption] => Saisons
[Saisons.description] =>
[Saisons.editor_type] => 0
[Saisons.category] => 0
[Saisons.locked] => 1
[Saisons.elements] => printemps||été||automne
[Saisons.rank] => 0
[Saisons.display] =>
[Saisons.display_params] =>
[Saisons.default_text] =>
[alias] =>
[cacheable] => 1
[content] =>
[contentType] => text/html
[content_dispo] => 0
[createdby] => 0
[createdon] => 1157330249
[deleted] => 0
[deletedby] => 0
[deletedon] => 0
[description] =>
[donthit] => 0
[editedby] => 0
[editedon] => 0
[haskeywords] => 0
[hasmetatags] => 0
[hidemenu] => 0
[id] => 12914
[introtext] =>
[isfolder] => 0
[link_attributes] =>
[longtitle] =>
[menuindex] => 0
[menutitle] =>
[pagetitle] => recettes Asperges - 3
[parent] => 12910
[privatemgr] => 0
[privateweb] => 0
[pub_date] => 0
[published] => 1
[publishedby] => 0
[publishedon] => 0
[richtext] => 1
[searchable] => 1
[template] => 4
[type] => document
[unpub_date] => 0
)
)
Je me demande pourquoi elle n’a pas été rajouté au core mais elle pourrait servir de base pour une recherche sur les TVs.
:-)