/**
  * @param RedBeanModel $precedingModel
  * @param null|string $precedingRelation
  * @param null|string $onlyIncludeThisModelClassName
  * @return array
  * @throws NotSupportedException if there the preceding model and relation are not either both defined or both
  * null
  */
 protected function getDerivedRelationsViaCastedUpModelData(RedBeanModel $precedingModel = null, $precedingRelation = null, $onlyIncludeThisModelClassName = null)
 {
     assert('$onlyIncludeThisModelClassName  === null || is_string($onlyIncludeThisModelClassName)');
     if ($precedingModel != null && $precedingRelation == null || $precedingModel == null && $precedingRelation != null) {
         throw new NotSupportedException();
     }
     $attributes = array();
     $metadata = $this->model->getMetadata();
     foreach ($metadata as $modelClassName => $modelClassMetadata) {
         if (isset($metadata[$modelClassName]["derivedRelationsViaCastedUpModel"])) {
             foreach ($metadata[$modelClassName]["derivedRelationsViaCastedUpModel"] as $relation => $derivedRelationData) {
                 $relationModelClassName = $this->model->getDerivedRelationModelClassName($relation);
                 if ($onlyIncludeThisModelClassName === null || $relationModelClassName == $onlyIncludeThisModelClassName) {
                     if (!$this->derivedRelationLinksToPrecedingRelation($relationModelClassName, $this->model->getDerivedRelationViaCastedUpModelOpposingRelationName($relation), $precedingModel, $precedingRelation)) {
                         $attributes[$relation] = array('label' => $this->model->getAttributeLabel($relation));
                     }
                 }
             }
         }
     }
     return $attributes;
 }
Пример #2
0
 /**
  * @param RedBeanModel $model
  * @param string $relation
  * @return Array of models
  */
 public static function resolveDerivedModels(RedBeanModel $model, $relation)
 {
     assert('is_string($relation)');
     $modelClassName = $model->getDerivedRelationModelClassName($relation);
     $inferredRelationName = $model->getDerivedRelationViaCastedUpModelOpposingRelationName($relation);
     return WorkflowUtil::getModelsFilteredByInferredModel($modelClassName, $inferredRelationName, (int) $model->getClassId('Item'));
 }