Source for file NumberVersionConstraint.class.php

Documentation is available at NumberVersionConstraint.class.php

  1. <?php
  2.  
  3. require_once HARMONI."dataManager/versionConstraints/VersionConstraint.interface.php";
  4.  
  5. /**
  6. * Removes versions based on the number for a certain value stored in the database. The maximum number
  7. * allowed is passed to the constructor, and any extra values will be deleted based on age.
  8. *
  9. * @package harmoni.datamanager.versionconstraint
  10. *
  11. * @copyright Copyright &copy; 2005, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: NumberVersionConstraint.class.php,v 1.5 2007/09/04 20:25:33 adamfranco Exp $
  15. */
  16. class NumberVersionConstraint extends VersionConstraint {
  17. var $_num;
  18. function NumberVersionConstraint( $num ) {
  19. $this->_num = $num;
  20. }
  21. function checkRecordFieldValue($value) {
  22. $numVers = $value->numVersions();
  23. if ($numVers <= $this->_num) return; // it's all good. nothing to do
  24. $timestamps = array();
  25. $versions = array();
  26. foreach ($value->getVersionIDs() as $verID) {
  27. $ver =$value->getVersion($verID);
  28. $date =$ver->getDate();
  29. $timestamp = $date->toTimestamp();
  30. $timestamps[] = $timestamp;
  31. $versions[$timestamp] =$ver;
  32. }
  33. // sort the versions from oldest to newest
  34. asort($timestamps);
  35. for ($i=0; $i<count($timestamps); $i++) {
  36. $tstamp = $timestamps[$i];
  37. if ($versions[$tstamp]->isActive()) continue;
  38. $versions[$tstamp]->prune();
  39. $numVers--;
  40. if ($numVers <= $this->_num) return;
  41. }
  42. }
  43. function checkTags($record) {
  44. // do nothing
  45. return;
  46. }
  47. function checkRecord($record) {
  48. // do nothing
  49. return true;
  50. }
  51. }

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