コード例 #1
0
ファイル: DibiJoinHelper.php プロジェクト: clevis/orm
 /** @param DibiMapper */
 public function __construct(DibiMapper $mapper)
 {
     $this->mapper = $mapper;
     $model = $mapper->getModel();
     $repository = $mapper->getRepository();
     foreach ((array) $repository->getEntityClassName() as $entityName) {
         foreach (MetaData::getEntityRules($entityName, $model) as $name => $rule) {
             if ($rule['relationship'] === MetaData::OneToMany) {
                 $loader = $rule['relationshipParam'];
                 if ($r = $loader->getRepository() and $p = $loader->getParam()) {
                     $this->relationships[$name] = array($r, array('id', false), array($p, false));
                 }
             } else {
                 if ($rule['relationship'] === MetaData::ManyToMany) {
                     $loader = $rule['relationshipParam'];
                     if ($r = $loader->getRepository()) {
                         $manyToManyMapper = $loader->getMapper($repository);
                         if ($manyToManyMapper instanceof DibiManyToManyMapper) {
                             $this->relationships[$name] = array($r, array($manyToManyMapper->childParam, true), array('id', false), array($manyToManyMapper->table, array('id', false), array($manyToManyMapper->parentParam, true)));
                         }
                     }
                 } else {
                     if ($rule['relationship'] === MetaData::ManyToOne or $rule['relationship'] === MetaData::OneToOne) {
                         $this->relationships[$name] = array($rule['relationshipParam'], array(NULL, false), array('id', false));
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: OneToMany.php プロジェクト: clevis/orm
 /**
  * @return string|NULL null mean disable
  */
 protected function getOrderProperty()
 {
     // Default ordering by property order is deprecated and in future version will be removed.
     if ($this->defaltOrderPropertyBCValue === false) {
         foreach ($this->getMetaData()->getCanConnectWithEntities($this->getModel()) as $entityClass) {
             $meta = MetaData::getEntityRules($entityClass, $this->getModel());
             if (!isset($meta['order'])) {
                 $this->defaltOrderPropertyBCValue = NULL;
                 break;
             }
             $this->defaltOrderPropertyBCValue = 'order';
         }
     }
     return $this->defaltOrderPropertyBCValue;
 }
コード例 #3
0
ファイル: Repository.php プロジェクト: clevis/orm
 /**
  * Vrati cizy klice pro tuto entitu.
  * @param string
  * @return array paramName => repositoryName
  */
 private final function getFkForEntity($entityName)
 {
     static $fks = array();
     if (!isset($fks[$entityName])) {
         $fk = array();
         foreach (MetaData::getEntityRules($entityName, $this->model) as $name => $rule) {
             if ($rule['relationship'] !== MetaData::ManyToOne and $rule['relationship'] !== MetaData::OneToOne) {
                 continue;
             }
             $fk[$name] = $rule['relationshipParam'];
         }
         $fks[$entityName] = $fk;
     }
     return $fks[$entityName];
 }
コード例 #4
0
 /**
  * Vytazena z mapperu
  * @param IRepository
  * @param array
  */
 protected function onLoad(IRepository $repository, array $data)
 {
     parent::onLoad($repository, $data);
     $this->rules = MetaData::getEntityRules(get_class($this), $repository->getModel());
     $this->values = $data;
     $this->valid = [];
     $this->getValue('id');
     // throw error if any
 }
コード例 #5
0
 /**
  * @param IRepositoryContainer
  * @param string MetaData::ManyToOne|MetaData::OneToOne|MetaData::ManyToMany|MetaData::OneToMany
  * @param bool
  * @param callback (RelationshipMetaData $parent, RelationshipMetaData $child)
  */
 protected function checkIntegrity(IRepositoryContainer $model, $expectedType, $requiredChildParam, $callback = NULL)
 {
     $lowerEntityName = strtolower($this->parentEntityName);
     $classes = array_values((array) $model->getRepository($this->childRepository)->getEntityClassName());
     $this->canConnectWith = array_combine(array_map('strtolower', $classes), $classes);
     if (!$this->childParam) {
         return;
     }
     foreach ($this->canConnectWith as $lowerEn => $en) {
         $meta = MetaData::getEntityRules($en, $model, $this->childParam);
         $e = NULL;
         if (isset($meta[$this->childParam])) {
             $meta = $meta[$this->childParam];
             try {
                 if ($meta['relationship'] !== $expectedType) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neni asociace ktera by ukazovala zpet");
                 }
                 $loader = $meta['relationshipParam'];
                 if ($requiredChildParam and !$loader->childParam) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neni vyplnen param ktery by ukazoval zpet");
                 }
                 if (!isset($loader->canConnectWith[$lowerEntityName])) {
                     do {
                         foreach ($loader->canConnectWith as $canConnectWithEntity) {
                             if (is_subclass_of($canConnectWithEntity, $lowerEntityName)) {
                                 break 2;
                                 // goto canConnect;
                             }
                         }
                         throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neukazuje zpet; ukazuje na jiny repository ({$loader->repository})");
                     } while (false);
                     // canConnect:
                 }
                 if ($loader->childParam and $loader->childParam !== $this->parentParam) {
                     throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$en}::\${$this->childParam} neukazuje zpet; ukazuje na jiny parametr ({$loader->childParam})");
                 }
                 if ($callback) {
                     call_user_func($callback, $this, $loader);
                 }
                 continue;
             } catch (Exception $e) {
             }
         }
         unset($this->canConnectWith[$lowerEn]);
         if ($e) {
             throw $e;
         }
     }
     if (!$this->canConnectWith) {
         throw new RelationshipLoaderException("{$this->parentEntityName}::\${$this->parentParam} {{$this->type}} na druhe strane asociace {$this->repository}::\${$this->childParam} neni asociace ktera by ukazovala zpet");
     }
 }