registry = $bugsys; $this->page = $page; $this->process_incoming(); } // ################################################################### /** * Processes the incoming variables and then sets all the sort order * information appropriately * * @access private */ function process_incoming() { $this->sortkey = $this->registry->in['by']; if (!$this->fetch_by_text($this->registry->in['by'])) { $this->sortkey = (isset($this->registry->userinfo['defaultsortkey']) ? $this->registry->userinfo['defaultsortkey'] : $this->registry->options['defaultsortkey']); } $this->direction = $this->registry->in['as']; if (!in_array($this->direction, array('asc', 'desc'))) { $this->direction = (isset($this->registry->userinfo['defaultsortas']) ? $this->registry->userinfo['defaultsortas'] : $this->registry->options['defaultsortas']); } } // ################################################################### /** * Fetch a SQL query to gather bugs with the sort filters applied * * @access public * * @param string Additional WHERE clauses in an array * @param string A LIMIT clause * * @return string Compiled SQL query */ function fetch_sql_query($where = null, $limit = null) { // this WHERE clause is used for all the queries $basewhere = "bug.product IN (" . fetch_on_bits('canviewbugs') . ") AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . $this->registry->userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")" . (($this->registry->options['hidestatuses'] OR isset($this->registry->userinfo['hidestatuses'])) ? " AND bug.status NOT IN (" . ($this->registry->userinfo['hidestatuses'] != '' ? $this->registry->userinfo['hidestatuses'] : $this->registry->options['hidestatuses']) . ")" : ""); // remap the sort keys to be actual SQL fields $querykeys = array( 'id' => 'bugid', 'summary' => 'summary', 'reporter' => 'userid', 'lastpost' => (can_perform('canviewhidden') ? "lastposttime" : "hiddenlastposttime") ); switch ($this->sortkey) { case 'id': case 'summary': case 'reporter': case 'lastpost': $query = " SELECT * FROM " . TABLE_PREFIX . "bug AS bug WHERE $basewhere" . (is_array($where) ? " AND " . implode("\nAND ", $where) : "") . " ORDER BY " . $querykeys[ $this->sortkey ] . " " . strtoupper($this->direction) . ($this->sortkey != 'lastpost' ? ", " . $querykeys['lastpost'] . " " . strtoupper($this->direction) : "") . ($limit ? " LIMIT $limit" : ""); break; case 'product': case 'status': case 'resolution': case 'priority': case 'severity': $query = " SELECT * FROM " . TABLE_PREFIX . "{$this->sortkey} AS {$this->sortkey} RIGHT JOIN " . TABLE_PREFIX . "bug AS bug ON (bug.{$this->sortkey} = {$this->sortkey}.{$this->sortkey}id) WHERE $basewhere" . (is_array($where) ? " AND " . implode("\nAND ", $where) : "") . " ORDER BY {$this->sortkey}.displayorder " . strtoupper($this->direction) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction) . ($limit ? " LIMIT $limit" : ""); break; } return $query; } // ################################################################### /** * Returns the display text for a given sort order key * * @access public static * * @param string Sort order key, or FALSE for the array * * @return mixed Display text if param is string, or array of all key=>text if param is NULL */ function fetch_by_text($key) { global $lang; $keys = array( 'lastpost' => _('Last Post Time'), 'id' => _('Bug ID'), 'summary' => _('Summary'), 'reporter' => _('Reporter'), 'product' => _('Product'), 'status' => _('Status'), 'resolution' => _('Resolution'), 'priority' => _('Priority'), 'severity' => _('Severity') ); if ($key === false) { return $keys; } else { return $keys["$key"]; } } // ################################################################### /** * Returns the display text for a given sort order direction * * @access public static * * @param string Sort direction, or FALSE for the array * * @return mixed Display text if param is string, or array of all key=>text if param is NULL */ function fetch_as_text($key) { global $lang; $keys = array( 'desc' => _('Descending'), 'asc' => _('Ascending') ); if ($key === false) { return $keys; } else { return $keys["$key"]; } } // ################################################################### /** * Returns a multi-dimensional array with sort by keys indexing arrays * with 'image' and 'href' keys that store the values from * fetch_sort_image() and fetch_sort_link(), respectively * * @access public * * @param string Extra GET parameters to pass to fetch_sort_link() * * @return array Array as described above */ function fetch_display_array($params = null) { $return = $this->fetch_by_text(false); foreach ($return AS $key => $nil) { $return["$key"] = array('image' => ($this->sortkey == $key ? $this->fetch_sort_image() : ''), 'href' => $this->fetch_sort_link($key, $params, true)); } return $return; } // ################################################################### /** * Returns the entire tag for the sort arrow * * @access public * * @return string HTML tag */ function fetch_sort_image() { return ''; } // ################################################################### /** * Returns the href value for an tag by generating all the necessary * bits and concat'ing it onto an extra string of GETs (optional) * * @access public * * @param string Sorting key * @param string Additional GET parameters * @param bool Highlight the current sortkey if that's passed? * * @return string HREF */ function fetch_sort_link($key, $params = null, $highlight = false) { if ($params) { $params .= '&'; } return $this->page . '.php?' . $params . 'by=' . $key . '&as=' . (($this->sortkey == $key AND $highlight) ? $this->fetch_opposite_sort_direction() . '" class="select' : $this->fetch_sort_direction()); } // ################################################################### /** * Returns the OPPOSITE direction to sort when you click on a link * * @access public * * @return string Either asc or desc */ function fetch_opposite_sort_direction() { if ($this->direction == 'asc') { return 'desc'; } else { return 'asc'; } } // ################################################################### /** * Returns the current sorted direction for the image path * * @access public * * @return string Either asc or desc */ function fetch_sort_direction() { return $this->direction; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>