diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 7fdba28d5..83537c1de 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -662,20 +662,36 @@ class SeedDMS_Core_DMS { /** * 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 * 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[] */ - function getDocumentsExpired($date, $user=null) { /* {{{ */ + function getDocumentsExpired($date, $user=null, $orderby='e', $orderdir='desc', $update=true) { /* {{{ */ $db = $this->getDB(); if (!$db->createTemporaryTable("ttstatid") || !$db->createTemporaryTable("ttcontentid")) { return false; } + $tsnow = mktime(0, 0, 0); /* Start of today */ if(is_int($date)) { - $ts = mktime(0, 0, 0) + $date * 86400; + $ts = $tsnow + $date * 86400; } elseif(is_string($date)) { $tmp = explode('-', $date, 3); if(count($tmp) != 3) @@ -684,11 +700,10 @@ class SeedDMS_Core_DMS { } else return false; - $tsnow = mktime(0, 0, 0); /* Start of today */ if($ts < $tsnow) { /* Check for docs expired in the past */ $startts = $ts; $endts = $tsnow+86400; /* Use end of day */ - $updatestatus = true; + $updatestatus = $update; } else { /* Check for docs which will expire in the future */ $startts = $tsnow; $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 `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusLogID` = `ttstatid`.`maxLogID`"; $queryStr .= - " WHERE `tblDocuments`.`expires` > ".$startts." AND `tblDocuments`.`expires` < ".$endts; + " WHERE `tblDocuments`.`expires` >= ".$startts." AND `tblDocuments`.`expires` < ".$endts; if($user) $queryStr .= " AND `tblDocuments`.`owner` = '".$user->getID()."' "; $queryStr .= - " ORDER BY `expires` DESC"; + " ORDER BY ".($orderby == 'e' ? "`expires`" : "`name`")." ".($orderdir == 'd' ? "DESC" : "ASC"); $resArr = $db->getResultArray($queryStr); if (is_bool($resArr) && !$resArr) @@ -721,8 +736,9 @@ class SeedDMS_Core_DMS { $documents = array(); foreach ($resArr as $row) { $document = $this->getDocument($row["id"]); - if($updatestatus) + if($updatestatus) { $document->verifyLastestContentExpriry(); + } $documents[] = $document; } return $documents; diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index 54f316133..e8364dc0c 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -26,6 +26,7 @@ - add new callback onSetStatus - fix SeedDMS_Core_DMS::getExpiredDocuments(), sql statement failed because temp. tables were not created +- add parameters $orderdir, $orderby, $update to SeedDMS_Core::getExpiredDocuments()