Beispiel #1
0
 /**
  * Builds optionnal SQL expressions, component of the SELECT query
  *
  * @return string[]
  */
 private function buildOptions()
 {
     $options = [];
     foreach ($this->options as $option) {
         if ($option instanceof Option\Group_By) {
             $columns = new Columns($this->class_name, $option->properties, $this->joins);
             $columns->expand_objects = false;
             $columns->resolve_aliases = false;
             $group_by = $columns->build();
             $options[10] = LF . 'GROUP BY ' . $group_by;
         } elseif ($option instanceof Option\Sort) {
             $columns = new Columns($this->class_name, $option->getColumns($this->class_name), $this->joins, ['DESC' => $option->reverse]);
             $columns->replaceProperties($this->columns_builder);
             $columns->expand_objects = false;
             $columns->resolve_aliases = false;
             $order_by = $columns->build();
             if ($order_by) {
                 $options[20] = LF . 'ORDER BY ' . $order_by;
             }
         } elseif ($option instanceof Option\Limit) {
             // todo this works only with Mysql so beware, this should be into Mysql or something
             $options[30] = LF . 'LIMIT ' . (isset($option->from) ? $option->from - 1 . ', ' : '') . $option->count;
         } elseif ($option instanceof Option\Count) {
             $this->additional_where_clause = ' SQL_CALC_FOUND_ROWS';
         }
     }
     ksort($options);
     return $options;
 }