public function testResolveNewTimeStampForDuration() { $timeTrigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', Workflow::TYPE_ON_SAVE); $timeTrigger->durationInterval = 5; $timeTrigger->durationType = TimeDurationUtil::DURATION_TYPE_DAY; $timeTrigger->durationSign = TimeDurationUtil::DURATION_SIGN_POSITIVE; $this->assertEquals(5 * 24 * 60 * 60, $timeTrigger->resolveNewTimeStampForDuration(0)); $timeTrigger->durationType = TimeDurationUtil::DURATION_TYPE_MINUTE; $this->assertEquals(5 * 60, $timeTrigger->resolveNewTimeStampForDuration(0)); $timeTrigger->durationInterval = 10; $this->assertEquals(10 * 60, $timeTrigger->resolveNewTimeStampForDuration(0)); $timeTrigger->durationType = TimeDurationUtil::DURATION_TYPE_HOUR; $this->assertEquals(10 * 60 * 60, $timeTrigger->resolveNewTimeStampForDuration(0)); $timeTrigger->durationSign = TimeDurationUtil::DURATION_SIGN_NEGATIVE; $this->assertEquals(-10 * 60 * 60, $timeTrigger->resolveNewTimeStampForDuration(0)); }
/** * @return string */ protected function renderTimeTriggerContentAndWrapper() { if ($this->model->timeTriggerAttribute != null) { $componentType = TimeTriggerForWorkflowForm::getType(); $inputPrefixData = array(get_class($this->model), $componentType); $adapter = new WorkflowAttributeToElementAdapter($inputPrefixData, $this->model->timeTrigger, $this->form, $componentType); $view = new AttributeRowForWorkflowComponentView($adapter, 1, $inputPrefixData, $this->model->timeTriggerAttribute, false, true, $componentType); $timeTriggerContent = ZurmoHtml::tag('div', array('class' => 'dynamic-rows'), ZurmoHtml::tag('ul', array(), $view->render())); $htmlOptions = array('id' => 'time-trigger-container'); } else { $timeTriggerContent = ZurmoHtml::tag('div', array('class' => 'dynamic-rows'), ZurmoHtml::tag('ul', array(), '')); $htmlOptions = array('id' => 'time-trigger-container', 'style' => 'display:none'); } return ZurmoHtml::tag('div', $htmlOptions, $timeTriggerContent); }
/** * No need to sanitize for Date and DateTime since those attributes utilize integers for time-based triggers * @param array $data * @param Workflow $workflow */ public static function resolveTimeTrigger($data, Workflow $workflow) { assert('is_array($data)'); if ($workflow->getType() != Workflow::TYPE_BY_TIME) { return; } $workflow->removeTimeTrigger(); $moduleClassName = $workflow->getModuleClassName(); $timeTrigger = new TimeTriggerForWorkflowForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $workflow->getType()); if (null != ($timeTriggerData = ArrayUtil::getArrayValue($data, ComponentForWorkflowForm::TYPE_TIME_TRIGGER))) { $timeTrigger->setAttributes($timeTriggerData); } $workflow->setTimeTrigger($timeTrigger); }
/** * @param TimeTriggerForWorkflowForm $timeTriggerForWorkflowForm * @return array */ protected static function makeArrayFromTimeTriggerForWorkflowFormAttributesData(TimeTriggerForWorkflowForm $timeTriggerForWorkflowForm) { $data = array(); foreach ($timeTriggerForWorkflowForm->getAttributes() as $attribute => $value) { if ($attribute != 'stringifiedModelForValue') { $data[$attribute] = $value; } } return $data; }
public function actionAddOrChangeTimeTriggerAttribute($type, $attributeIndexOrDerivedType, $moduleClassName, $id = null, $isBeingCopied = false) { $componentType = TimeTriggerForWorkflowForm::getType(); $postData = PostUtil::getData(); //Special situation since this is coming form GET $postData['ByTimeWorkflowWizardForm']['moduleClassName'] = $moduleClassName; $savedWorkflow = null; $workflow = null; $this->resolveSavedWorkflowAndWorkflowByPostData($postData, $savedWorkflow, $workflow, $type, $id, (bool) $isBeingCopied); $moduleClassName = $workflow->getModuleClassName(); $modelClassName = $moduleClassName::getPrimaryModelName(); $form = new WizardActiveForm(); $form->enableAjaxValidation = true; //ensures error validation populates correctly $form->id = WorkflowWizardView::getFormId(); $wizardFormClassName = WorkflowToWizardFormAdapter::getFormClassNameByType($workflow->getType()); $model = ComponentForWorkflowFormFactory::makeByComponentType($moduleClassName, $modelClassName, $workflow->getType(), $componentType); $form->modelClassNameForError = $wizardFormClassName; $model->attributeIndexOrDerivedType = $attributeIndexOrDerivedType; $inputPrefixData = array($wizardFormClassName, $componentType); $adapter = new WorkflowAttributeToElementAdapter($inputPrefixData, $model, $form, $componentType); $view = new AttributeRowForWorkflowComponentView($adapter, 1, $inputPrefixData, $attributeIndexOrDerivedType, false, true, $componentType); $content = $view->render(); $form->renderAddAttributeErrorSettingsScript($view::getFormId()); Yii::app()->getClientScript()->setToAjaxMode(); Yii::app()->getClientScript()->render($content); echo $content; }
/** * @param TimeTriggerForWorkflowForm $trigger * @param RedBeanModel $model * @return mixed * @throws NotSupportedException */ protected static function resolveModelValueByTimeTrigger(TimeTriggerForWorkflowForm $trigger, RedBeanModel $model) { if ($trigger->getAttribute() == null) { $attributeAndRelationData = $trigger->getAttributeAndRelationData(); if (count($attributeAndRelationData) == 2) { $penultimateRelation = $trigger->getResolvedRealAttributeNameForPenultimateRelation(); $resolvedAttribute = $trigger->getResolvedAttributeRealAttributeName(); if ($model->{$penultimateRelation} instanceof RedBeanMutableRelatedModels) { throw new NotSupportedException(); } else { $resolvedModel = $model->{$penultimateRelation}; return $resolvedModel->{$resolvedAttribute}; } } else { throw new NotSupportedException(); } } else { $attribute = $trigger->getResolvedAttributeRealAttributeName(); return $model->{$attribute}; } }