コード例 #1
0
ファイル: Entity.php プロジェクト: aeberh/php-movico
 public function addFinder(Finder $finder)
 {
     if (!empty($this->finders[$finder->getName()])) {
         throw new ServiceBuilderException("Duplicate finder name '{$finder->getName()}' for entity '{$this->name}'");
     }
     foreach ($finder->getColumns() as $finderColumn) {
         if (empty($this->properties[$finderColumn->getName()])) {
             //throw new ServiceBuilderException("Finder column '{$finderColumn->getName()}' is not a property for entity '$this->name'");
         }
     }
     $this->finders[$finder->getName()] = $finder;
 }
コード例 #2
0
 protected function parseFinder(Sql $sql, Finder $finder, $alias, &$aliases, &$conditions)
 {
     $entity = $finder->getName();
     $parent = $finder->getParentName();
     $next = $finder->getNextName();
     $parentAlias = $parent ? $aliases[$parent] : null;
     $aliases[$entity] = $alias;
     $parsedConditions = $this->parseConditions($conditions, $finder, $alias);
     if (!empty($parsedConditions)) {
         $conditions[] = $parsedConditions;
     }
     if (is_null($parentAlias)) {
         return $sql->from($entity);
     } elseif ($finder->isRequired()) {
         $sql->innerJoin($entity);
     } else {
         $sql->leftJoin($entity);
     }
     if ($alias !== $entity) {
         $sql->as($alias);
     }
     $aliasedPk = "{$alias}." . $this->findPrimaryKey($entity);
     $aliasedParentPk = "{$parentAlias}." . $this->findPrimaryKey($parent);
     if ($entity === "{$parent}_{$next}") {
         return $sql->on(array("{$alias}.{$parent}_id" => $aliasedParentPk));
     } else {
         return $sql->on(array("{$parentAlias}.{$entity}_id" => $aliasedPk));
     }
 }