Пример #1
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);
     }
 }
Пример #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);
 }