add new parameter and documentation for getDocumentsExpired()

This commit is contained in:
Uwe Steinmann 2020-05-27 12:00:58 +02:00
parent 42de312953
commit f737b20830
2 changed files with 25 additions and 8 deletions

View File

@ -662,20 +662,36 @@ class SeedDMS_Core_DMS {
/** /**
* Returns all documents which already expired or will expire in the future * Returns all documents which already expired or will expire in the future
* *
* The parameter $date will be relative to the start of the day. It can
* be either a number of days (if an integer is passed) or a date string
* in the format 'YYYY-MM-DD'.
* If the parameter $date is a negative number or a date in the past, then
* all documents from the start of that date till the end of the current
* day will be returned. If $date is a positive integer or $date is a
* date in the future, the all documents from the start of the current
* day till the end of the day of the given date will be returned.
* Passing 0 or the
* current date in $date, will return all documents expiring the current
* day.
* @param string $date date in format YYYY-MM-DD or an integer with the number * @param string $date date in format YYYY-MM-DD or an integer with the number
* of days. A negative value will cover the days in the past. * of days. A negative value will cover the days in the past.
* @param SeedDMS_Core_User $user * @param SeedDMS_Core_User $user limits the documents on those owned
* by this user
* @param string $orderby n=name, e=expired
* @param string $orderdir d=desc or a=asc
* @param bool $update update status of document if set to true
* @return bool|SeedDMS_Core_Document[] * @return bool|SeedDMS_Core_Document[]
*/ */
function getDocumentsExpired($date, $user=null) { /* {{{ */ function getDocumentsExpired($date, $user=null, $orderby='e', $orderdir='desc', $update=true) { /* {{{ */
$db = $this->getDB(); $db = $this->getDB();
if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) { if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) {
return false; return false;
} }
$tsnow = mktime(0, 0, 0); /* Start of today */
if(is_int($date)) { if(is_int($date)) {
$ts = mktime(0, 0, 0) + $date * 86400; $ts = $tsnow + $date * 86400;
} elseif(is_string($date)) { } elseif(is_string($date)) {
$tmp = explode('-', $date, 3); $tmp = explode('-', $date, 3);
if(count($tmp) != 3) if(count($tmp) != 3)
@ -684,11 +700,10 @@ class SeedDMS_Core_DMS {
} else } else
return false; return false;
$tsnow = mktime(0, 0, 0); /* Start of today */
if($ts < $tsnow) { /* Check for docs expired in the past */ if($ts < $tsnow) { /* Check for docs expired in the past */
$startts = $ts; $startts = $ts;
$endts = $tsnow+86400; /* Use end of day */ $endts = $tsnow+86400; /* Use end of day */
$updatestatus = true; $updatestatus = $update;
} else { /* Check for docs which will expire in the future */ } else { /* Check for docs which will expire in the future */
$startts = $tsnow; $startts = $tsnow;
$endts = $ts+86400; /* Use end of day */ $endts = $ts+86400; /* Use end of day */
@ -706,12 +721,12 @@ class SeedDMS_Core_DMS {
"LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` ". "LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` ".
"LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusLogID` = `ttstatid`.`maxLogID`"; "LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusLogID` = `ttstatid`.`maxLogID`";
$queryStr .= $queryStr .=
" WHERE `tblDocuments`.`expires` > ".$startts." AND `tblDocuments`.`expires` < ".$endts; " WHERE `tblDocuments`.`expires` >= ".$startts." AND `tblDocuments`.`expires` < ".$endts;
if($user) if($user)
$queryStr .= $queryStr .=
" AND `tblDocuments`.`owner` = '".$user->getID()."' "; " AND `tblDocuments`.`owner` = '".$user->getID()."' ";
$queryStr .= $queryStr .=
" ORDER BY `expires` DESC"; " ORDER BY ".($orderby == 'e' ? "`expires`" : "`name`")." ".($orderdir == 'd' ? "DESC" : "ASC");
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && !$resArr) if (is_bool($resArr) && !$resArr)
@ -721,8 +736,9 @@ class SeedDMS_Core_DMS {
$documents = array(); $documents = array();
foreach ($resArr as $row) { foreach ($resArr as $row) {
$document = $this->getDocument($row["id"]); $document = $this->getDocument($row["id"]);
if($updatestatus) if($updatestatus) {
$document->verifyLastestContentExpriry(); $document->verifyLastestContentExpriry();
}
$documents[] = $document; $documents[] = $document;
} }
return $documents; return $documents;

View File

@ -26,6 +26,7 @@
<notes> <notes>
- add new callback onSetStatus - add new callback onSetStatus
- fix SeedDMS_Core_DMS::getExpiredDocuments(), sql statement failed because temp. tables were not created - fix SeedDMS_Core_DMS::getExpiredDocuments(), sql statement failed because temp. tables were not created
- add parameters $orderdir, $orderby, $update to SeedDMS_Core::getExpiredDocuments()
</notes> </notes>
<contents> <contents>
<dir baseinstalldir="SeedDMS" name="/"> <dir baseinstalldir="SeedDMS" name="/">