API:getDocuments
From MODx Wiki
API Function Definition:
getDocument
- Versions
- > 0.6.0
- Return Values
- Success: The document
- Fail: boolean false
- Data Type
- array
- Object Hierarchy
- DocumentParser
array getDocument(array $ids[, int $published[, int $deleted[, string $fields[, string $where[, string $sort[, string $dir[, string $limit]]]);
Retrieves a document from the database given the id. By default, this function searches for published documents that are not deleted. The defaults can be overridden by the 3rd and 4th parameters of the function.
[edit]
Examples
// Retrieve the pagetitles for document 6,7, and 8 $doc = $modx->getDocuments(array(6,7,8), 1, 0, 'pagetitle');
[edit]
Related Functions
- getDocument
- getPageInfo
- getParent
[edit]
Source Code
| File: | manager/includes/document.parser.class.inc.php |
|---|---|
| Line: | 1395 |
function getDocuments($ids= array (), $published= 1, $deleted= 0, $fields= "*", $where= '', $sort= "menuindex", $dir= "ASC", $limit= "") { if (count($ids) == 0) { return false; } else { $limit= ($limit != "") ? "LIMIT $limit" : ""; // LIMIT capabilities - rad14701 $tblsc= $this->getFullTableName("site_content"); $tbldg= $this->getFullTableName("document_groups"); // modify field names to use sc. table reference $fields= 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $fields))); $sort= ($sort == "") ? "" : 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $sort))); if ($where != '') $where= 'AND ' . $where; // get document groups for current user if ($docgrp= $this->getUserDocGroups()) $docgrp= implode(",", $docgrp); $access= ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); $sql= "SELECT DISTINCT $fields FROM $tblsc sc LEFT JOIN $tbldg dg on dg.document = sc.id WHERE (sc.id IN (" . join($ids, ",") . ") AND sc.published=$published AND sc.deleted=$deleted $where) AND ($access) GROUP BY sc.id " . ($sort ? " ORDER BY $sort $dir" : "") . " $limit "; $result= $this->dbQuery($sql); $resourceArray= array (); for ($i= 0; $i < @ $this->recordCount($result); $i++) { array_push($resourceArray, @ $this->fetchRow($result)); } return $resourceArray; } }
