/** * * @param Database_Query_Builder_Select $query */ public function apply_ordering(&$query) { $this->orderby = Arr::get($_GET, 'orderby', ''); $this->orderdir = Arr::get($_GET, 'orderdir') == 'desc' ? 'desc' : 'asc'; if (!in_array($this->orderby, array_keys($this->get_columns()))) { $this->orderby = $this->get_title_column()->get_name(); } if ($this->get_column($this->orderby)->is_foreign_key()) { $fk1_alias = 'o1'; $fk1_table = $this->get_column($this->orderby)->get_referenced_table(); $query->join(array($fk1_table->get_name(), $fk1_alias), 'LEFT OUTER'); $query->on($this->get_name() . '.' . $this->orderby, '=', "{$fk1_alias}.id"); $orderby = $fk1_alias . '.' . $fk1_table->get_title_column()->get_name(); if ($fk1_table->get_title_column()->is_foreign_key()) { $fk2_alias = 'o2'; $fk2_table = $fk1_table->get_title_column()->get_referenced_table(); $query->join(array($fk2_table->get_name(), $fk2_alias), 'LEFT OUTER'); $query->on($fk1_alias . '.' . $fk1_table->get_title_column()->get_name(), '=', "{$fk2_alias}.id"); $orderby = $fk2_alias . '.' . $fk2_table->get_title_column()->get_name(); } $query->order_by($orderby, $this->orderdir); } else { $query->order_by($this->get_name() . '.' . $this->orderby, $this->orderdir); } }
public function on($c1, $op, $c2) { if (!$this->_last_join) { throw new Kohana_Exception('You must specifiy a JOIN first!'); } return parent::on($c1, $op, $c2); }
/** * Adds "ON ..." conditions for the last created JOIN statement. * * @param mixed $c1 column name or array($column, $alias) or object * @param string $op logic operator * @param mixed $c2 column name or array($column, $alias) or object * @return Jelly_Builder */ public function on($c1, $op, $c2) { return parent::on($this->_field_alias($c1), $op, $this->_field_alias($c2)); }