/**
 * Set the most recent ordering for a query.
 * @param QUERY $query
 * @param string $type
 * @access private
 */
function project_query_order_by_recent($query, $type)
{
    switch ($type) {
        case 'change':
            $query->set_order('chng.time_applied DESC, entry.time_created DESC');
            break;
        case 'job':
            $query->set_order('entry.state, (closer_id = 0) DESC, job.status ASC, job.priority DESC, job.time_closed DESC, entry.time_created DESC');
            break;
        default:
            $query->set_order('entry.type, entry.time_created DESC');
            break;
    }
}
 /**
  * @param APPLICATION $context Main application.
  */
 public function __construct($context)
 {
     parent::__construct($context);
     $this->_select = 'perm.*';
     $this->_order = 'kind DESC, importance DESC';
     $this->_tables = "{$context->table_names->folder_permissions} perm";
     $this->type = All;
 }
 /**
  * Prepare security- and filter-based restrictions.
  * @access private
  */
 protected function _prepare_restrictions()
 {
     $this->_returns_no_data = !isset($this->_entry) || !$this->_entry->exists();
     if (!$this->_returns_no_data) {
         parent::_prepare_restrictions();
         $this->_calculated_restrictions[] = "etob.entry_id = {$this->_entry->id}";
     }
 }
 /**
  * Modify the query to navigate.
  * @param QUERY $query
  * @access private
  */
 protected function _adjust_query($query)
 {
     $calendar = read_var('calendar');
     $first_day = read_var('first_day');
     $last_day = read_var('last_day');
     $folder = $this->_entry->parent_folder();
     if ($calendar) {
         $this->page->location->append("Calendar", "view_calendar.php?id={$folder->id}");
     }
     if ($first_day) {
         $day = $this->app->make_date_time($first_day, Date_time_iso);
         $url = new URL($this->env->url(Url_part_no_host_path));
         $url->replace_argument('id', $folder->id);
         $url->replace_name_and_extension('view_journals.php');
         $this->page->location->append($folder->format_date($day), $url->as_text());
         $query->set_days($first_day, $last_day);
     }
     $query->set_order('date ASC');
     parent::_adjust_query($query);
 }
/**
 * Sets up a query for a particular entry type.
 * @param QUERY $query
 * @param string $type
 * @access private
 */
function album_query_set_type($query, $type)
{
    /** @var ALBUM_APPLICATION_TABLE_NAMES $table_names */
    $table_names = $query->app->table_names;
    switch ($type) {
        case 'picture':
            $query->add_select('pic.*');
            $query->add_table($table_names->pictures . ' pic', 'pic.entry_id = entry.id');
            break;
        case 'journal':
            $query->add_select('jrnl.*');
            $query->add_table($table_names->journals . ' jrnl', 'jrnl.entry_id = entry.id');
            break;
        default:
            $query->add_select('jrnl.*, pic.*');
            $query->add_table($table_names->journals . ' jrnl', 'jrnl.entry_id = entry.id', 'LEFT');
            $query->add_table($table_names->pictures . ' pic', 'pic.entry_id = entry.id', 'LEFT');
            break;
    }
    $query->order_by_day('ASC');
}
Example #6
0
 /**
  * @return integer
  */
 public function num_objects()
 {
     return $this->query->size();
 }
 /**
  * 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();
     }
 }
Example #8
0
 /**
  * Return the requested object; might be cached.
  * @param integer $id
  * @return UNIQUE_OBJECT
  */
 public function object_at_id($id)
 {
     $this->assert(!empty($id), 'ID cannot be empty (in ' . strtoupper(get_class($this->query)) . ')', 'object_at_id', 'QUERY_BASED_CACHE');
     if (isset($this->_cache[$id])) {
         return $this->_cache[$id];
     }
     $Result = $this->query->object_at_id($id);
     $this->add_object($Result);
     return $Result;
 }
/**
 * Adds restrictions for finding only unscheduled jobs.
 * 
 * @param QUERY $query The query to adjust; cannot be null.
 * @access private
 */
function restrict_to_unscheduled($query)
{
    $query->restrict('entry.release_id = 0');
}
 /**
  * Apply the desired sorting for RSS.
  * Called from {@link prepare_query()}.
  * @param QUERY $query
  * @access private
  */
 protected function _prepare_sort($query)
 {
     $query->set_order('entry.time_created DESC');
 }
    /**
     * Draw a list with a title.
     * @param string $title
     * @param string $text
     * @param QUERY $query
     * @access private
     */
    protected function _draw_section($title, $text, $query)
    {
        /** @var PROJECT_ENTRY[] $objects */
        $objects = $query->objects();
        if (sizeof($objects)) {
            $this->_objects_displayed = true;
            ?>
  <h3><?php 
            echo sizeof($objects);
            ?>
 <?php 
            echo $title;
            ?>
</h3>
  <p>
    <?php 
            echo $text;
            ?>
  </p>
  <?php 
            $this->app->display_options->overridden_max_title_size = 100;
            echo '<ul class="minimal">';
            foreach ($objects as $entry) {
                $props = $entry->kind_properties();
                $text = $this->context->get_icon_with_text($props->icon, Sixteen_px, $entry->title_as_link());
                echo '<li>' . $text . '</li>';
            }
            echo '</ul>';
        }
    }
 /**
  * Modify the query to navigate.
  * Restrict the query selection to required fields.
  * The navigator needs only a few fields from an entry; use {@link QUERY::
  * set_select()} to reset the selection clause.
  * @param QUERY $query
  * @access private
  */
 protected function _adjust_query($query)
 {
     $query->set_select('entry.id, entry.title, entry.state');
 }
 /**
  * Restrict the query by these fields.
  * @param QUERY $query The query to which to apply parameters.
  * @param stdClass $obj The object from which to extract parameters.
  */
 public function apply_to_query($query, $obj)
 {
     $now = time();
     switch ($obj->parameters[$this->search_type_name()]) {
         case Search_date_today:
             $date_after = new DATE_TIME(mktime(0, 0, 0, date('n'), date('d'), date('Y')));
             $date_before = new DATE_TIME($now);
             break;
         case Search_date_this_week:
             $date_after = new DATE_TIME($now - 86400 * 7);
             $date_before = new DATE_TIME($now);
             break;
         case Search_date_this_month:
             $date_after = new DATE_TIME($now - 86400 * 30);
             $date_before = new DATE_TIME($now);
             break;
         case Search_date_constant:
             $date_before = $obj->parameters[$this->before_name()];
             $date_after = $obj->parameters[$this->after_name()];
             break;
     }
     if (isset($date_before) && isset($date_after)) {
         $query->restrict_date($this->full_name($query, $this->base_name), $date_after, $date_before);
     }
 }