add SeedDMS_Core_Document::transferToUser()

This commit is contained in:
Uwe Steinmann 2017-12-05 18:31:04 +01:00
parent bd616ac46e
commit b68cfe3893
2 changed files with 47 additions and 0 deletions

View File

@ -2429,6 +2429,52 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
return $timeline;
} /* }}} */
/**
* Transfers the document to a new user
*
* This method not just sets a new owner of the document but also
* transfers the document links, attachments and locks to the new user.
*
* @return boolean true if successful, otherwise false
*/
function transferToUser($newuser) { /* {{{ */
$db = $this->_dms->getDB();
if($newuser->getId() == $this->_ownerID)
return true;
$db->startTransaction();
$queryStr = "UPDATE `tblDocuments` SET `owner` = ".$newuser->getId()." WHERE `id` = " . $this->_id;
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
$queryStr = "UPDATE `tblDocumentLocks` SET `userID` = ".$newuser->getId()." WHERE `document` = " . $this->_id . " AND `userID` = ".$this->_ownerID;
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
$queryStr = "UPDATE `tblDocumentLinks` SET `userID` = ".$newuser->getId()." WHERE `document` = " . $this->_id . " AND `userID` = ".$this->_ownerID;
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
$queryStr = "UPDATE `tblDocumentFiles` SET `userID` = ".$newuser->getId()." WHERE `document` = " . $this->_id . " AND `userID` = ".$this->_ownerID;
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
$this->_ownerID = $newuser->getID();
$this->_owner = $newuser;
$db->commitTransaction();
return true;
} /* }}} */
} /* }}} */

View File

@ -27,6 +27,7 @@
- use views instead of temp. tables
- add list of expired documents in SeedDMS_Core_DMS::getDocumentList()
- add methods to set comment, name, public, version of document files
- add method SeedDMS_Core_Document::transferToUser()
</notes>
<contents>
<dir baseinstalldir="SeedDMS" name="/">