From 3788e6a895c16291d78e536ec414f3f1cb871415 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 15 Sep 2008 22:22:08 -0400 Subject: [PATCH] Update class_sort.php --- includes/class_sort.php | 337 +++++++++++++++++----------------------- index.php | 4 +- 2 files changed, 148 insertions(+), 193 deletions(-) diff --git a/includes/class_sort.php b/includes/class_sort.php index 9d53cf3..e260c8d 100644 --- a/includes/class_sort.php +++ b/includes/class_sort.php @@ -20,79 +20,68 @@ \*=====================================================================*/ /** -* Bug Listing Sorter -* -* This class is used to sort bugs based on user-sent options and variables. -* -* @author Blue Static -* @copyright Copyright ©2002 - 2007, Blue Static -* @version $Revision$ -* @package Bugdar -* -*/ + * Bug Listing Sorter + * + * This class is used to sort bugs based on user-sent options and variables. + * + * @author Blue Static + * @copyright Copyright ©2002 - 2007, Blue Static + * @version $Revision$ + * @package Bugdar + * + */ class ListSorter { /** - * Bugsys registry - * @var object - * @access private - */ - var $db; + * Bugsys registry + * @var object + */ + private $db; /** - * Page name - * @var string - * @access public - */ - var $page = ''; + * Page name + * @var string + */ + public $page = ''; /** - * Current sort key - * @var string - * @access private - */ - var $sortkey = ''; + * Current sort key + * @var string + */ + public $sortkey = ''; /** - * Current sort direction - * @var string - * @access private - */ - var $direction = ''; + * Current sort direction + * @var string + */ + private $direction = ''; /** - * Column array for table heads - * @var array - */ - var $columns; + * Column array for table heads + * @var array + */ + private $columns; - // ################################################################### /** - * Constructor: set the page name - * - * @access public - * - * @param string File name without the .php extension - */ - function ListSorter($page) + * Constructor: set the page name + * + * @param string File name without the .php extension + */ + public function __construct($page) { - global $bugsys; $this->db = BSApp::$db; $this->page = $page; - $this->process_incoming(); + $this->_processIncoming(); } - // ################################################################### /** - * Processes the incoming variables and then sets all the sort order - * information appropriately - * - * @access private - */ - function process_incoming() + * Processes the incoming variables and then sets all the sort order + * information appropriately + */ + private function _processIncoming() { $this->sortkey = BSApp::$input->in['by']; - if (!$this->fetch_by_text(BSApp::$input->in['by'])) + if (!self::fetch_by_text(BSApp::$input->in['by'])) { $this->sortkey = (isset(bugdar::$userinfo['defaultsortkey']) ? bugdar::$userinfo['defaultsortkey'] : bugdar::$options['defaultsortkey']); } @@ -104,23 +93,20 @@ class ListSorter } } - // ################################################################### /** - * 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) + * Fetch a SQL query to gather bugs with the sort filters applied + * + * @param string Additional WHERE clauses in an array + * @param string A LIMIT clause + * + * @return string Compiled SQL query + */ + public function fetchSqlQuery($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 = " . bugdar::$userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")" . - ((bugdar::$options['hidestatuses'] OR isset(bugdar::$userinfo['hidestatuses'])) ? " + ((bugdar::$options['hidestatuses'] || isset(bugdar::$userinfo['hidestatuses'])) ? " AND bug.status NOT IN (" . (bugdar::$userinfo['hidestatuses'] != '' ? bugdar::$userinfo['hidestatuses'] : bugdar::$options['hidestatuses']) . ")" : ""); // remap the sort keys to be actual SQL fields @@ -177,7 +163,7 @@ class ListSorter WHERE $basewhere" . (is_array($where) ? " AND " . implode("\nAND ", $where) : "") . " - ORDER BY vote.votefor " . strtoupper($this->direction) . ", vote.voteagainst " . strtoupper($this->fetch_opposite_sort_direction()) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction) . ($limit ? " + ORDER BY vote.votefor " . strtoupper($this->direction) . ", vote.voteagainst " . strtoupper($this->fetchOppositeSortDirection()) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction) . ($limit ? " LIMIT $limit" : ""); break; default: @@ -200,21 +186,16 @@ class ListSorter 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 - * @param bool Permission check the custom fields? - * - * @return mixed Display text if param is string, or array of all key=>text if param is NULL - */ - function fetch_by_text($key, $doPerm = true) + * Returns the display text for a given sort order key + * + * @param string Sort order key, or FALSE for the array + * @param bool Permission check the custom fields? + * + * @return mixed Display text if param is string, or array of all key=>text if param is NULL + */ + public static function fetch_by_text($key, $doPerm = true) { - global $bugsys; - $keys = array( 'lastpost' => T('Last Post Time'), 'bugid' => T('Bug ID'), @@ -231,7 +212,7 @@ class ListSorter 'assignedto' => T('Assigned To') ); - $fields = self::_fetchCustomFields($doPerm); + $fields = self::_fetch_custom_fields($doPerm); foreach ($fields AS $field) { $keys['custom' . $field['fieldid']] = $field['name']; @@ -247,20 +228,15 @@ class ListSorter } } - // ################################################################### /** - * 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) + * Returns the display text for a given sort order direction + * + * @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 + */ + public static function fetch_as_text($key) { - global $lang; - $keys = array( 'desc' => T('Descending'), 'asc' => T('Ascending') @@ -276,75 +252,63 @@ class ListSorter } } - // ################################################################### /** - * 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) + * Returns a multi-dimensional array with sort by keys indexing arrays + * with 'image' and 'href' keys that store the values from + * fetchSortImage() and fetchSortLink(), respectively + * + * @param string Extra GET parameters to pass to fetchSortLink() + * + * @return array Array as described above + */ + public function fetchDisplayArray($params = null) { - $return = $this->fetch_by_text(false); + $return = self::fetch_by_text(false); - foreach ($return AS $key => $nil) + 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["$key"] = array('image' => ($this->sortkey == $key ? $this->fetchSortImage() : ''), 'href' => $this->fetchSortLink($key, $params, true)); } return $return; } - // ################################################################### /** - * Returns the entire tag for the sort arrow - * - * @access public - * - * @return string HTML tag - */ - function fetch_sort_image() + * Returns the entire tag for the sort arrow + * + * @return string HTML tag + */ + public function fetchSortImage() { - return ''; + 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) + * Returns the href value for an tag by generating all the necessary + * bits and concat'ing it onto an extra string of GETs (optional) + * + * @param string Sorting key + * @param string Additional GET parameters + * @param bool Highlight the current sortkey if that's passed? + * + * @return string HREF + */ + public function fetchSortLink($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()); + return $this->page . '.php?' . $params . 'by=' . $key . '&as=' . (($this->sortkey == $key && $highlight) ? $this->fetchOppositeSortDirection() . '" class="select' : $this->fetchSortDirection()); } - // ################################################################### /** - * 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() + * Returns the OPPOSITE direction to sort when you click on a link + * + * @return string Either asc or desc + */ + public function fetchOppositeSortDirection() { if ($this->direction == 'asc') { @@ -356,43 +320,39 @@ class ListSorter } } - // ################################################################### /** - * Returns the current sorted direction for the image path - * - * @access public - * - * @return string Either asc or desc - */ - function fetch_sort_direction() + * Returns the current sorted direction for the image path + * + * @return string Either asc or desc + */ + public function fetchSortDirection() { return $this->direction; } - // ################################################################### /** - * Returns the HTML code for bug listing table column headers - * - * @param bool Include the sort links/image? - * @param string Additional GET params to pass to fetch_sort_link() - * - * @return string HTML code - */ - function constructColumnHeaders($sortable, $params = null) + * Returns the HTML code for bug listing table column headers + * + * @param bool Include the sort links/image? + * @param string Additional GET params to pass to fetchSortLink() + * + * @return string HTML code + */ + public function constructColumnHeaders($sortable, $params = null) { $this->_processColumns(); $names = self::fetch_by_text(false); $output = ''; - foreach ($this->columns AS $columns) + foreach ($this->columns as $columns) { $build = array(); - foreach ($columns AS $column) + foreach ($columns as $column) { - $build[] = ($sortable ? '' . $names[$column] . '' : $names[$column]); + $build[] = ($sortable ? '' . $names[$column] . '' : $names[$column]); } - $image = ((in_array($this->sortkey, $columns) AND $sortable) ? $this->fetch_sort_image() : ''); + $image = ((in_array($this->sortkey, $columns) && $sortable) ? $this->fetchSortImage() : ''); $name = implode(' / ', $build); $tpl = new BSTemplate('list_head'); @@ -406,27 +366,26 @@ class ListSorter return $output; } - // ################################################################### /** - * Returns the HTML code for a row of data for the bug listing - * - * @param array Bug data array - * @param string Additional link params - * - * @return string Row HTML - */ + * Returns the HTML code for a row of data for the bug listing + * + * @param array Bug data array + * @param string Additional link params + * + * @return string Row HTML + */ function constructRow($bug, $params = null) { global $bugsys; $this->_processColumns(); - foreach ($this->columns AS $columns) + foreach ($this->columns as $columns) { if (sizeof($columns) > 1) { $build = array(); - foreach ($columns AS $column) + foreach ($columns as $column) { $build[] = $this->_processDataForColumn($bug, $column, $params, true); } @@ -447,18 +406,17 @@ class ListSorter return $tpl->evaluate()->getTemplate(); } - // ################################################################### /** - * Handler for special-case column data - * - * @param array Bug data - * @param string Column name - * @param string Additional URL params - * @param bool Will this column have multiple data sets? - * - * @return string Processed column data - */ - function _processDataForColumn($bug, $column, $params = null, $multi = false) + * Handler for special-case column data + * + * @param array Bug data + * @param string Column name + * @param string Additional URL params + * @param bool Will this column have multiple data sets? + * + * @return string Processed column data + */ + private function _processDataForColumn($bug, $column, $params = null, $multi = false) { $open = ($multi ? '
' : ''); $close = ($multi ? '
' : ''); @@ -477,12 +435,11 @@ class ListSorter } } - // ################################################################### /** - * Sets up $this->columns so that the data can be processed more - * easily - */ - function _processColumns() + * Sets up $this->columns so that the data can be processed more + * easily + */ + private function _processColumns() { if (is_array($this->columns)) { @@ -491,9 +448,9 @@ class ListSorter $columns = self::fetch_by_text(false); - $array = ((bugdar::$userinfo['userid'] AND is_array(bugdar::$userinfo['columnoptions'])) ? bugdar::$userinfo['columnoptions'] : bugdar::$options['columnoptions']); + $array = ((bugdar::$userinfo['userid'] && is_array(bugdar::$userinfo['columnoptions'])) ? bugdar::$userinfo['columnoptions'] : bugdar::$options['columnoptions']); - foreach ($array AS $column => $position) + foreach ($array as $column => $position) { // the column doesn't exist, or more likely, we don't have permission to view it if (!isset($columns[$column])) @@ -509,7 +466,6 @@ class ListSorter ksort($this->columns); } - // ################################################################### /** * Returns an array of all the custom fields that the current user * has permission to use @@ -518,16 +474,15 @@ class ListSorter * * @return array */ - private static function _fetchCustomFields($doPerm = true) + private static function _fetch_custom_fields($doPerm = true) { - global $bugsys; static $fields = array(), $fieldsPerm = array(); - if ($doPerm AND !empty($fieldsPerm)) + if ($doPerm && !empty($fieldsPerm)) { return $fieldsPerm; } - else if (!$doPerm AND !empty($fields)) + else if (!$doPerm && !empty($fields)) { return $fields; } diff --git a/index.php b/index.php index eea2ec8..6621d31 100644 --- a/index.php +++ b/index.php @@ -63,7 +63,7 @@ if (!$count['count']) $pagination->setTotal($count['count']); $pagination->splitPages(); -$bugs_fetch = $db->query($sort->fetch_sql_query(null, $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage())); +$bugs_fetch = $db->query($sort->fetchSqlQuery(null, $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage())); foreach ($bugs_fetch as $bug) { @@ -81,7 +81,7 @@ $tpl = new BSTemplate('trackerhome'); $tpl->vars = array( 'columnHeads' => $columnHeads, 'bugs' => $bugs, - 'pagenav' => $pagination->constructPageNav($sort->fetch_sort_link($sort->sortkey)) + 'pagenav' => $pagination->constructPageNav($sort->fetchSortLink($sort->sortkey)) ); $tpl->evaluate()->flush(); -- 2.22.5