- addContent() determines a new version number itself and doesn't relay

on the auto_increment of the database anymore
- some mor documentation
This commit is contained in:
steinm 2010-11-30 09:27:37 +00:00
parent 56b2211263
commit e3ad95de38

View File

@ -165,6 +165,15 @@ class LetoDMS_Document { /* {{{ */
return $this->_folder;
} /* }}} */
/**
* Set folder of a document
*
* This function basically moves a document from a folder to another
* folder.
*
* @param object $newFolder
* @return boolean false in case of an error, otherwise true
*/
function setFolder($newFolder) { /* {{{ */
$db = $this->_dms->getDB();
@ -775,28 +784,47 @@ class LetoDMS_Document { /* {{{ */
return 0;
} /* }}} */
function addContent($comment, $user, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers=array(), $approvers=array(),$version=0,$send_email=TRUE) { /* {{{ */
/**
* Add content to a document
*
* Each document may have any number of content elements attached to it.
* Each content element has a version number. Newer versions (greater
* version number) replace older versions.
*
* @param string $comment comment
* @param object $user user who shall be the owner of this content
* @param string $tmpFile file containing the actuall content
* @param string $orgFileName original file name
* @param string $mimeType MimeType of the content
* @param array $reviewers list of reviewers
* @param array $approvers list of approvers
* @param integer $version version number of content or 0 if next higher version shall be used.
* @return bool/array false in case of an error or a result set
*/
function addContent($comment, $user, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers=array(), $approvers=array(), $version=0) { /* {{{ */
$db = $this->_dms->getDB();
// the doc path is id/version.filetype
$dir = $this->getDir();
//Eintrag in tblDocumentContent
$date = mktime();
if ((int)$version<1){
/* The version field in table tblDocumentContent used to be auto
* increment but that requires the field to be primary as well if
* innodb is used. That's why the version is now determined here.
*/
if ((int)$version<1) {
$queryStr = "SELECT MAX(version) as m from tblDocumentContent where document = ".$this->_id;
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$res)
return false;
$queryStr = "INSERT INTO tblDocumentContent (document, comment, date, createdBy, dir, orgFileName, fileType, mimeType) VALUES ".
"(".$this->_id.", '".$comment."', ".$date.", ".$user->getID().", '".$dir."', '".$orgFileName."', '".$fileType."', '" . $mimeType . "')";
if (!$db->getResult($queryStr)) return false;
$version = $resArr[0]['m']+1;
}
$version = $db->getInsertID();
}else{
$queryStr = "INSERT INTO tblDocumentContent (document, version, comment, date, createdBy, dir, orgFileName, fileType, mimeType) VALUES ".
"(".$this->_id.", ".(int)$version.",'".$comment."', ".$date.", ".$user->getID().", '".$dir."', '".$orgFileName."', '".$fileType."', '" . $mimeType . "')";
if (!$db->getResult($queryStr)) return false;
}
// copy file
if (!LetoDMS_File::makeDir($this->_dms->contentDir . $dir)) return false;
@ -877,6 +905,13 @@ class LetoDMS_Document { /* {{{ */
return $docResultSet;
} /* }}} */
/**
* Return all content elements of a document
*
* This functions returns an array of content elements ordered by version
*
* @return array list of objects of class LetoDMS_DocumentContent
*/
function getContent() { /* {{{ */
$db = $this->_dms->getDB();
@ -894,6 +929,12 @@ class LetoDMS_Document { /* {{{ */
return $this->_content;
} /* }}} */
/**
* Return the content element of a document with a given version number
*
* @param integer $version version number of content element
* @return object object of class LetoDMS_DocumentContent
*/
function getContentByVersion($version) { /* {{{ */
if (!is_numeric($version)) return false;