diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 03b713229..26a196243 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -596,6 +596,70 @@ class SeedDMS_Core_DMS { return $user->getDocumentsLocked(); } /* }}} */ + /** + * Returns all documents which already expired or will expire in the future + * + * @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. + * @return array list of documents + */ + function getDocumentsExpired($date, $user=null) { /* {{{ */ + $db = $this->getDB(); + + if(is_int($date)) { + $ts = mktime(0, 0, 0) + $date * 86400; + } elseif(is_string($date)) { + $tmp = explode('-', $date, 3); + if(count($tmp) != 3) + return false; + $ts = mktime(0, 0, 0, $tmp[1], $tmp[2], $tmp[0]); + } 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; + } else { /* Check for docs which will expire in the future */ + $startts = $tsnow; + $endts = $ts+86400; /* Use end of day */ + $updatestatus = false; + } + + /* Get all documents which have an expiration date. It doesn't check for + * the latest status which should be S_EXPIRED, but doesn't have to, because + * status may have not been updated after the expiration date has been reached. + **/ + $queryStr = "SELECT `tblDocuments`.`id`, `tblDocumentStatusLog`.`status` FROM `tblDocuments` ". + "LEFT JOIN `ttcontentid` ON `ttcontentid`.`document` = `tblDocuments`.`id` ". + "LEFT JOIN `tblDocumentContent` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` AND `tblDocumentContent`.`version` = `ttcontentid`.`maxVersion` ". + "LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID` = `tblDocumentContent`.`document` AND `tblDocumentContent`.`version` = `tblDocumentStatus`.`version` ". + "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; + if($user) + $queryStr .= + " AND `tblDocuments`.`owner` = '".$user->getID()."' "; + $queryStr .= + " ORDER BY `expires` DESC"; + + $resArr = $db->getResultArray($queryStr); + if (is_bool($resArr) && !$resArr) + return false; + + $documents = array(); + $ts = mktime(0, 0, 0) + 86400; + foreach ($resArr as $row) { + $document = $this->getDocument($row["id"]); + if($updatestatus) + $document->verifyLastestContentExpriry(); + $documents[] = $document; + } + return $documents; + } /* }}} */ + /** * Returns a document by its name *