/** * * Get model properties as array. * return array */ public function getData() { $data = array(); $data['id'] = $this->model->id; $retrievableAttributes = static::resolveRetrievableAttributesByModel($this->model); foreach ($this->model->getAttributes($retrievableAttributes) as $attributeName => $notUsed) { $type = ModelAttributeToMixedArrayTypeUtil::getType($this->model, $attributeName); $adapterClassName = $type . 'RedBeanModelAttributeValueToArrayValueAdapter'; if ($type != null && @class_exists($adapterClassName) && !($this->model->isRelation($attributeName) && $this->model->getRelationType($attributeName) != RedBeanModel::HAS_ONE)) { $adapter = new $adapterClassName($this->model, $attributeName); $adapter->resolveData($data); } elseif ($this->model->isOwnedRelation($attributeName) && ($this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE || $this->model->getRelationType($attributeName) == RedBeanModel::HAS_MANY_BELONGS_TO)) { if ($this->model->{$attributeName}->id > 0) { $util = new ModelToArrayAdapter($this->model->{$attributeName}); $relatedData = $util->getData(); $data[$attributeName] = $relatedData; } else { $data[$attributeName] = null; } } elseif ($this->model->isRelation($attributeName) && $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE) { if ($this->model->{$attributeName}->id > 0) { $data[$attributeName] = array('id' => $this->model->{$attributeName}->id); } else { $data[$attributeName] = null; } } } return $data; }
/** * @param boolean $includeRequired * @param boolean $includeNonRequired * @param $includeReadOnly * @return array */ protected function resolveDynamicallyDerivedAttributesForActionsOrTimeTriggerData($includeRequired = false, $includeNonRequired = false, $includeReadOnly = false) { assert('is_bool($includeRequired)'); assert('is_bool($includeNonRequired)'); assert('is_bool($includeReadOnly)'); $attributes = array(); foreach ($this->model->getAttributes() as $attribute => $notUsed) { if (!$this->model instanceof User && $this->model->isRelation($attribute) && (!$this->model->isAttributeReadOnly($attribute) || $includeReadOnly) && $this->model->getRelationModelClassName($attribute) == 'User') { $attributeIsRequired = $this->model->isAttributeRequired($attribute); if ($includeNonRequired && !$attributeIsRequired || $includeRequired && $attributeIsRequired) { $attributes[$attribute . FormModelUtil::DELIMITER . self::DYNAMIC_ATTRIBUTE_USER] = array('label' => $this->model->getAttributeLabel($attribute)); } } if ($this->model->isRelation($attribute) && $this->model->isOwnedRelation($attribute) && $this->isRelationASingularRelation($attribute) && ($this->model->getRelationModelClassName($attribute) == 'Address' || $this->model->getRelationModelClassName($attribute) == 'Email')) { $relatedModel = $this->model->{$attribute}; //Assumes only Email or Address are possible owned models here $zurmoRules = WorkflowRules::makeByModuleClassName('ZurmoModule'); foreach ($relatedModel->getAttributes() as $relatedAttribute => $notUsed) { if (!$relatedModel->isAttributeReadOnly($relatedAttribute) && !$relatedModel->isRelation($relatedAttribute) && $zurmoRules->attributeCanBeTriggered($relatedModel, $relatedAttribute)) { $relatedAttributeIsRequired = $relatedModel->isAttributeRequired($relatedAttribute); if ($includeNonRequired && !$relatedAttributeIsRequired || $includeRequired && $relatedAttributeIsRequired) { $attributes[$attribute . FormModelUtil::RELATION_DELIMITER . $relatedAttribute] = array('label' => $this->model->getAttributeLabel($attribute) . ' ' . ComponentForWorkflowForm::DISPLAY_LABEL_RELATION_DIVIDER . ' ' . $relatedModel->getAttributeLabel($relatedAttribute)); } } } } } return $attributes; }
/** * Assumes for now that we only need to know about real attributes that are 'owned'. * @param $relation * @return bool * @throws NotSupportedException */ public function isOwnedRelation($relation) { assert('is_string($relation)'); $delimiter = FormModelUtil::DELIMITER; $relationAndInferredData = explode($delimiter, $relation); $derivedRelations = $this->getDerivedRelationsViaCastedUpModelData(); if (count($relationAndInferredData) == 3) { return false; } elseif (count($relationAndInferredData) == 2) { return false; } elseif (count($relationAndInferredData) == 1 && isset($derivedRelations[$relation])) { return false; } elseif (count($relationAndInferredData) == 1) { return $this->model->isOwnedRelation($relation); } else { throw new NotSupportedException(); } }