/** * Build SQL condition for a given time range * * @access protected * @param string $start_time Start timestamp * @param string $end_time End timestamp * @param string $start_column Start column name * @param string $end_column End column name * @return string */ protected function getCalendarCondition($start_time, $end_time, $start_column, $end_column) { $start_column = $this->db->escapeIdentifier($start_column); $end_column = $this->db->escapeIdentifier($end_column); $conditions = array("({$start_column} >= '{$start_time}' AND {$start_column} <= '{$end_time}')", "({$start_column} <= '{$start_time}' AND {$end_column} >= '{$start_time}')", "({$start_column} <= '{$start_time}' AND ({$end_column} = '0' OR {$end_column} IS NULL))"); return $start_column . ' IS NOT NULL AND ' . $start_column . ' > 0 AND (' . implode(' OR ', $conditions) . ')'; }
/** * Build a select query * * @access public * @return string */ public function buildSelectQuery() { if (empty($this->sqlSelect)) { $this->columns = $this->db->escapeIdentifierList($this->columns); $this->sqlSelect = ($this->distinct ? 'DISTINCT ' : '') . (empty($this->columns) ? '*' : implode(', ', $this->columns)); } $this->groupBy = $this->db->escapeIdentifierList($this->groupBy); return trim(sprintf('SELECT %s FROM %s %s %s %s %s %s %s', $this->sqlSelect, $this->db->escapeIdentifier($this->name), implode(' ', $this->joins), $this->condition->build(), empty($this->groupBy) ? '' : 'GROUP BY ' . implode(', ', $this->groupBy), $this->sqlOrder, $this->sqlLimit, $this->sqlOffset)); }
/** * IS NOT NULL condition * * @access public * @param string $column */ public function notNull($column) { $this->addCondition($this->db->escapeIdentifier($column) . ' IS NOT NULL'); }