diff --git a/SeedDMS_Core/Core.php b/SeedDMS_Core/Core.php index 0f7b956ea..d9ae9b206 100644 --- a/SeedDMS_Core/Core.php +++ b/SeedDMS_Core/Core.php @@ -96,4 +96,9 @@ require_once('Core/inc.FileUtils.php'); */ require_once('Core/inc.ClassTransmittal.php'); +/** + * @uses SeedDMS_DownloadLink + */ +require_once('Core/inc.ClassDownloadLink.php'); + ?> diff --git a/SeedDMS_Core/Core/inc.ClassDownloadLink.php b/SeedDMS_Core/Core/inc.ClassDownloadLink.php new file mode 100644 index 000000000..213518fc6 --- /dev/null +++ b/SeedDMS_Core/Core/inc.ClassDownloadLink.php @@ -0,0 +1,123 @@ + + * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, + * 2010 Matteo Lucarelli, 2010 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class to represent a download link in the document management system + * + * Download links are access rights to a particular document version. + * + * @category DMS + * @package SeedDMS_Core + * @author Uwe Steinmann + * @copyright Copyright (C) 2016 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Core_DownloadLink { /* {{{ */ + /** + * @var integer unique id of object + */ + protected $_id; + + /** + * @var object document belonging to link + */ + protected $_document; + + /** + * @var integer version of document + */ + protected $_version; + + /** + * @var object user owning the document link + */ + protected $_user; + + /** + * @var string hash of document link + */ + protected $_hash; + + /** + * @var date date till links valid + */ + protected $_valid; + + /** + * @var object back reference to document management system + */ + public $_dms; + + function __construct($id, $document, $version, $user, $hash, $valid) { /* {{{ */ + $this->_id = $id; + $this->_dms = null; + $this->_document = $document; + $this->_version = $version; + $this->_user = $user; + $this->_hash = $hash; + $this->_valid = $valid; + } /* }}} */ + + private static function __getInstance($queryStr, $dms) { /* {{{ */ + $db = $dms->getDB(); + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && $resArr == false) + return false; + if (count($resArr) != 1) + return false; + $resArr = $resArr[0]; + + $document = $dms->getDocument($resArr['document']); + $user = $dms->getUser($resArr['user']); + + $classname = $dms->getClassname('downloadlink'); + $downloadlink = new $classname($resArr["id"], $document, $resArr["version"], $user, $resArr["hash"], $resArr["valid"]); + $downloadlink->setDMS($dms); + return $downloadlink; + } /* }}} */ + + public static function getInstance($id, $dms) { /* {{{ */ + $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); + return self::__getInstance($queryStr, $dms); + } /* }}} */ + + /* + * Set dms this object belongs to. + * + * Each object needs a reference to the dms it belongs to. It will be + * set when the object is created. + * The dms has a references to the currently logged in user + * and the database connection. + * + * @param object $dms reference to dms + */ + function setDMS($dms) { /* {{{ */ + $this->_dms = $dms; + } /* }}} */ + + /** + * Return owner of document link + * + * @return object owner of document link as an instance of {@link SeedDMS_Core_User} + */ + function getUser() { /* {{{ */ + return $this->_user; + } /* }}} */ + +} /* }}} */