示例#1
0
 /**
  * Return the number of days since last change of password
  *
  * @return int
  */
 public function getPasswordAge()
 {
     $date = \MUtil_Date::ifDate($this->_getVar('user_password_last_changed'), array(\Gems_Tracker::DB_DATETIME_FORMAT, \Gems_Tracker::DB_DATE_FORMAT, \Zend_Date::ISO_8601));
     if ($date instanceof \MUtil_Date) {
         return abs($date->diffDays());
     } else {
         return 0;
     }
 }
 /**
  *
  * @param string $fieldName
  * @return \MUtil_Date
  */
 public function getDate($fieldName)
 {
     if (isset($this->_respTrackData[$fieldName])) {
         $date = $this->_respTrackData[$fieldName];
     } else {
         $this->_ensureFieldData();
         if (isset($this->_fieldData[$fieldName])) {
             $date = $this->_fieldData[$fieldName];
             if ($this->getTrackEngine()->isAppointmentField($fieldName)) {
                 $appointment = $this->tracker->getAppointment($date);
                 if ($appointment->isActive()) {
                     $date = $appointment->getAdmissionTime();
                 } else {
                     $date = false;
                 }
             }
         } else {
             $date = false;
         }
     }
     if ($date) {
         return \MUtil_Date::ifDate($date, array(\Gems_Tracker::DB_DATETIME_FORMAT, \Gems_Tracker::DB_DATE_FORMAT));
     }
 }
示例#3
0
 /**
  *
  * @param string|\MUtil_Date $completionTime Completion time as a date or null
  * @param int $userId The current user
  * @return \Gems_Tracker_Token (continuation pattern)
  */
 public function setCompletionTime($completionTime, $userId)
 {
     if (null === $completionTime) {
         $values['gto_completion_time'] = null;
     } else {
         if (!$completionTime instanceof \Zend_Date) {
             $completionTime = \MUtil_Date::ifDate($completionTime, array(\Gems_Tracker::DB_DATETIME_FORMAT, \Gems_Tracker::DB_DATE_FORMAT, null));
         }
         $values['gto_completion_time'] = $completionTime->toString(\Gems_Tracker::DB_DATETIME_FORMAT);
     }
     $changed = $this->_updateToken($values, $userId);
     $survey = $this->getSurvey();
     $source = $survey->getSource();
     $source->setTokenCompletionTime($this, $completionTime, $survey->getSurveyId(), $survey->getSourceSurveyId());
     $this->refresh();
     $this->checkTokenCompletion($userId);
     return $this;
 }
 /**
  * Converting the field value when saving to a respondent track
  *
  * @param array $currentValue The current value
  * @param array $fieldData The other values loaded so far
  * @return mixed the new value
  */
 public function onFieldDataSave($currentValue, array $fieldData)
 {
     if (null === $currentValue || $currentValue instanceof \Zend_Db_Expr || \MUtil_String::startsWith($currentValue, 'current_', true)) {
         return $currentValue;
     }
     $saveFormat = $this->getStorageFormat();
     if ($currentValue instanceof \Zend_Date) {
         return $currentValue->toString($saveFormat);
     } else {
         $displayFormat = $this->getDateFormat();
         $saveDate = \MUtil_Date::ifDate($currentValue, array($displayFormat, $saveFormat, \Gems_Tracker::DB_DATETIME_FORMAT));
         if ($saveDate instanceof \Zend_Date) {
             return $saveDate->toString($saveFormat);
         }
     }
     return (string) $currentValue;
 }
 /**
  * A ModelAbstract->setOnLoad() function that takes care of transforming a
  * dateformat read from the database to a \Zend_Date format
  *
  * If empty or \Zend_Db_Expression (after save) it will return just the value
  * currently there are no checks for a valid date format.
  *
  * @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
  * @param boolean $isPost True when passing on post data
  * @return \MUtil_Date|\Zend_Db_Expr|null
  */
 public function formatLoadDate($value, $isNew = false, $name = null, array $context = array(), $isPost = false)
 {
     static $formats;
     // If not empty or zend_db_expression and not already a zend date, we
     // transform to a \Zend_Date using the stored formats
     if (null === $value || $value instanceof \Zend_Date || $value instanceof \Zend_Db_Expr) {
         return $value;
     }
     if (!isset($formats[$name][$isPost])) {
         // Stored the used formats (as they are usually used often within a model)
         if ($isPost) {
             // Add possible custom format
             $formats[$name][$isPost][] = $this->_getKeyValue($name, 'dateFormat');
             // Add default format as a fallback
             $type = \MUtil_Date_Format::getDateTimeType($this->_getKeyValue($name, 'dateFormat'));
             $formats[$name][$isPost][] = \MUtil_Model_Bridge_FormBridge::getFixedOption($type, 'dateFormat');
         }
         $formats[$name][$isPost][] = $this->_getKeyValue($name, 'storageFormat');
     }
     return \MUtil_Date::ifDate($value, $formats[$name][$isPost]);
 }
 /**
  * Get a readable version of date / time object with nearby days translated in text
  *
  * @param \MUtil_Date $dateTimeValue
  * @return string
  */
 public function formatDateTime($dateTimeValue)
 {
     if (!$dateTimeValue) {
         return null;
     }
     //$dateTime = strtotime($dateTimeValue);
     // \MUtil_Echo::track($dateTimeValue, date('c', $dateTime), $dateTime / 86400, date('c', time()), time() / 86400);
     // TODO: Timezone seems to screw this one up
     //$days = floor($dateTime / 86400) - floor(time() / 86400); // 86400 = 24*60*60
     if ($dateTimeValue instanceof \MUtil_Date) {
         $dateTime = $dateTimeValue;
     } else {
         $dateTime = \MUtil_Date::ifDate($dateTimeValue, array(\Gems_Tracker::DB_DATETIME_FORMAT, \Gems_Tracker::DB_DATE_FORMAT, \Zend_Date::ISO_8601));
         if (!$dateTime) {
             return null;
         }
     }
     $days = $dateTime->diffDays();
     switch ($days) {
         case -2:
             return $this->_('2 days ago');
         case -1:
             return $this->_('Yesterday');
         case 0:
             return $this->_('Today');
         case 1:
             return $this->_('Tomorrow');
         case 2:
             return $this->_('Over 2 days');
         default:
             if ($days > -14 && $days < 14) {
                 if ($days > 0) {
                     return sprintf($this->_('Over %d days'), $days);
                 } else {
                     return sprintf($this->_('%d days ago'), -$days);
                 }
             }
             return date($this->phpDateFormatString, $dateTime->getTimestamp());
             //  . ' (' . $days . ')';
     }
 }