コード例 #1
0
 /**
  *
  * 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;
 }
 /**
  * Copy the account from a related model to a activity items
  * @param RedBeanModel $model
  * @param RedBeanModel $relatedModel
  */
 protected function addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
 {
     $metadata = Activity::getMetadata();
     if ($relatedModel->isRelation('account') && isset($relatedModel->account) && $relatedModel->account->id > 0 && in_array(get_class($relatedModel->account), $metadata['Activity']['activityItemsModelClassNames'])) {
         $model->activityItems->add($relatedModel->account);
     }
 }
 /**
  * @return array
  */
 protected function getDynamicallyDerivedAttributesData()
 {
     if (isset(self::$dynamicallyDerivedAttributesData[get_class($this->model)])) {
         return self::$dynamicallyDerivedAttributesData[get_class($this->model)];
     }
     $attributes = array();
     foreach ($this->model->getAttributes() as $attribute => $notUsed) {
         if (!$this->model instanceof User && $this->model->isRelation($attribute) && $this->model->getRelationModelClassName($attribute) == 'User') {
             $attributes[$attribute . FormModelUtil::DELIMITER . self::DYNAMIC_ATTRIBUTE_USER] = array('label' => $this->model->getAttributeLabel($attribute));
         }
     }
     self::$dynamicallyDerivedAttributesData[get_class($this->model)] = $attributes;
     return self::$dynamicallyDerivedAttributesData[get_class($this->model)];
 }
コード例 #5
0
 /**
  * Copy attributes from one model to another. If the attributes are relations, then only copy when it is a
  * HAS_ONE variant.  In the case that the relation is an OwnedModel, take special consideration for CurrencyValue
  * CustomField, and MultipleValuesCustomField models. If it is owned and not one of those 3, then it should just
  * copy the OwnedModel nonRelation attributes. An example of that would be Address or Email
  * @param RedBeanModel $model
  * @param RedBeanModel $copyToModel - model to copy attribute values from $model to
  */
 public static function copy(RedBeanModel $model, RedBeanModel $copyToModel)
 {
     $copyToModel->setIsCopied();
     foreach ($model->attributeNames() as $attributeName) {
         if ($attributeName == 'owner') {
             continue;
         }
         $isReadOnly = $model->isAttributeReadOnly($attributeName);
         if (!$model->isRelation($attributeName) && !$isReadOnly) {
             static::copyNonRelation($model, $attributeName, $copyToModel);
         } elseif ($model->isRelation($attributeName) && !$isReadOnly && $model->isRelationTypeAHasOneVariant($attributeName)) {
             static::copyRelation($model, $attributeName, $copyToModel);
         }
     }
     if ($model instanceof OwnedSecurableItem) {
         static::copyRelation($model, 'owner', $copyToModel);
     }
     static::resolveExplicitPermissions($model, $copyToModel);
 }
コード例 #6
0
 /**
  * @see https://www.pivotaltracker.com/story/show/58372836
  * This method is called to resolve the issue of the cache having incorrect information and requiring a clearCache
  * Now after saving, it will resolve the related model correctly.
  * @param RedBeanModel $precedingModel
  * @param string $precedingRelation
  * @param RedBeanModel $model
  */
 protected function resolveOneToManyPostCreateActionSaveModelCache(RedBeanModel $precedingModel, $precedingRelation, RedBeanModel $model)
 {
     if ($precedingModel->{$precedingRelation} instanceof RedBeanOneToManyRelatedModels) {
         $relationToUse = null;
         foreach ($model->getAttributes() as $attributeName => $notUsed) {
             if ($model->isRelation($attributeName)) {
                 if (RedBeanModel::relationLinksToPrecedingRelation(get_class($model), $attributeName, get_class($precedingModel), $precedingRelation)) {
                     $relationToUse = $attributeName;
                     break;
                 }
             }
         }
         if ($relationToUse != null) {
             $model->{$relationToUse} = $precedingModel;
         }
     }
 }
コード例 #7
0
 public static function getHasManyOpposingRelationName(RedBeanModel $model, $precedingModelClassName, $precedingRelation)
 {
     assert('is_string($precedingModelClassName)');
     assert('is_string($precedingRelation)');
     foreach ($model->attributeNames() as $attributeName) {
         if ($model->isRelation($attributeName) && ($model->getRelationType($attributeName) == RedBeanModel::HAS_ONE || $model->getRelationType($attributeName) == RedBeanModel::HAS_MANY_BELONGS_TO) && static::relationLinksToPrecedingRelation(get_class($model), $attributeName, $precedingModelClassName, $precedingRelation)) {
             return $attributeName;
         }
     }
 }
 /**
  * Copy the account from a related model to a Note activity items
  * ToDo: This shouldn't be in a view, but as we already add some activity items in this view, it is fine for now
  * ToDo: but we should think about refactoring it
  * @param RedBeanModel $model
  * @param RedBeanModel $relatedModel
  */
 protected function addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
 {
     if ($relatedModel->isRelation('account') && isset($relatedModel->account) && $relatedModel->account->id > 0) {
         $model->activityItems->add($relatedModel->account);
     }
 }