/** * A ModelAbstract->setOnSave() function that tracks the change * * @see \MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved * @param string $name The name of the current field * @param array $context Optional, the other values being saved * @return string Of the values concatenated */ public function saveValue($value, $isNew = false, $name = null, array $context = array()) { // \MUtil_Echo::track($value, $this->_changedValue); // Once the value is set (and e.g. stored in the database) do not overwrite it if ($this->_changedValue == $value) { return $value; } $compare = $this->_model->get($name, __CLASS__); if (!(is_array($compare) && 2 === count($compare))) { // Actually a valid setting, do nothring return $value; } list($trackedField, $oldValueField) = $compare; if (!isset($context[$trackedField], $context[$oldValueField])) { return $value; } if (!($context[$trackedField] && $context[$oldValueField])) { return $context[$trackedField] || $context[$oldValueField] ? $this->_changedValue : $this->_unchangedValue; } $storageFormat = $this->_model->get($trackedField, 'storageFormat'); if (!$storageFormat) { return $context[$trackedField] == $context[$oldValueField] ? $this->_unchangedValue : $this->_changedValue; } if ($context[$oldValueField] instanceof \Zend_Date) { $oldValue = $context[$oldValueField]; } else { $oldValue = new \MUtil_Date($context[$oldValueField], $storageFormat); } if ($context[$trackedField] instanceof \Zend_Date) { $currentValue = $context[$trackedField]; } elseif (\Zend_Date::isDate($context[$trackedField], $storageFormat)) { $currentValue = new \MUtil_Date($context[$trackedField], $storageFormat); } else { if ($this->_model->has($trackedField, 'dateFormat')) { $secondFormat = $this->_model->get($trackedField, 'dateFormat'); } else { $secondFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat'); } if (!\Zend_Date::isDate($context[$trackedField], $secondFormat)) { // Cannot compare, do nothing return $value; } $currentValue = new \MUtil_Date($context[$trackedField], $secondFormat); } // \MUtil_Echo::track($trackedField, $oldValueField, $oldValue->toString(), $currentValue->toString(), $oldValue->getTimestamp() === $currentValue->getTimestamp()); return $oldValue->getTimestamp() === $currentValue->getTimestamp() ? $this->_unchangedValue : $this->_changedValue; }
/** * Are we past the valid until date * * @param array $tokenData * @return boolean */ protected function _isMissed($tokenData) { $missed = false; if (isset($tokenData['gto_valid_until'])) { $date = $tokenData['gto_valid_until']; if ($date instanceof \MUtil_Date) { $now = new \MUtil_Date(); if ($now->getTimestamp() - $date->getTimestamp() > 0) { $missed = true; } } } return $missed; }