/**
 * Sets up a query for a particular entry type.
 * @param QUERY $query
 * @param string $type
 * @access private
 */
function project_query_set_type($query, $type)
{
    $table_names = $query->app->table_names;
    switch ($type) {
        case 'change':
            $query->add_select('chng.*');
            $query->add_table($table_names->changes . ' chng', 'chng.entry_id = entry.id');
            break;
        case 'job':
            $query->add_select('job.*');
            $query->add_table($table_names->jobs . ' job', 'job.entry_id = entry.id');
            break;
        default:
            $query->add_select('chng.*, job.*');
            $query->add_table($table_names->changes . ' chng', 'chng.entry_id = entry.id', 'LEFT');
            $query->add_table($table_names->jobs . ' job', 'job.entry_id = entry.id', 'LEFT');
            break;
    }
    $query->order_by_recent();
}
 /**
  * Restrict the query to the time frame.
  * @param QUERY $query
  */
 public function prepare_query($query)
 {
     if (!$query) {
         $this->raise("'query' cannot be empty", 'prepare_query', 'TIME_FRAME_SELECTOR');
     }
     switch ($this->period) {
         case Time_frame_recent:
             $query->set_limits(0, $this->num_in_recent);
             break;
         case Time_frame_today:
             $first = new DATE_TIME(mktime(0, 0, 0, date('n'), date('d'), date('Y')));
             $last = new DATE_TIME(time());
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_last_week:
             $now = time();
             $last = new DATE_TIME($now);
             $first = new DATE_TIME($now - 86400 * 7);
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_last_month:
             $now = time();
             $last = new DATE_TIME($now);
             $first = new DATE_TIME($now - 86400 * 30);
             $query->set_days($first->as_iso(), $last->as_iso());
             break;
         case Time_frame_all:
             break;
     }
     if ($this->period != Time_frame_all) {
         $query->order_by_recent();
     }
 }