示例#1
0
 /**
  *
  * @param mixed $validFrom \Zend_Date or string
  * @param mixed $validUntil null, \Zend_Date or string. False values leave values unchangeds
  * @param int $userId The current user
  * @return int 1 if the token has changed, 0 otherwise
  */
 public function setValidFrom($validFrom, $validUntil, $userId)
 {
     if ($validFrom && $this->getMailSentDate()) {
         // Check for newerness
         if ($validFrom instanceof \Zend_Date) {
             $start = $validFrom;
         } else {
             $start = new \MUtil_Date($validFrom, \Gems_Tracker::DB_DATETIME_FORMAT);
         }
         if ($start->isLater($this->getMailSentDate())) {
             $values['gto_mail_sent_date'] = null;
             $values['gto_mail_sent_num'] = 0;
         }
     }
     if ($validFrom instanceof \Zend_Date) {
         $validFrom = $validFrom->toString(\Gems_Tracker::DB_DATETIME_FORMAT);
     } elseif ('' === $validFrom) {
         $validFrom = null;
     }
     if ($validUntil instanceof \Zend_Date) {
         $validUntil = $validUntil->toString(\Gems_Tracker::DB_DATETIME_FORMAT);
     } elseif ('' === $validUntil) {
         $validUntil = null;
     }
     $values['gto_valid_from'] = $validFrom;
     $values['gto_valid_until'] = $validUntil;
     return $this->_updateToken($values, $userId);
 }
 /**
  * Function to check whether the mail_sent should be reset
  *
  * @param boolean $isNew True when a new item is being saved
  * @param array $context The values being saved
  * @return boolean True when the change should be triggered
  */
 private function _checkForMailSent($isNew, array $context)
 {
     // Never change on new tokens
     if ($isNew) {
         return false;
     }
     // Only act on existing valid from date
     if (!(isset($context['gto_valid_from']) && $context['gto_valid_from'])) {
         return false;
     }
     // There must be data to reset
     $hasSentDate = isset($context['gto_mail_sent_date']) && $context['gto_mail_sent_date'];
     if (!($hasSentDate || isset($context['gto_mail_sent_num']) && $context['gto_mail_sent_num'])) {
         return false;
     }
     // When only the sent_num is set, then clear the existing data
     if (!$hasSentDate) {
         return true;
     }
     if ($context['gto_valid_from'] instanceof \Zend_Date) {
         $start = $context['gto_valid_from'];
     } else {
         $start = new \MUtil_Date($context['gto_valid_from'], $this->get('gto_valid_from', 'dateFormat'));
     }
     if ($context['gto_mail_sent_date'] instanceof \Zend_Date) {
         $sent = $context['gto_mail_sent_date'];
     } else {
         $sent = new \MUtil_Date($context['gto_mail_sent_date'], $this->get('gto_mail_sent_date', 'dateFormat'));
     }
     return $start->isLater($sent);
 }