Source for file DateVersionConstraint.class.php

Documentation is available at DateVersionConstraint.class.php

  1. <?php
  2.  
  3. require_once HARMONI."dataManager/versionConstraints/VersionConstraint.interface.php";
  4.  
  5. /**
  6. * Limits pruning based on a cutoff date, specified in the past. The date is passed to the constructor,
  7. * and can be a specific date or a relative date, like "-2 weeks" or "-12 hours". Dates in the future
  8. * will throw an error.
  9. *
  10. * @package harmoni.datamanager.versionconstraint
  11. *
  12. * @copyright Copyright &copy; 2005, Middlebury College
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  14. *
  15. * @version $Id: DateVersionConstraint.class.php,v 1.6 2007/09/04 20:25:33 adamfranco Exp $
  16. */
  17. class DateVersionConstraint extends VersionConstraint {
  18. var $_cutoffDate;
  19. function DateVersionConstraint( $relativeDateString ) {
  20. $now = time();
  21. $relative = strtotime($relativeDateString, $now);
  22. if ($relative === -1) {
  23. throwError( new Error("DateVersionConstraint: the passed relative date string, '$relativeDateString', does not appear to be valid.","DateVersionConstraint",true));
  24. }
  25. if ($relativeDateString >= $now) {
  26. throwError( new Error("DateVersionConstraint: the specified relative date must be in the PAST.", "DateVersionConstraint", true));
  27. }
  28. $this->_cutoffDate = $relative;
  29. }
  30. function checkRecordFieldValue($value) {
  31. foreach ($value->getVersionIDs() as $verID) {
  32. $ver =$value->getVersion($verID);
  33. if ($ver->isActive()) continue;
  34. $date =$ver->getDate();
  35. $timestamp = $date->toTimestamp();
  36. if ($timestamp < $this->_cutoffDate) {
  37. $ver->prune();
  38. }
  39. }
  40. }
  41. function checkTags($record) {
  42. $mgr = Services::getService("RecordTagManager");
  43. $tags =$mgr->fetchTagDescriptors($record->getID());
  44. if ($tags && is_array($tags)) {
  45. foreach (array_keys($tags) as $id) {
  46. $date =$tags[$id]->getDate();
  47. $timestamp = $date->toTimestamp();
  48. if ($timestamp < $this->_cutoffDate) {
  49. $mgr->pruneTag($tags[$id]);
  50. }
  51. }
  52. }
  53. }
  54. function checkRecord($record) {
  55. // do nothing
  56. return true;
  57. }
  58. }

Documentation generated on Wed, 19 Sep 2007 10:22:36 -0400 by phpDocumentor 1.3.0RC3