better documentation of getReverseDocumentLinks() and getDocumentLinks()

This commit is contained in:
Uwe Steinmann 2021-09-24 10:11:13 +02:00
parent 2f9148e5b9
commit 77de9bfaae

View File

@ -2121,12 +2121,22 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
* The list may contain all links to other documents, even those which * The list may contain all links to other documents, even those which
* may not be visible by certain users, unless you pass appropriate * may not be visible by certain users, unless you pass appropriate
* parameters to filter out public links and those created by * parameters to filter out public links and those created by
* the given user. The application may call * the given user. The two parameters are or'ed. If $publiconly
* SeedDMS_Core_DMS::filterDocumentLinks() afterwards. * is set the method will return all public links disregarding the
* user. If $publiconly is not set but a user is set, the method
* will return all links of that user (public and none public).
* Setting a user and $publiconly to true will *not* return the
* public links of that user but all links which are public or
* owned by that user.
* *
* @param boolean $publiconly return on publically visible links * The application must call
* @param object $user return also private links of this user * SeedDMS_Core_DMS::filterDocumentLinks() afterwards to filter out
* @return array list of objects of class SeedDMS_Core_DocumentLink * those links pointing to a document not accessible by a given user.
*
* @param boolean $publiconly return all publically visible links
* @param SeedDMS_Core_User $user return also private links of this user
*
* @return array list of objects of class {@see SeedDMS_Core_DocumentLink}
*/ */
function getDocumentLinks($publiconly=false, $user=null) { /* {{{ */ function getDocumentLinks($publiconly=false, $user=null) { /* {{{ */
if (!isset($this->_documentLinks)) { if (!isset($this->_documentLinks)) {
@ -2167,39 +2177,41 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
* parameters to filter out public links and those created by * parameters to filter out public links and those created by
* the given user. * the given user.
* This functions is basically the reverse of * This functions is basically the reverse of
* SeedDMS_Core_Document::getDocumentLinks() * {@see SeedDMS_Core_Document::getDocumentLinks()}
* *
* The application may call * The application must call
* SeedDMS_Core_DMS::filterDocumentLinks() afterwards. * SeedDMS_Core_DMS::filterDocumentLinks() afterwards to filter out
* those links pointing to a document not accessible by a given user.
*
* @param boolean $publiconly return all publically visible links
* @param SeedDMS_Core_User $user return also private links of this user
* *
* @param boolean $publiconly return on publically visible links
* @param object $user return also private links of this user
* @return array list of objects of class SeedDMS_Core_DocumentLink * @return array list of objects of class SeedDMS_Core_DocumentLink
*/ */
function getReverseDocumentLinks($publiconly=false, $user=null) { /* {{{ */ function getReverseDocumentLinks($publiconly=false, $user=null) { /* {{{ */
$db = $this->_dms->getDB(); $db = $this->_dms->getDB();
$queryStr = "SELECT * FROM `tblDocumentLinks` WHERE `target` = " . $this->_id; $queryStr = "SELECT * FROM `tblDocumentLinks` WHERE `target` = " . $this->_id;
$tmp = array(); $tmp = array();
if($publiconly) if($publiconly)
$tmp[] = "`public`=1"; $tmp[] = "`public`=1";
if($user) if($user)
$tmp[] = "`userID`=".$user->getID(); $tmp[] = "`userID`=".$user->getID();
if($tmp) { if($tmp) {
$queryStr .= " AND (".implode(" OR ", $tmp).")"; $queryStr .= " AND (".implode(" OR ", $tmp).")";
} }
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)
return false; return false;
$links = array(); $links = array();
foreach ($resArr as $row) { foreach ($resArr as $row) {
$document = $this->_dms->getDocument($row["document"]); $document = $this->_dms->getDocument($row["document"]);
$link = new SeedDMS_Core_DocumentLink($row["id"], $document, $this, $row["userID"], $row["public"]); $link = new SeedDMS_Core_DocumentLink($row["id"], $document, $this, $row["userID"], $row["public"]);
if($link->getAccessMode($user, $document, $this) >= M_READ) if($link->getAccessMode($user, $document, $this) >= M_READ)
array_push($links, $link); array_push($links, $link);
} }
return $links; return $links;
} /* }}} */ } /* }}} */