]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_sort.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
25 * This class is used to sort bugs based on user-sent options and variables.
28 * @copyright Copyright ©2002 - [#]year[#], Blue Static
57 * Current sort direction
63 // ###################################################################
65 * Constructor: set the page name
69 * @param string File name without the .php extension
71 function ListSorter ( $page )
74 $this- > registry
= $bugsys ;
76 $this- > process_incoming ();
79 // ###################################################################
81 * Processes the incoming variables and then sets all the sort order
82 * information appropriately
86 function process_incoming ()
88 $this- > sortkey
= $this- > registry
-> in
[ 'by' ];
89 if (! $this- > fetch_by_text ( $this- > registry
-> in
[ 'by' ]))
91 $this- > sortkey
= ( isset ( $this- > registry
-> userinfo
[ 'defaultsortkey' ]) ? $this- > registry
-> userinfo
[ 'defaultsortkey' ] : $this- > registry
-> options
[ 'defaultsortkey' ]);
94 $this- > direction
= $this- > registry
-> in
[ 'as' ];
95 if (! in_array ( $this- > direction
, array ( 'asc' , 'desc' )))
97 $this- > direction
= ( isset ( $this- > registry
-> userinfo
[ 'defaultsortas' ]) ? $this- > registry
-> userinfo
[ 'defaultsortas' ] : $this- > registry
-> options
[ 'defaultsortas' ]);
101 // ###################################################################
103 * Fetch a SQL query to gather bugs with the sort filters applied
107 * @param string Additional WHERE clauses in an array
108 * @param string A LIMIT clause
110 * @return string Compiled SQL query
112 function fetch_sql_query ( $where = null , $limit = null )
114 // this WHERE clause is used for all the queries
115 $basewhere = "bug.product IN (" . fetch_on_bits ( 'canviewbugs' ) . ")
116 AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits ( 'canviewhidden' ) . ")))" . (( $this- > registry
-> options
[ 'hidestatuses' ] OR isset ( $this- > registry
-> userinfo
[ 'hidestatuses' ])) ? "
117 AND bug.status NOT IN (" . ( $this- > registry
-> userinfo
[ 'hidestatuses' ] != '' ? $this- > registry
-> userinfo
[ 'hidestatuses' ] : $this- > registry
-> options
[ 'hidestatuses' ]) . ")" : "" );
119 // remap the sort keys to be actual SQL fields
122 'summary' => 'summary' ,
123 'reporter' => 'userid' ,
124 'lastpost' => ( can_perform ( 'canviewhidden' ) ? "lastposttime" : "hiddenlastposttime" )
127 switch ( $this- > sortkey
)
134 SELECT * FROM " . TABLE_PREFIX
. "bug AS bug
136 (is_array( $where ) ? "
137 AND " . implode(" \nAND
", $where ) : " ") . "
138 ORDER BY
" . $querykeys [ $this- >sortkey ] . " " . strtoupper( $this- >direction) . ( $this- >sortkey != 'lastpost' ? " , " . $querykeys ['lastpost'] . " " . strtoupper( $this- >direction) : " ") . ( $limit ? "
147 SELECT * FROM " . TABLE_PREFIX
. " {$this->sortkey} AS {$this->sortkey}
148 RIGHT JOIN " . TABLE_PREFIX
. "bug AS bug
149 ON (bug. {$this->sortkey} = {$this->sortkey} . {$this->sortkey} id)
151 (is_array( $where ) ? "
152 AND " . implode(" \nAND
", $where ) : " ") . "
153 ORDER BY {$this
-> sortkey
}. displayorder
" . strtoupper( $this- >direction) . " , bug
. $querykeys [ lastpost
] " . strtoupper( $this- >direction) . ( $limit ? "
161 // ###################################################################
163 * Returns the display text for a given sort order key
165 * @access public static
167 * @param string Sort order key, or FALSE for the array
169 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
171 function fetch_by_text ( $key )
176 'lastpost' => _ ( 'Last Post Time' ),
178 'summary' => _ ( 'Summary' ),
179 'reporter' => _ ( 'Reporter' ),
180 'product' => _ ( 'Product' ),
181 'status' => _ ( 'Status' ),
182 'resolution' => _ ( 'Resolution' ),
183 'priority' => _ ( 'Priority' ),
184 'severity' => _ ( 'Severity' )
193 return $keys [ " $key" ];
197 // ###################################################################
199 * Returns the display text for a given sort order direction
201 * @access public static
203 * @param string Sort direction, or FALSE for the array
205 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
207 function fetch_as_text( $key )
212 'desc' => _('Descending'),
213 'asc' => _('Ascending')
222 return $keys [" $key" ];
226 // ###################################################################
228 * Returns a multi-dimensional array with sort by keys indexing arrays
229 * with 'image' and 'href' keys that store the values from
230 * fetch_sort_image() and fetch_sort_link(), respectively
234 * @param string Extra GET parameters to pass to fetch_sort_link()
236 * @return array Array as described above
238 function fetch_display_array ( $params = null )
240 $return = $this- > fetch_by_text ( false );
242 foreach ( $return AS $key => $nil )
244 $return [ " $key" ] = array('image' => ( $this- >sortkey == $key ? $this- >fetch_sort_image() : ''), 'href' => $this- >fetch_sort_link( $key , $params , true));
250 // ###################################################################
252 * Returns the entire <img> tag for the sort arrow
256 * @return string HTML <img> tag
258 function fetch_sort_image()
260 return '<img src=" templates
/ images
/ arrow_
' . $this- >fetch_sort_direction() . ' . gif
" alt=" " style=" vertical
- align
: top
; border
: none
" />';
263 // ###################################################################
265 * Returns the href value for an <a> tag by generating all the necessary
266 * bits and concat'ing it onto an extra string of GETs (optional)
270 * @param string Sorting key
271 * @param string Additional GET parameters
272 * @param bool Highlight the current sortkey if that's passed?
274 * @return string HREF
276 function fetch_sort_link( $key , $params = null, $highlight = false)
283 return $this- >page . '.php?' . $params . 'by=' . $key . '&as=' . (( $this- >sortkey == $key AND $highlight ) ? $this- >fetch_opposite_sort_direction() . '" class = "select' : $this- >fetch_sort_direction());
286 // ###################################################################
288 * Returns the OPPOSITE direction to sort when you click on a link
292 * @return string Either asc or desc
294 function fetch_opposite_sort_direction()
296 if ( $this- >direction == 'asc')
306 // ###################################################################
308 * Returns the current sorted direction for the image path
312 * @return string Either asc or desc
314 function fetch_sort_direction()
316 return $this- >direction;
320 /*=====================================================================*\
321 || ###################################################################
324 || ###################################################################
325 \*=====================================================================*/