mirror of
https://git.code.sf.net/p/seeddms/code
synced 2026-01-27 11:39:15 +00:00
add method __getAllInstances(), use right db field for user
This commit is contained in:
parent
5739611595
commit
2407f5c5e6
|
|
@ -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;
|
||||
} /* }}} */
|
||||
|
||||
} /* }}} */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user