mapper = $mapper; $this->from($mapper->getTableName(), $mapper->getColumnNames()); } public function from($table, $columns = null) { $this->table = (string)$table; $this->columns = (array)$columns; return $this; } public function where($condition, $values = null, $conditionName = null) { $condition = (string)$condition; if ($values !== null) $condition = $this->db->quoteInto($condition, $values); if ($conditionName !== null && !is_numeric($conditionName)) $this->where[$conditionName] = $condition; else $this->where[] = $condition; return $this; } public function combineWhere($conditionName1, $conditionName2, $combineType = self::COMBINE_TYPE_AND, $conditionName = null) { $condition1 = isset($this->where[$conditionName1]) ? $this->where[$conditionName1] : null; $condition2 = isset($this->where[$conditionName2]) ? $this->where[$conditionName2] : null; if ($condition1 !== null && $condition2 !== null) { unset($this->where[$conditionName1], $this->where[$conditionName2]); $this->where($condition1 . ' ' . $combineType . ' ' . $condition2, null, $conditionName); } return $this; } public function resetWhere() { $this->where = array(); return $this; } public function order($column) { $this->order[] = (string)$column; return $this; } public function resetOrder() { $this->order = array(); return $this; } public function limit($limit, $offset = null) { $this->limit = ($limit === null) ? null : (int)$limit; $this->offset = ($offset === null) ? null : (int)$offset; return $this; } public function with($relationName) { $this->join(self::JOIN_TYPE_INNER, $tableName, $on, $columns); return $this; } }