/** * @param array $inputPrefixData * @return array */ protected function resolveAttributeRowsForUpdateTypes(array $inputPrefixData) { assert('is_array($inputPrefixData)'); $attributeRows = array(self::REQUIRED_ATTRIBUTES_INDEX => array(), self::NON_REQUIRED_ATTRIBUTES_INDEX => array()); foreach ($this->model->resolveAllActionAttributeFormsAndLabelsAndSort() as $attribute => $actionAttributeForm) { $elementAdapter = new WorkflowActionAttributeToElementAdapter($actionAttributeForm, $this->form, $this->model->type, array_merge($inputPrefixData, array($attribute)), false); $attributeRows[self::NON_REQUIRED_ATTRIBUTES_INDEX][] = $elementAdapter->getContent(); } return $attributeRows; }
/** * @param ActionForWorkflowForm $action * @param RedBeanModel $model * @param User $triggeredByUser * @param RedBeanModel $triggeredModel * @param boolean $create */ protected static function processActionAttributesForActionBeforeSave(ActionForWorkflowForm $action, RedBeanModel $model, User $triggeredByUser, RedBeanModel $triggeredModel, $create = false) { assert('is_bool($create)'); $processedAttributes = array(); foreach ($action->getActionAttributes() as $attribute => $actionAttribute) { if ($actionAttribute->resolveValueBeforeSave() && $actionAttribute->shouldSetValue) { if (null === ($relation = ActionForWorkflowForm::resolveFirstRelationName($attribute))) { $resolvedModel = $model; $resolvedAttribute = ActionForWorkflowForm::resolveRealAttributeName($attribute); } else { $resolvedModel = $model->{$relation}; $resolvedAttribute = ActionForWorkflowForm::resolveRealAttributeName($attribute); } $adapter = new WorkflowActionProcessingModelAdapter($resolvedModel, $triggeredByUser, $triggeredModel); $actionAttribute->resolveValueAndSetToModel($adapter, $resolvedAttribute); $processedAttributes[] = $attribute; } } if ($create) { foreach ($action->resolveAllActionAttributeFormsAndLabelsAndSort() as $attribute => $actionAttribute) { if (!in_array($attribute, $processedAttributes) && $actionAttribute->resolveValueBeforeSave() && $actionAttribute->shouldSetNullAlternativeValue()) { if (null === ($relation = ActionForWorkflowForm::resolveFirstRelationName($attribute))) { $resolvedModel = $model; $resolvedAttribute = ActionForWorkflowForm::resolveRealAttributeName($attribute); $adapter = new WorkflowActionProcessingModelAdapter($resolvedModel, $triggeredByUser, $triggeredModel); $actionAttribute->resolveNullAlternativeValueAndSetToModel($adapter, $resolvedAttribute); } } } } }
/** * @depends testValidate */ public function testResolveAllActionAttributeFormsAndLabelsAndSort() { $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE); $form->type = ActionForWorkflowForm::TYPE_UPDATE_RELATED; $form->relation = 'hasMany2'; $data = $form->resolveAllActionAttributeFormsAndLabelsAndSort(); $this->assertEquals(41, count($data)); }