Commit e7c61114d110aac4e125c43c22cfbfb2ddda4947
1 parent
2b085590
updates for merging archiving settings table
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2233 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
259 additions
and
24 deletions
lib/archiving/ArchivingSettings.inc
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * $Id$ | ||
| 5 | + * | ||
| 6 | + * Represents archive settings for a document. | ||
| 7 | + * | ||
| 8 | + * Licensed under the GNU GPL. For full terms see the file COPYING. | ||
| 9 | + * | ||
| 10 | + * @version $Revision$ | ||
| 11 | + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | ||
| 12 | + * @package lib.archiving | ||
| 13 | + */ | ||
| 14 | + | ||
| 15 | +class ArchivingSettings { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * The primary key | ||
| 19 | + */ | ||
| 20 | + var $iId; | ||
| 21 | + /** | ||
| 22 | + * The archiving method- date or utilisation | ||
| 23 | + */ | ||
| 24 | + var $iArchivingTypeID; | ||
| 25 | + /** | ||
| 26 | + * The expiration date | ||
| 27 | + */ | ||
| 28 | + var $dExpirationDate; | ||
| 29 | + /** | ||
| 30 | + * The document transaction id | ||
| 31 | + */ | ||
| 32 | + var $iDocumentTransactionID; | ||
| 33 | + /** | ||
| 34 | + * The expiration time period | ||
| 35 | + */ | ||
| 36 | + var $iTimePeriodID; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Constructs an archive date settings instance | ||
| 40 | + * | ||
| 41 | + * @param date the expiration date | ||
| 42 | + * @param integer the expiration time period id | ||
| 43 | + */ | ||
| 44 | + function ArchivingSettings($iNewArchivingTypeID, $dNewExpirationDate, $iNewDocumentTransactionID, $iNewTimePeriodID) { | ||
| 45 | + global $default; | ||
| 46 | + | ||
| 47 | + // primary key not set as this is not stored yet | ||
| 48 | + $this->iId = -1; | ||
| 49 | + $this->iArchivingTypeID = $iNewArchivingTypeID; | ||
| 50 | + $this->setExpirationDate($dNewExpirationDate); | ||
| 51 | + $this->iDocumentTransactionID = $iNewDocumentTransactionID; | ||
| 52 | + $this->iTimePeriodID = $iNewTimePeriodID; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * Gets the primary key | ||
| 57 | + */ | ||
| 58 | + function getID(){ | ||
| 59 | + return $this->iId; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Gets the archiving type | ||
| 64 | + */ | ||
| 65 | + function getArchivingTypeID(){ | ||
| 66 | + return $this->iArchivingTypeID; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * Sets the archiving type | ||
| 71 | + * | ||
| 72 | + * @param integer the new archiving type | ||
| 73 | + */ | ||
| 74 | + function setArchivingTypeID($iNewArchivingTypeID){ | ||
| 75 | + $this->iArchivingTypeID = $iNewArchivingTypeID; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Gets the expiration date | ||
| 80 | + */ | ||
| 81 | + function getExpirationDate() { | ||
| 82 | + return ($this->dExpirationDate == "NULL" ? "" : $this->dExpirationDate); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Sets the expiration date | ||
| 87 | + * | ||
| 88 | + * @param date the new expiration date | ||
| 89 | + */ | ||
| 90 | + function setExpirationDate($dNewExpirationDate){ | ||
| 91 | + $this->dExpirationDate = strlen($dNewExpirationDate) == 0 ? "NULL" : $dNewExpirationDate; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Gets the document transaction id | ||
| 96 | + */ | ||
| 97 | + function getDocumentTransactionID() { | ||
| 98 | + return $this->iDocumentTransactionID; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Sets the document transaction id | ||
| 103 | + * | ||
| 104 | + * @param integer the new document transaction id | ||
| 105 | + */ | ||
| 106 | + function setDocumentTransactionID($iNewDocumentTransactionID){ | ||
| 107 | + $this->iDocumentTransactionID = $iNewDocumentTransactionID; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * Gets the time period id | ||
| 112 | + */ | ||
| 113 | + function getTimePeriodID(){ | ||
| 114 | + return $this->iTimePeriodID; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * Sets the time period id | ||
| 119 | + * | ||
| 120 | + * @param integer the new time period id | ||
| 121 | + */ | ||
| 122 | + function setTimePeriodID($iNewTimePeriodID){ | ||
| 123 | + $this->iTimePeriodID = $iNewTimePeriodID; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * Inserts the archive date settings into the database | ||
| 128 | + * | ||
| 129 | + * @return boolean true on successful update, false otherwise | ||
| 130 | + */ | ||
| 131 | + function create(){ | ||
| 132 | + global $default; | ||
| 133 | + //if the id >= 0, then the object has already been created | ||
| 134 | + if ($this->iId < 0) { | ||
| 135 | + $sql = $default->db; | ||
| 136 | + $sQuery = "INSERT INTO $default->owl_archiving_settings_table (archiving_type_id, expiration_date, document_transaction_id, time_period_id) " . | ||
| 137 | + "VALUES ($this->iArchivingTypeID, " . $this->addQuotes($this->dExpirationDate) . ", $this->iDocumentTransactionID, $this->iTimePeriodID)"; | ||
| 138 | + $result = $sql->query($sQuery); | ||
| 139 | + $default->log->info($sQuery); | ||
| 140 | + if ($result) { | ||
| 141 | + //set the current primary key | ||
| 142 | + $this->iId = $sql->insert_id(); | ||
| 143 | + return true; | ||
| 144 | + } | ||
| 145 | + return false; | ||
| 146 | + } | ||
| 147 | + return false; | ||
| 148 | + } | ||
| 149 | + function addQuotes($sDate) { | ||
| 150 | + if ($sDate == "NULL") { | ||
| 151 | + return $sDate; | ||
| 152 | + } else { | ||
| 153 | + return "'$sDate'"; | ||
| 154 | + } | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Update the archive date settings current values in the database | ||
| 159 | + * | ||
| 160 | + * @return boolean true on successful update, false otherwise | ||
| 161 | + */ | ||
| 162 | + function update(){ | ||
| 163 | + global $default; | ||
| 164 | + if ($this->iId >= 0) { | ||
| 165 | + $sql = $default->db; | ||
| 166 | + $sQuery = "UPDATE $default->owl_archiving_settings_table SET " . | ||
| 167 | + "archiving_type_id = $this->iArchivingTypeID, " . | ||
| 168 | + "expiration_date = " . $this->addQuotes($this->dExpirationDate) . ", " . | ||
| 169 | + "document_transaction_id = $this->iDocumentTransactionID, " . | ||
| 170 | + "time_period_id = $this->iTimePeriodID " . | ||
| 171 | + "WHERE id = $this->iId"; | ||
| 172 | + $default->log->info($sQuery); | ||
| 173 | + $result = $sql->query($sQuery); | ||
| 174 | + if ($result) { | ||
| 175 | + return true; | ||
| 176 | + } | ||
| 177 | + return false; | ||
| 178 | + } | ||
| 179 | + return false; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Delete the current archive date settings from the database. Set the primary key to -1 | ||
| 184 | + * on successful deletion | ||
| 185 | + * | ||
| 186 | + * @return boolean true and reset id to -1 on successful deletion, false otherwise | ||
| 187 | + */ | ||
| 188 | + function delete() { | ||
| 189 | + global $default; | ||
| 190 | + if ($this->iId >= 0) { | ||
| 191 | + $sql = $default->db; | ||
| 192 | + $result = $sql->query("DELETE FROM $default->owl_archiving_settings_table WHERE id = $this->iId"); | ||
| 193 | + if ($result) { | ||
| 194 | + $this->iId = -1; | ||
| 195 | + return true; | ||
| 196 | + } | ||
| 197 | + return false; | ||
| 198 | + } | ||
| 199 | + return false; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + /** | ||
| 203 | + * Static function. Given a primary key will create | ||
| 204 | + * a ArchivingSettings object and populate it with the corresponding | ||
| 205 | + * database values | ||
| 206 | + * | ||
| 207 | + * @return ArchivingSettings populated ArchivingSettings object on success, false otherwise | ||
| 208 | + */ | ||
| 209 | + function & get($iArchivingSettingsID) { | ||
| 210 | + global $default; | ||
| 211 | + $sql = $default->db; | ||
| 212 | + $sql->query("SELECT * FROM $default->owl_archiving_settings_table WHERE id = $iArchivingSettingsID"); | ||
| 213 | + if ($sql->next_record()) { | ||
| 214 | + $oArchivingSettings = & new ArchivingSettings($sql->f("archiving_type_id"), | ||
| 215 | + $sql->f("expiration_date"), | ||
| 216 | + $sql->f("document_transaction_id"), | ||
| 217 | + $sql->f("time_period_id")); | ||
| 218 | + $oArchivingSettings->iId = $iArchivingSettingsID; | ||
| 219 | + return $oArchivingSettings; | ||
| 220 | + } | ||
| 221 | + return false; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * Static function | ||
| 226 | + * Get a list of ArchivingSettings objects | ||
| 227 | + * | ||
| 228 | + * @param String Where clause (optional) | ||
| 229 | + * @return Array array of ArchivingSettings objects, false otherwise | ||
| 230 | + */ | ||
| 231 | + function getList($sWhereClause = null) { | ||
| 232 | + global $default; | ||
| 233 | + $aArchivingSettings = array(); | ||
| 234 | + $sql = $default->db; | ||
| 235 | + $result = $sql->query("SELECT * FROM $default->owl_archiving_settings_table " . (isset($sWhereClause) ? " WHERE " . $sWhereClause : "")); | ||
| 236 | + if ($result) { | ||
| 237 | + while ($sql->next_record()) { | ||
| 238 | + $oArchivingSettings = & ArchivingSettings::get($sql->f("id")); | ||
| 239 | + $aArchivingSettings[] = $oArchivingSettings; | ||
| 240 | + } | ||
| 241 | + return $aArchivingSettings; | ||
| 242 | + } | ||
| 243 | + return false; | ||
| 244 | + } | ||
| 245 | +} | ||
| 246 | +?> | ||
| 0 | \ No newline at end of file | 247 | \ No newline at end of file |
lib/archiving/DocumentArchiveSettingsFactory.inc
| 1 | <?php | 1 | <?php |
| 2 | require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiving.inc"); | 2 | require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiving.inc"); |
| 3 | -require_once("$default->fileSystemRoot/lib/archiving/ArchivingUtilisationSettings.inc"); | ||
| 4 | -require_once("$default->fileSystemRoot/lib/archiving/ArchivingDateSettings.inc"); | 3 | +require_once("$default->fileSystemRoot/lib/archiving/ArchivingSettings.inc"); |
| 5 | require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc"); | 4 | require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc"); |
| 6 | 5 | ||
| 7 | /** | 6 | /** |
| @@ -17,19 +16,7 @@ require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc"); | @@ -17,19 +16,7 @@ require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc"); | ||
| 17 | */ | 16 | */ |
| 18 | 17 | ||
| 19 | class DocumentArchiveSettingsFactory { | 18 | class DocumentArchiveSettingsFactory { |
| 20 | - var $iArchivingTypeID; | ||
| 21 | - var $sArchivingType; | ||
| 22 | 19 | ||
| 23 | - /** | ||
| 24 | - * Constructs a new factory for the specified archiving type | ||
| 25 | - */ | ||
| 26 | - function DocumentArchiveSettingsFactory($iArchivingTypeID) { | ||
| 27 | - global $default; | ||
| 28 | - | ||
| 29 | - $this->iArchivingTypeID = $iArchivingTypeID; | ||
| 30 | - $this->sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | function handleTimePeriod($iTimeUnitID, $iUnits) { | 20 | function handleTimePeriod($iTimeUnitID, $iUnits) { |
| 34 | if ($iTimeUnitID && $iUnits) { | 21 | if ($iTimeUnitID && $iUnits) { |
| 35 | // search for an existing time period id | 22 | // search for an existing time period id |
| @@ -52,20 +39,22 @@ class DocumentArchiveSettingsFactory { | @@ -52,20 +39,22 @@ class DocumentArchiveSettingsFactory { | ||
| 52 | return $iTimePeriodID; | 39 | return $iTimePeriodID; |
| 53 | } | 40 | } |
| 54 | 41 | ||
| 55 | - function create($iDocumentID, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) { | 42 | + function create($iArchivingTypeID, $iDocumentID, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) { |
| 56 | global $default; | 43 | global $default; |
| 57 | 44 | ||
| 45 | + $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID); | ||
| 46 | + | ||
| 58 | // process time period (if any) | 47 | // process time period (if any) |
| 59 | $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits); | 48 | $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits); |
| 60 | 49 | ||
| 61 | // construction strings | 50 | // construction strings |
| 62 | - switch ($this->sArchivingType) { | ||
| 63 | - case "Date" : $sSearchConstruction = "\$aArchiveSettings = ArchivingDateSettings::getList(\""; | 51 | + switch ($sArchivingType) { |
| 52 | + case "Date" : $sSearchConstruction = "\$aArchiveSettings = ArchivingSettings::getList(\""; | ||
| 64 | $sSearchConstruction .= (isset($dExpirationDate) ? "expiration_date='$dExpirationDate'" : "time_period_id=$iTimePeriodID") . "\");"; | 53 | $sSearchConstruction .= (isset($dExpirationDate) ? "expiration_date='$dExpirationDate'" : "time_period_id=$iTimePeriodID") . "\");"; |
| 65 | - $sConstruction = "\$oArchiveSettings = new ArchivingDateSettings(\$dExpirationDate, $iTimePeriodID);"; | 54 | + $sConstruction = "\$oArchiveSettings = new ArchivingSettings($iArchivingTypeID, \$dExpirationDate, -1, $iTimePeriodID);"; |
| 66 | break; | 55 | break; |
| 67 | - case "Utilisation" : $sSearchConstruction = "\$aArchiveSettings = ArchivingUtilisationSettings::getList(\"document_transaction_id=$iDocumentTransactionID AND time_period_id=$iTimePeriodID\");"; | ||
| 68 | - $sConstruction = "\$oArchiveSettings = new ArchivingUtilisationSettings($iDocumentTransactionID, $iTimePeriodID);"; | 56 | + case "Utilisation" : $sSearchConstruction = "\$aArchiveSettings = ArchivingSettings::getList(\"document_transaction_id=$iDocumentTransactionID AND time_period_id=$iTimePeriodID\");"; |
| 57 | + $sConstruction = "\$oArchiveSettings = new ArchivingSettings($iArchivingTypeID, \"NULL\", $iDocumentTransactionID, $iTimePeriodID);"; | ||
| 69 | break; | 58 | break; |
| 70 | } | 59 | } |
| 71 | 60 | ||
| @@ -86,7 +75,7 @@ class DocumentArchiveSettingsFactory { | @@ -86,7 +75,7 @@ class DocumentArchiveSettingsFactory { | ||
| 86 | } | 75 | } |
| 87 | 76 | ||
| 88 | // now link to the documents | 77 | // now link to the documents |
| 89 | - $oDocumentArchiving = new DocumentArchiving($iDocumentID, $this->iArchivingTypeID, $iArchiveSettingsID); | 78 | + $oDocumentArchiving = new DocumentArchiving($iDocumentID, $iArchiveSettingsID); |
| 90 | if ($oDocumentArchiving->create()) { | 79 | if ($oDocumentArchiving->create()) { |
| 91 | return true; | 80 | return true; |
| 92 | } else { | 81 | } else { |
| @@ -99,16 +88,16 @@ class DocumentArchiveSettingsFactory { | @@ -99,16 +88,16 @@ class DocumentArchiveSettingsFactory { | ||
| 99 | global $default; | 88 | global $default; |
| 100 | 89 | ||
| 101 | // retrieve the settings | 90 | // retrieve the settings |
| 102 | - $sRetrieveConstruction = "\$oArchiveSettings = Archiving" . $this->sArchivingType . "Settings::get(\"" . $oDocumentArchiving->getArchivingSettingsID(). "\");"; | ||
| 103 | - eval($sRetrieveConstruction); | 91 | + $oArchiveSettings = ArchivingSettings::get($oDocumentArchiving->getArchivingSettingsID()); |
| 104 | if ($oArchiveSettings) { | 92 | if ($oArchiveSettings) { |
| 105 | 93 | ||
| 106 | // process time period (if any) | 94 | // process time period (if any) |
| 107 | $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits); | 95 | $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits); |
| 108 | $oArchiveSettings->setTimePeriodID($iTimePeriodID); | 96 | $oArchiveSettings->setTimePeriodID($iTimePeriodID); |
| 109 | 97 | ||
| 98 | + $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $oArchiveSettings->getArchivingTypeID()); | ||
| 110 | // update it based on the type | 99 | // update it based on the type |
| 111 | - switch ($this->sArchivingType) { | 100 | + switch ($sArchivingType) { |
| 112 | case "Date" : $oArchiveSettings->setExpirationDate($dExpirationDate); | 101 | case "Date" : $oArchiveSettings->setExpirationDate($dExpirationDate); |
| 113 | break; | 102 | break; |
| 114 | case "Utilisation" : $oArchiveSettings->setDocumentTransactionID($iDocumentTransactionID); | 103 | case "Utilisation" : $oArchiveSettings->setDocumentTransactionID($iDocumentTransactionID); |