/**
  * @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 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);
 }
Пример #3
0
 protected static function resolveReadOnlyAndSetValueToAttribute(RedBeanModel $model, $attributeName, $value)
 {
     assert('is_string($attributeName)');
     if (!$model->isAttributeReadOnly($attributeName) || $model->isAttributeReadOnly($attributeName) && $model->isAllowedToSetReadOnlyAttribute($attributeName)) {
         $model->{$attributeName} = $value;
     }
 }