예제 #1
0
파일: Select.php 프로젝트: Konro1/pms
 public function compile($db = NULL)
 {
     if ($db === NULL and $this->meta()) {
         $db = Database::instance($this->meta()->db());
     }
     $original_select = $this->_select;
     $original_from = $this->_from;
     if (empty($this->_from)) {
         $this->_from[] = $this->meta()->model();
     }
     if (empty($this->_select)) {
         $this->_select[] = $this->meta()->table() . '.*';
     }
     foreach ($this->_from as &$from) {
         $from = Jam_Query_Builder::resolve_table_alias($from);
     }
     foreach ($this->_select as &$attribute) {
         $attribute = Jam_Query_Builder::resolve_attribute_name($attribute, $this->meta()->model());
     }
     $this->meta()->events()->trigger('builder.before_select', $this);
     $result = parent::compile($db);
     $this->meta()->events()->trigger('builder.after_select', $this);
     $this->_select = $original_select;
     $this->_from = $original_from;
     return $result;
 }
예제 #2
0
파일: Join.php 프로젝트: Konro1/pms
 public function compile($db = NULL)
 {
     if ($this->context_model() and $meta = Jam::meta(Jam_Query_Builder::aliased_model($this->context_model()))) {
         $db = Database::instance($meta->db());
     }
     $original_on = $this->_on;
     $original_using = $this->_using;
     $original_table = $this->_table;
     if (!empty($this->_on)) {
         foreach ($this->_on as &$condition) {
             $condition[0] = Jam_Query_Builder::resolve_attribute_name($condition[0], $this->model() ? $this->model() : $this->_table);
             $condition[2] = Jam_Query_Builder::resolve_attribute_name($condition[2], $this->context_model());
         }
     }
     $this->_table = Jam_Query_Builder::resolve_table_alias($this->_table);
     if (!empty($this->_using)) {
         foreach ($this->_using as &$column) {
             $column = Jam_Query_Builder::resolve_attribute_name($column, $this->meta());
         }
     }
     $additional_joins = '';
     foreach ($this->_joins as $join) {
         $additional_joins .= ' ' . $join->compile($db);
     }
     $compiled = parent::compile($db) . $additional_joins;
     $this->_on = $original_on;
     $this->_using = $original_using;
     $this->_table = $original_table;
     return $compiled;
 }