From 2407f5c5e61758f2d1674974cd812b68bc960661 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 1 Mar 2017 08:04:40 +0100 Subject: [PATCH] add method __getAllInstances(), use right db field for user --- SeedDMS_Core/Core/inc.ClassDownloadLink.php | 66 ++++++++++++++++++++- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDownloadLink.php b/SeedDMS_Core/Core/inc.ClassDownloadLink.php index 213518fc6..18ae63b99 100644 --- a/SeedDMS_Core/Core/inc.ClassDownloadLink.php +++ b/SeedDMS_Core/Core/inc.ClassDownloadLink.php @@ -79,7 +79,7 @@ class SeedDMS_Core_DownloadLink { /* {{{ */ $resArr = $resArr[0]; $document = $dms->getDocument($resArr['document']); - $user = $dms->getUser($resArr['user']); + $user = $dms->getUser($resArr['userID']); $classname = $dms->getClassname('downloadlink'); $downloadlink = new $classname($resArr["id"], $document, $resArr["version"], $user, $resArr["hash"], $resArr["valid"]); @@ -87,16 +87,51 @@ class SeedDMS_Core_DownloadLink { /* {{{ */ return $downloadlink; } /* }}} */ + private static function __getAllInstances($queryStr, $dms) { /* {{{ */ + $db = $dms->getDB(); + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + + $downloadlinks = array(); + foreach($resArr as $rec) { + $document = $dms->getDocument($rec['document']); + $user = $dms->getUser($rec['userID']); + + $classname = $dms->getClassname('downloadlink'); + $downloadlink = new $classname($rec["id"], $document, $rec["version"], $user, $rec["hash"], $rec["valid"]); + $downloadlink->setDMS($dms); + $downloadlinks[] = $downloadlink; + } + return $downloadlinks; + } /* }}} */ + public static function getInstance($id, $dms) { /* {{{ */ - $queryStr = "SELECT * FROM tblDownloadLinks WHERE id = " . (int) $id; + $queryStr = "SELECT * FROM `tblDownloadLinks` WHERE `id` = " . (int) $id; return self::__getInstance($queryStr, $dms); } /* }}} */ public static function getInstanceByHash($hash, $dms) { /* {{{ */ - $queryStr = "SELECT * FROM tblDownloadLinks WHERE hash = " . $db->qstr($hash); + $queryStr = "SELECT * FROM `tblDownloadLinks` WHERE `hash` = " . $db->qstr($hash); return self::__getInstance($queryStr, $dms); } /* }}} */ + public static function getAllInstances($user, $version, $dms) { /* {{{ */ + $queryStr = "SELECT * FROM `tblDownloadLinks`"; + if($user || $version) { + $queryStr .= " WHERE"; + if($user) { + $queryStr .= " `userID` = " . (int) $user->getID(); + if($version) { + $queryStr .= " AND `version` = " . (int) $version; + } + } else { + $queryStr .= " `version` = " . (int) $version; + } + } + return self::__getAllInstances($queryStr, $dms); + } /* }}} */ + /* * Set dms this object belongs to. * @@ -120,4 +155,29 @@ class SeedDMS_Core_DownloadLink { /* {{{ */ return $this->_user; } /* }}} */ + /** + * Return hash of document link + * + * @return string hash of link + */ + function getHash() { /* {{{ */ + return $this->_hash; + } /* }}} */ + + /** + * Remove a download link + * + * @return boolean true on success, otherwise false + */ + function remove() { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "DELETE FROM `tblDownloadLinks` WHERE `id` = " . $this->_id; + if (!$db->getResult($queryStr)) { + return false; + } + + return true; + } /* }}} */ + } /* }}} */