Commit 4bff9ce4a44fbab58dd0b554d18d70a785f1e728

Authored by Michael Joseph
1 parent f0a4e03a

added update method


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1916 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/archiving/DocumentArchiveSettingsFactory.inc 0 → 100644
  1 +<?php
  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");
  5 +require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc");
  6 +
  7 +/**
  8 + * $Id$
  9 + *
  10 + * Business logic for setting document archive settings
  11 + *
  12 + * Licensed under the GNU GPL. For full terms see the file DOCS/COPYING.
  13 + *
  14 + * @version $Revision$
  15 + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa
  16 + * @package lib.archiving
  17 + */
  18 +
  19 +class DocumentArchiveSettingsFactory {
  20 + var $iArchivingTypeID;
  21 + var $sArchivingType;
  22 +
  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) {
  34 + if ($iTimeUnitID && $iUnits) {
  35 + // search for an existing time period id
  36 + $aTimePeriod = TimePeriod::getList("time_unit_id=$iTimeUnitID AND units=$iUnits");
  37 + if (count($aTimePeriod) > 0) {
  38 + $iTimePeriodID = $aTimePeriod[0]->getID();
  39 + } else {
  40 + // create it
  41 + $oTimePeriod = new TimePeriod($iTimeUnitID, $iUnits);
  42 + if ($oTimePeriod->create()) {
  43 + $iTimePeriodID = $oTimePeriod->getID();
  44 + } else {
  45 + $default->log->error("couldn't create time period- " . arrayToString($oTimePeriod));
  46 + return false;
  47 + }
  48 + }
  49 + } else {
  50 + $iTimePeriodID = -1;
  51 + }
  52 + return $iTimePeriodID;
  53 + }
  54 +
  55 + function create($iDocumentID, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) {
  56 + global $default;
  57 +
  58 + // process time period (if any)
  59 + $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits);
  60 +
  61 + // construction strings
  62 + switch ($this->sArchivingType) {
  63 + case "Date" : $sSearchConstruction = "\$aArchiveSettings = ArchivingDateSettings::getList(\"";
  64 + $sSearchConstruction .= (isset($dExpirationDate) ? "expiration_date='$dExpirationDate'" : "time_period_id=$iTimePeriodID") . "\");";
  65 + $sConstruction = "\$oArchiveSettings = new ArchivingDateSettings(\$dExpirationDate, $iTimePeriodID);";
  66 + break;
  67 + case "Utilisation" : $sSearchConstruction = "\$aArchiveSettings = ArchivingUtilisationSettings::getList(\"document_transaction_id=$iDocumentTransactionID AND time_period_id=$iTimePeriodID\");";
  68 + $sConstruction = "\$oArchiveSettings = new ArchivingUtilisationSettings($iDocumentTransactionID, $iTimePeriodID);";
  69 + break;
  70 + }
  71 +
  72 + // search for the settings first
  73 + eval($sSearchConstruction);
  74 + if (count($aArchiveSettings) > 0) {
  75 + $iArchiveSettingsID = $aArchiveSettings[0]->getID();
  76 + $default->log->info("looked up archive settings id=$iArchiveSettingsID");
  77 + } else {
  78 + // create them
  79 + eval($sConstruction);
  80 + if ($oArchiveSettings->create()) {
  81 + $iArchiveSettingsID = $oArchiveSettings->getID();
  82 + } else {
  83 + $default->log->error("couldn't create archive settings- " . arrayToString($oArchiveSettings));
  84 + return false;
  85 + }
  86 + }
  87 +
  88 + // now link to the documents
  89 + $oDocumentArchiving = new DocumentArchiving($iDocumentID, $this->iArchivingTypeID, $iArchiveSettingsID);
  90 + if ($oDocumentArchiving->create()) {
  91 + return true;
  92 + } else {
  93 + $default->log->error("couldn't create document archiving - " . arrayToString($oDocumentArchiving));
  94 + return false;
  95 + }
  96 + }
  97 +
  98 + function update($oDocumentArchiving, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) {
  99 + global $default;
  100 +
  101 + // retrieve the settings
  102 + $sRetrieveConstruction = "\$oArchiveSettings = Archiving" . $this->sArchivingType . "Settings::get(\"" . $oDocumentArchiving->getArchivingSettingsID(). "\");";
  103 + eval($sRetrieveConstruction);
  104 + if ($oArchiveSettings) {
  105 +
  106 + // process time period (if any)
  107 + $iTimePeriodID = $this->handleTimePeriod($iTimeUnitID, $iUnits);
  108 + $oArchiveSettings->setTimePeriodID($iTimePeriodID);
  109 +
  110 + // update it based on the type
  111 + switch ($this->sArchivingType) {
  112 + case "Date" : $oArchiveSettings->setExpirationDate($dExpirationDate);
  113 + break;
  114 + case "Utilisation" : $oArchiveSettings->setDocumentTransactionID($iDocumentTransactionID);
  115 + break;
  116 + }
  117 + if ($oArchiveSettings->update()) {
  118 + return true;
  119 + } else {
  120 + $default->log->error("error updating archive settings for documentID=" . $oArchiveSettings->getDocumentID());
  121 + }
  122 + } else {
  123 + $default->log->error("couldn't retrieve archive settings");
  124 + return false;
  125 + }
  126 + }
  127 +}
  128 +?>
0 129 \ No newline at end of file
... ...