Пример #1
0
 /**
  * Given a value, attempt to convert the value to a db date format based on the format provided.  If the value
  * does not convert properly, meaning the value is not really in the format specified, then a
  * InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     if ($value == null) {
         return $value;
     }
     $timeStamp = CDateTimeParser::parse($value, $this->mappingRuleData['format']);
     if ($timeStamp === false) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid date format.'));
     }
     $dbDateValue = DateTimeUtil::convertTimestampToDbFormatDate($timeStamp);
     return $dbDateValue;
 }
Пример #2
0
 /**
  * Given a value, attempt to convert the value to a db date format based on the format provided.  If the value
  * does not convert properly, meaning the value is not really in the format specified, then a
  * InvalidValueToSanitizeException will be thrown.
  * @param string $modelClassName
  * @param string $attributeName
  * @param mixed $value
  * @param array $mappingRuleData
  */
 public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData)
 {
     assert('is_string($modelClassName)');
     assert('is_string($attributeName)');
     assert('isset($mappingRuleData["format"])');
     if ($value == null) {
         return $value;
     }
     $timeStamp = CDateTimeParser::parse($value, $mappingRuleData['format']);
     if ($timeStamp === false) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid date format.'));
     }
     $dbDateValue = DateTimeUtil::convertTimestampToDbFormatDate($timeStamp);
     return $dbDateValue;
 }
 /**
  * Utilized to create or update model attribute values after a workflow's triggers are fired as true.
  * @param WorkflowActionProcessingModelAdapter $adapter
  * @param $attribute
  * @throws NotSupportedException
  */
 public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
 {
     assert('is_string($attribute)');
     if ($this->type == static::TYPE_STATIC) {
         $adapter->getModel()->{$attribute} = $this->value;
     } elseif ($this->type == self::TYPE_DYNAMIC_FROM_TRIGGERED_DATE) {
         $adapter->getModel()->{$attribute} = DateTimeUtil::convertTimestampToDbFormatDate(time() + $this->value);
     } elseif ($this->type == self::TYPE_DYNAMIC_FROM_EXISTING_DATE) {
         if (!DateTimeUtil::isDateStringNull($adapter->getModel()->{$attribute})) {
             $existingTimeStamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp(DateTimeUtil::resolveDateAsDateTime($adapter->getModel()->{$attribute}));
             $newDate = DateTimeUtil::convertTimestampToDbFormatDate($existingTimeStamp + $this->value);
             $adapter->getModel()->{$attribute} = $newDate;
         }
     } else {
         throw new NotSupportedException();
     }
 }
 public function testDateResolveValueAndSetToModelUpdateAsDynamicFromTriggeredDate()
 {
     $form = new DateWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem');
     $form->type = DateWorkflowActionAttributeForm::TYPE_DYNAMIC_FROM_TRIGGERED_DATE;
     $form->durationInterval = '1';
     $model = new WorkflowModelTestItem();
     $model->date = '1980-06-03';
     $adapter = new WorkflowActionProcessingModelAdapter($model, Yii::app()->user->userModel);
     $form->resolveValueAndSetToModel($adapter, 'date');
     $this->assertEquals(DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400), $model->date);
 }
 /**
  * @depends testTriggerBeforeSaveAtLeastXBeforeTriggeredDate
  */
 public function testTriggerBeforeSaveLessThanXAfterTriggeredDate()
 {
     $workflow = self::makeOnSaveWorkflowAndTriggerForDateOrDateTime('date', 'Less Than X After Triggered Date', null, 'WorkflowsTestModule', 'WorkflowModelTestItem', null, 5, TimeDurationUtil::DURATION_TYPE_DAY);
     $model = new WorkflowModelTestItem();
     $model->lastName = 'someLastName';
     $model->string = 'something';
     //At this point the date value is null, so it should not trigger
     $this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     //Set the date to some time within the last day. it should pass
     $model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() - 86400);
     $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     $model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400);
     $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     $model = self::saveAndReloadModel($model);
     //Even though it changed, it changed to null, so it should not fire
     $model->date = null;
     $this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     $model = self::saveAndReloadModel($model);
     //This date is way in the future, so it should definitely not fire
     $model->date = '2020-07-03';
     $this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     //The date is 6 days in the future, it should not fire
     $model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400 * 6);
     $this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
     //This date is 5 days in the future, it should not fire
     $model->date = DateTimeUtil::convertTimestampToDbFormatDate(time() + 86400 * 5);
     $this->assertFalse(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model));
 }
 /**
  * @param SavedCalendarSubscriptions $savedCalendarSubscriptions
  * @param array $config
  */
 public function __construct(SavedCalendarSubscriptions $savedCalendarSubscriptions, array $config = array())
 {
     $this->savedCalendarSubscriptions = $savedCalendarSubscriptions;
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
     $this->startDate = DateTimeUtil::convertTimestampToDbFormatDate(strtotime($this->startDate));
     $this->endDate = DateTimeUtil::convertTimestampToDbFormatDate(strtotime($this->endDate));
     $this->_itemCount = 0;
 }