/**
  * note: listener hook fires after record hook
  * (non-PHPdoc)
  * @see branch/vendors/doctrine/Doctrine/Record/Doctrine_Record_Listener#preSave()
  */
 public function preSave(Doctrine_Event $event)
 {
     // housekeeping
     $record = $event->getInvoker();
     $this->limitParentDates($record);
     // set any runtime defaults here
     if (!$record->getEffectiveDate()) {
         // effective date defaults to the table's currently set query date
         $record->{$this->_options['eff_date']} = date($this->date_format);
     }
     // sanity checks
     if (!$record->isModified()) {
         // no changes? don't check anything
         return;
     }
     // don't save an instantaneous or nonsense record
     if (!is_null($record->getExpirationDate())) {
         if ($record->getEffectiveDate() == $record->getExpirationDate()) {
             throw new Doctrine_Record_SavingNonsenseException("Won't save instantaneous {$record->getTable()->getComponentName()} record with effective & expiration: " . $record->getEffectiveDate());
         } elseif ($record->getEffectiveDate() > $record->getExpirationDate()) {
             throw new Doctrine_Record_SavingNonsenseException("Won't save {$record->getTable()->getComponentName()} record with effective > expiration: " . $record->getEffectiveDate() . " > " . $record->getExpirationDate());
         }
     }
     /**
      * validation: can't modify past dates
      * - can't change expired records (exp_date < today)
      * - can't change past eff_date (eff_date < today)
      *  - if changing eff_date to future on current record, then this will force creation of new, future record AND truncate the current one TODAY.
      */
     if (Doctrine_Template_Temporal::isTemporalEnforcementSet() && !$this->_options['allow_past_modifications']) {
         $this->enforceTemporalModConstraints($record);
     }
     // after finalizing & checking all the date values, is there a temporal unique constraint violation?
     $record->enforceTemporalUniqueness();
 }
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     $segment_options = $this->_options;
     $segment_options['parents'][] = $segment_options['parent_alias'];
     // enforce temporal parent/child constraints
     if (isset($segment_options['segment_classname'])) {
         $segment_options['className'] = $segment_options['segment_classname'];
         unset($segment_options['segment_classname']);
     } else {
         unset($segment_options['className']);
         // let it default
     }
     unset($segment_options['children']);
     // interferes with Doctrine_Record_Generator
     $this->_plugin = new Doctrine_Record_Generator_TemporalSegment($segment_options);
     $this->_options['children'][] = $this->_options['child_alias'];
     // enforce temporal parent/child constraints
 }
 public static function setTemporalEnforcement($enforce = true)
 {
     self::$enforce_temporal_constraints = $enforce;
 }