mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-28 10:30:42 +00:00
184 lines
4.7 KiB
PHP
184 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Implementation of a document in the document management system
|
|
*
|
|
* @category DMS
|
|
* @package SeedDMS_Core
|
|
* @license GPL2
|
|
* @author Markus Westphal, Malcolm Cowe, Matteo Lucarelli,
|
|
* Uwe Steinmann <uwe@steinmann.cx>
|
|
* @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 <uwe@steinmann.cx>
|
|
* @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['userID']);
|
|
|
|
$classname = $dms->getClassname('downloadlink');
|
|
$downloadlink = new $classname($resArr["id"], $document, $resArr["version"], $user, $resArr["hash"], $resArr["valid"]);
|
|
$downloadlink->setDMS($dms);
|
|
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;
|
|
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);
|
|
} /* }}} */
|
|
|
|
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.
|
|
*
|
|
* 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;
|
|
} /* }}} */
|
|
|
|
/**
|
|
* 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;
|
|
} /* }}} */
|
|
|
|
} /* }}} */
|