Пример #1
0
 /**
  * Adds a property path to the joins list
  *
  * @param $path  string full path to desired property, starting from starting class
  * @param $depth integer for internal use : please do not use this
  * @return Join the added join, or null if $path does not generate any join
  */
 public function add($path, $depth = 0)
 {
     if (isset($this->joins[$path]) || array_key_exists($path, $this->joins)) {
         return $this->joins[$path];
     }
     list($master_path, $master_property_name) = Sql\Builder::splitPropertyPath($path);
     if ($master_path && !isset($this->joins[$master_path])) {
         $this->add($master_path, $depth + 1);
     }
     if (isset($this->link_joins[$path])) {
         $property_type = $this->getProperties($master_path)[$master_property_name]->getType();
         if ($property_type->isClass()) {
             $linked_master_alias = $this->link_joins[$path]->foreign_alias;
         } else {
             return $this->link_joins[$path];
         }
     }
     $join = new Join();
     $foreign_class_name = strpos($master_property_name, '->') ? $this->addReverseJoin($join, $master_path, $master_property_name, $path) : $this->addSimpleJoin($join, $master_path, $master_property_name, $path);
     $this->joins[$path] = $join->mode ? $this->addFinalize($join, $master_path, $foreign_class_name, $path, $depth) : null;
     if (isset($linked_master_alias)) {
         $join->master_alias = $linked_master_alias;
     }
     return $this->joins[$path];
 }
Пример #2
0
 /**
  * @param $path string
  * @param $join Join
  * @param $as   boolean
  * @return string
  */
 public function buildColumn($path, $join = null, $as = true)
 {
     if (!isset($join)) {
         $join = $this->joins->add($path);
     }
     list($master_path, $column_name) = Sql\Builder::splitPropertyPath($path);
     if (!isset($join)) {
         $join = $this->joins->getJoin($master_path);
     }
     return ($join ? $join->foreign_alias . DOT . BQ . $column_name . BQ : 't0.' . BQ . $path . BQ) . ($as && $column_name !== $path && $this->resolve_aliases ? ' AS ' . BQ . $path . BQ : false);
 }
Пример #3
0
 /**
  * Build SQL WHERE section for given path and value
  *
  * @param $path        string|integer Property path starting by a root class property (may be a numeric key, or a structure keyword)
  * @param $value       mixed May be a value, or a structured array of multiple where clauses
  * @param $clause      string For multiple where clauses, tell if they are linked with 'OR' or 'AND'
  * @return string
  */
 private function buildPath($path, $value, $clause)
 {
     if ($value instanceof Func\Where) {
         $this->joins->add($path);
         list($master_path, $foreign_column) = Builder::splitPropertyPath($path);
         if ($foreign_column == 'id') {
             $prefix = '';
         } else {
             $properties = $this->joins->getProperties($master_path);
             $property = isset($properties[$foreign_column]) ? $properties[$foreign_column] : null;
             $id_links = [Link_Annotation::OBJECT, Link_Annotation::COLLECTION, Link_Annotation::MAP];
             $prefix = $property ? in_array($property->getAnnotation('link')->value, $id_links) ? 'id_' : '' : '';
         }
         return $value->toSql($this, $path, $prefix);
     } elseif ($value instanceof Date_Time) {
         // TODO a class annotation (@business? @string?) could help choose
         $value = $value->toISO(false);
     }
     switch (gettype($value)) {
         case 'NULL':
             return '';
         case 'array':
             return $this->buildArray($path, $value, $clause);
         case 'object':
             return $this->buildObject($path, $value);
         default:
             return $this->buildValue($path, $value);
     }
 }