Пример #1
0
 /**
  * Validates the attribute of the model.
  * If there is any error, the error message is added to the model.
  * @param RedBeanModel $model the model being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     switch ($this->type) {
         case 'blob':
         case 'longblob':
             return;
         case 'integer':
             $valid = preg_match('/^[-+]?[0-9]+$/', trim($value));
             // Not Coding Standard
             break;
         case 'float':
             $valid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($value));
             // Not Coding Standard
             break;
         case 'date':
             $valid = DateTimeUtil::isValidDbFormattedDate($value);
             break;
         case 'time':
             $valid = CDateTimeParser::parse($value, $this->timeFormat) !== false;
             break;
         case 'datetime':
             $valid = DateTimeUtil::isValidDbFormattedDateTime($value);
             break;
         case 'array':
             $valid = is_array($value);
             break;
         case 'string':
         default:
             return;
     }
     if (!$valid) {
         if ($this->message !== null) {
             $message = $this->message;
         } else {
             $message = Zurmo::t('Core', '{attribute} must be {type}.');
         }
         $this->addError($object, $attribute, $message, array('{type}' => $this->type));
     }
 }
Пример #2
0
 public function testIsValidDbFormattedDate()
 {
     $this->assertTrue(DateTimeUtil::isValidDbFormattedDate('2011-09-23'));
     $this->assertTrue(DateTimeUtil::isValidDbFormattedDate('1756-01-01'));
     $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('0011-09-23'));
     $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('2011-13-32'));
     $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('zxczxc'));
 }
Пример #3
0
 /**
  * Gets full calendar formatted date time.
  * @param string $dateTime
  * @return string formatted in datetime format required for full calendar widget
  */
 public static function getFullCalendarFormattedDateTimeElement($dateTime)
 {
     assert('is_string($dateTime)');
     //The reason its put because timezone can vary from -12:00 to +12:00 max so
     //if we offset the gmt date by timezoneoffset, on applying offset, correct results
     //would come.
     if (DateTimeUtil::isValidDbFormattedDate($dateTime)) {
         $dateTime = DateTimeUtil::convertDateToDateTimeByTimeZoneOffset($dateTime);
     }
     $dateTimeObject = new DateTime();
     $dateTimeObject->setTimestamp(strtotime($dateTime));
     $offset = ZurmoTimeZoneHelper::getTimeZoneOffset();
     if ($offset < 0) {
         $offset = abs($offset);
         $dateTimeObject->sub(new DateInterval('PT' . $offset . 'S'));
     } else {
         $dateTimeObject->add(new DateInterval('PT' . $offset . 'S'));
     }
     return $dateTimeObject->format('c');
 }