Update class_sort.php
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 16 Sep 2008 02:22:08 +0000 (22:22 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 16 Sep 2008 02:22:08 +0000 (22:22 -0400)
includes/class_sort.php
index.php

index 9d53cf3dda0e8618ab0834cd1a64396c62a06e6c..e260c8dcc1c75b52057b142d22d415400197d9ff 100644 (file)
 \*=====================================================================*/
 
 /**
-* 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 <img> tag for the sort arrow
-       *
-       * @access       public
-       *
-       * @return       string  HTML <img> tag
-       */
-       function fetch_sort_image()
+        * Returns the entire <img> tag for the sort arrow
+        *
+        * @return      string  HTML <img> tag
+        */
+       public function fetchSortImage()
        {
-               return '<img src="templates/images/arrow_' . $this->fetch_sort_direction() . '.gif" alt="" style="vertical-align: top; border: none" />';
+               return '<img src="templates/images/arrow_' . $this->fetchSortDirection() . '.gif" alt="" style="vertical-align: top; border: none" />';
        }
        
-       // ###################################################################
        /**
-       * Returns the href value for an <a> 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 <a> 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 .= '&amp;';
                }
                
-               return $this->page . '.php?' . $params . 'by=' . $key . '&amp;as=' . (($this->sortkey == $key AND $highlight) ? $this->fetch_opposite_sort_direction() . '" class="select' : $this->fetch_sort_direction());
+               return $this->page . '.php?' . $params . 'by=' . $key . '&amp;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 ? '<a href="' . $this->fetch_sort_link($column, $params, true) . '">' . $names[$column] . '</a>' : $names[$column]);
+                               $build[] = ($sortable ? '<a href="' . $this->fetchSortLink($column, $params, true) . '">' . $names[$column] . '</a>' : $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 ? '<div>' : '');
                $close = ($multi ? '</div>' : '');
@@ -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;
                }
index eea2ec849afa1da2e8cba89ea2036f804e43f9ec..6621d3133ecd066cecd79f2ce6e2323d9a6599ee 100644 (file)
--- 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();