API:getDocumentChildrenTVars

From MODx Wiki
Jump to: navigation, search
File: manager/includes/document.parser.class.inc.php
Line: 1744
  1. function getDocumentChildrenTVars($parentid= 0, $tvidnames= array (), $published= 1, $docsort= "menuindex", $docsortdir= "ASC", $tvfields= "*", $tvsort= "rank", $tvsortdir= "ASC") {
  2. $docs= $this->getDocumentChildren($parentid, $published, 0, '*', '', $docsort, $docsortdir);
  3. if (!$docs)
  4. return false;
  5. else {
  6. $result= array ();
  7. // get user defined template variables
  8. $fields= ($tvfields == "") ? "tv.*" : 'tv.' . implode(',tv.', preg_replace("/^\s/i", "", explode(',', $tvfields)));
  9. $tvsort= ($tvsort == "") ? "" : 'tv.' . implode(',tv.', preg_replace("/^\s/i", "", explode(',', $tvsort)));
  10. if ($tvidnames == "*")
  11. $query= "tv.id<>0";
  12. else
  13. $query= (is_numeric($tvidnames[0]) ? "tv.id" : "tv.name") . " IN ('" . implode("','", $tvidnames) . "')";
  14. if ($docgrp= $this->getUserDocGroups())
  15. $docgrp= implode(",", $docgrp);
  16.  
  17. $docCount= count($docs);
  18. for ($i= 0; $i < $docCount; $i++) {
  19.  
  20. $tvs= array ();
  21. $docRow= $docs[$i];
  22. $docid= $docRow['id'];
  23.  
  24. $sql= "SELECT $fields, IF(tvc.value!='',tvc.value,tv.default_text) as value ";
  25. $sql .= "FROM " . $this->getFullTableName('site_tmplvars') . " tv ";
  26. $sql .= "INNER JOIN " . $this->getFullTableName('site_tmplvar_templates')." tvtpl ON tvtpl.tmplvarid = tv.id ";
  27. $sql .= "LEFT JOIN " . $this->getFullTableName('site_tmplvar_contentvalues')." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '" . $docid . "' ";
  28. $sql .= "WHERE " . $query . " AND tvtpl.templateid = " . $docRow['template'];
  29. if ($tvsort)
  30. $sql .= " ORDER BY $tvsort $tvsortdir ";
  31. $rs= $this->dbQuery($sql);
  32. $limit= @ $this->recordCount($rs);
  33. for ($x= 0; $x < $limit; $x++) {
  34. array_push($tvs, @ $this->fetchRow($rs));
  35. }
  36.  
  37. // get default/built-in template variables
  38. ksort($docRow);
  39. foreach ($docRow as $key => $value) {
  40. if ($tvidnames == "*" || in_array($key, $tvidnames))
  41. array_push($tvs, array (
  42. "name" => $key,
  43. "value" => $value
  44. ));
  45. }
  46.  
  47. if (count($tvs))
  48. array_push($result, $tvs);
  49. }
  50. return $result;
  51. }
  52. }
Personal tools