protected static function renderExpirationDateTimeContent(GameReward $gameReward)
 {
     if (!DateTimeUtil::isDateTimeStringNull($gameReward->expirationDateTime)) {
         $content = Zurmo::t('ZurmoModule', 'Until') . ' ';
         return $content . DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($gameReward->expirationDateTime);
     }
 }
 /**
  * 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_DATETIME) {
         $newTimeStamp = $this->resolveNewTimeStampForDuration(time());
         $adapter->getModel()->{$attribute} = DateTimeUtil::convertTimestampToDbFormatDateTime($newTimeStamp);
     } elseif ($this->type == self::TYPE_DYNAMIC_FROM_EXISTING_DATETIME) {
         if (!DateTimeUtil::isDateTimeStringNull($adapter->getModel()->{$attribute})) {
             $existingTimeStamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($adapter->getModel()->{$attribute});
             $newTimeStamp = $this->resolveNewTimeStampForDuration($existingTimeStamp);
             $newDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($newTimeStamp);
             $adapter->getModel()->{$attribute} = $newDateTime;
         }
     } else {
         throw new NotSupportedException();
     }
 }
 /**
  * @param Item $item
  * @param $dateTime
  * @param $modelClassName
  * @throws FailedToSaveModelException
  */
 public static function resolveItemToModelAndPopulateLatestActivityDateTime(Item $item, $dateTime, $modelClassName)
 {
     assert('is_string($dateTime)');
     assert('is_string($modelClassName)');
     $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($modelClassName);
     try {
         $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
         if (DateTimeUtil::isDateTimeStringNull($castedDownModel->latestActivityDateTime) || $dateTime > $castedDownModel->latestActivityDateTime) {
             $castedDownModel->setLatestActivityDateTime($dateTime);
             $saved = $castedDownModel->save();
             if (!$saved) {
                 throw new FailedToSaveModelException();
             }
         }
     } catch (NotFoundException $e) {
         //do nothing
     } catch (AccessDeniedSecurityException $e) {
         //do nothing, since the current user cannot update the related model. Fail silently.
     }
 }
 /**
  * Given a event, check that the event's sender is a EmailMessage and then check to process updating a related
  * contact's latestActivityDateTime if it should
  * Both sent and archived emails will have the sentDateTime just populated.
  * @param CEvent $event
  */
 public function updateContactLatestActivityDateTimeByEmailMessage(CEvent $event)
 {
     assert('$event->sender instanceof EmailMessage');
     //Check for a just sent message
     if (array_key_exists('sentDateTime', $event->sender->originalAttributeValues) && !DateTimeUtil::isDateTimeStringNull($event->sender->sentDateTime)) {
         foreach ($event->sender->sender->personsOrAccounts as $senderPersonsOrAccount) {
             $this->resolveItemToModelAndPopulateLatestActivityDateTime($senderPersonsOrAccount, $event->sender->sentDateTime, 'Contact');
         }
         foreach ($event->sender->recipients as $emailMessageRecipient) {
             foreach ($emailMessageRecipient->personsOrAccounts as $recipientPersonsOrAccount) {
                 $this->resolveItemToModelAndPopulateLatestActivityDateTime($recipientPersonsOrAccount, $event->sender->sentDateTime, 'Contact');
             }
         }
     }
 }
Пример #5
0
 /**
  * For a given model, and dateTime attribute, resolve to add a job by the job type. The delay is calculated
  * based on the value of the dateTime attribute
  * @param RedBeanModel $model
  * @param $attributeName
  * @param $jobType
  */
 public function resolveToAddJobTypeByModelByDateTimeAttribute(RedBeanModel $model, $attributeName, $jobType)
 {
     assert('is_string($attributeName)');
     assert('is_string($jobType)');
     if ($model->getIsNewModel() || isset($model->originalAttributeValues[$attributeName])) {
         if (DateTimeUtil::isDateTimeStringNull($model->{$attributeName})) {
             $secondsFromNow = 0;
         } else {
             $processDateTimeStamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($model->{$attributeName});
             $secondsFromNow = $processDateTimeStamp - time();
         }
         if ($secondsFromNow <= 0) {
             $delay = 0;
         } else {
             $delay = $secondsFromNow;
         }
         Yii::app()->jobQueue->add($jobType, $delay + 5);
     }
 }
 /**
  * @param TimeTriggerForWorkflowForm $trigger
  * @param RedBeanModel $model
  * @return int
  * @throws ValueForProcessDateTimeIsNullException
  */
 protected static function resolveTimeStampForDateTimeAttributeForProcessDateTime(TimeTriggerForWorkflowForm $trigger, RedBeanModel $model)
 {
     $dateTime = static::resolveModelValueByTimeTrigger($trigger, $model);
     if (DateTimeUtil::isDateTimeStringNull($dateTime)) {
         throw new ValueForProcessDateTimeIsNullException();
     } else {
         return $trigger->resolveNewTimeStampForDuration(DateTimeUtil::convertDbFormatDateTimeToTimestamp($dateTime));
     }
 }
Пример #7
0
 /**
  * Process data provider and get calendar items.
  * @param CalendarItemsDataProvider $dataProvider
  * @return boolean
  */
 public static function processDataProviderAndGetCalendarItems(CalendarItemsDataProvider $dataProvider)
 {
     $calendarItems = $dataProvider->getData(true);
     $fullCalendarItems = array();
     for ($k = 0; $k < count($calendarItems); $k++) {
         $fullCalendarItem = array();
         $calItem = $calendarItems[$k];
         $fullCalendarItem['title'] = $calItem->getTitle();
         $fullCalendarItem['start'] = $calItem->getStartDateTime();
         if (!DateTimeUtil::isDateTimeStringNull($calItem->getEndDateTime())) {
             $fullCalendarItem['end'] = $calItem->getEndDateTime();
         } else {
             $fullCalendarItem['end'] = '';
         }
         $fullCalendarItem['color'] = $calItem->getColor();
         $fullCalendarItem['modelClass'] = $calItem->getModelClass();
         $fullCalendarItem['modelId'] = $calItem->getModelId();
         $fullCalendarItem['calendarId'] = $calItem->getCalendarId();
         $fullCalendarItem['allDay'] = true;
         $fullCalendarItems[] = $fullCalendarItem;
     }
     if (count($fullCalendarItems) > 0) {
         ArrayUtil::sortArrayByElementField('compareCalendarItemsByDateTime', 'usort', $fullCalendarItems, 'CalendarUtil');
     }
     return $fullCalendarItems;
 }