]>
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
64 * Column array for table heads
69 // ###################################################################
71 * Constructor: set the page name
75 * @param string File name without the .php extension
77 function ListSorter ( $page )
80 $this- > registry
= $bugsys ;
82 $this- > process_incoming ();
85 // ###################################################################
87 * Processes the incoming variables and then sets all the sort order
88 * information appropriately
92 function process_incoming ()
94 $this- > sortkey
= $this- > registry
-> in
[ 'by' ];
95 if (! $this- > fetch_by_text ( $this- > registry
-> in
[ 'by' ]))
97 $this- > sortkey
= ( isset ( $this- > registry
-> userinfo
[ 'defaultsortkey' ]) ? $this- > registry
-> userinfo
[ 'defaultsortkey' ] : $this- > registry
-> options
[ 'defaultsortkey' ]);
100 $this- > direction
= $this- > registry
-> in
[ 'as' ];
101 if (! in_array ( $this- > direction
, array ( 'asc' , 'desc' )))
103 $this- > direction
= ( isset ( $this- > registry
-> userinfo
[ 'defaultsortas' ]) ? $this- > registry
-> userinfo
[ 'defaultsortas' ] : $this- > registry
-> options
[ 'defaultsortas' ]);
107 // ###################################################################
109 * Fetch a SQL query to gather bugs with the sort filters applied
113 * @param string Additional WHERE clauses in an array
114 * @param string A LIMIT clause
116 * @return string Compiled SQL query
118 function fetch_sql_query ( $where = null , $limit = null )
120 // this WHERE clause is used for all the queries
121 $basewhere = "bug.product IN (" . fetch_on_bits ( 'canviewbugs' ) . ")
122 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' ) . "))" : "" ) . ")" .
123 (( $this- > registry
-> options
[ 'hidestatuses' ] OR isset ( $this- > registry
-> userinfo
[ 'hidestatuses' ])) ? "
124 AND bug.status NOT IN (" . ( $this- > registry
-> userinfo
[ 'hidestatuses' ] != '' ? $this- > registry
-> userinfo
[ 'hidestatuses' ] : $this- > registry
-> options
[ 'hidestatuses' ]) . ")" : "" );
126 // remap the sort keys to be actual SQL fields
129 'summary' => 'summary' ,
130 'reporter' => 'userid' ,
131 'lastpost' => ( can_perform ( 'canviewhidden' ) ? "lastposttime" : "hiddenlastposttime" )
134 switch ( $this- > sortkey
)
141 SELECT * FROM " . TABLE_PREFIX
. "bug AS bug
143 (is_array( $where ) ? "
144 AND " . implode(" \nAND
", $where ) : " ") . "
145 ORDER BY
" . $querykeys [ $this- >sortkey ] . " " . strtoupper( $this- >direction) . ( $this- >sortkey != 'lastpost' ? " , " . $querykeys ['lastpost'] . " " . strtoupper( $this- >direction) : " ") . ( $limit ? "
154 SELECT * FROM " . TABLE_PREFIX
. " {$this->sortkey} AS {$this->sortkey}
155 RIGHT JOIN " . TABLE_PREFIX
. "bug AS bug
156 ON (bug. {$this->sortkey} = {$this->sortkey} . {$this->sortkey} id)
158 (is_array( $where ) ? "
159 AND " . implode(" \nAND
", $where ) : " ") . "
160 ORDER BY {$this
-> sortkey
}. displayorder
" . strtoupper( $this- >direction) . " , bug
. $querykeys [ lastpost
] " . strtoupper( $this- >direction) . ( $limit ? "
168 // ###################################################################
170 * Returns the display text for a given sort order key
172 * @access public static
174 * @param string Sort order key, or FALSE for the array
176 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
178 function fetch_by_text ( $key )
183 'lastpost' => _ ( 'Last Post Time' ),
184 'bugid' => _ ( 'Bug ID' ),
185 'summary' => _ ( 'Summary' ),
186 'reporter' => _ ( 'Reporter' ),
187 'product' => _ ( 'Product' ),
188 'status' => _ ( 'Status' ),
189 'resolution' => _ ( 'Resolution' ),
190 'priority' => _ ( 'Priority' ),
191 'severity' => _ ( 'Severity' )
200 return $keys [ " $key" ];
204 // ###################################################################
206 * Returns the display text for a given sort order direction
208 * @access public static
210 * @param string Sort direction, or FALSE for the array
212 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
214 function fetch_as_text( $key )
219 'desc' => _('Descending'),
220 'asc' => _('Ascending')
229 return $keys [" $key" ];
233 // ###################################################################
235 * Returns a multi-dimensional array with sort by keys indexing arrays
236 * with 'image' and 'href' keys that store the values from
237 * fetch_sort_image() and fetch_sort_link(), respectively
241 * @param string Extra GET parameters to pass to fetch_sort_link()
243 * @return array Array as described above
245 function fetch_display_array ( $params = null )
247 $return = $this- > fetch_by_text ( false );
249 foreach ( $return AS $key => $nil )
251 $return [ " $key" ] = array('image' => ( $this- >sortkey == $key ? $this- >fetch_sort_image() : ''), 'href' => $this- >fetch_sort_link( $key , $params , true));
257 // ###################################################################
259 * Returns the entire <img> tag for the sort arrow
263 * @return string HTML <img> tag
265 function fetch_sort_image()
267 return '<img src=" templates
/ images
/ arrow_
' . $this- >fetch_sort_direction() . ' . gif
" alt=" " style=" vertical
- align
: top
; border
: none
" />';
270 // ###################################################################
272 * Returns the href value for an <a> tag by generating all the necessary
273 * bits and concat'ing it onto an extra string of GETs (optional)
277 * @param string Sorting key
278 * @param string Additional GET parameters
279 * @param bool Highlight the current sortkey if that's passed?
281 * @return string HREF
283 function fetch_sort_link( $key , $params = null, $highlight = false)
290 return $this- >page . '.php?' . $params . 'by=' . $key . '&as=' . (( $this- >sortkey == $key AND $highlight ) ? $this- >fetch_opposite_sort_direction() . '" class = "select' : $this- >fetch_sort_direction());
293 // ###################################################################
295 * Returns the OPPOSITE direction to sort when you click on a link
299 * @return string Either asc or desc
301 function fetch_opposite_sort_direction()
303 if ( $this- >direction == 'asc')
313 // ###################################################################
315 * Returns the current sorted direction for the image path
319 * @return string Either asc or desc
321 function fetch_sort_direction()
323 return $this- >direction;
326 // ###################################################################
328 * Returns the HTML code for bug listing table column headers
330 * @param bool Include the sort links/image?
331 * @param string Additional GET params to pass to fetch_sort_link()
333 * @return string HTML code
335 function constructColumnHeaders( $sortable , $params = null)
337 $this- >_processColumns();
340 foreach ( $this- >columns AS $columns )
343 foreach ( $columns AS $column )
345 $build [] = ( $sortable ? '<a href=" ' . $this- >fetch_sort_link( $column , $params , true) . ' ">' . $this- >registry->columnNames[" $column" ] . '</a>' : $this- > registry
-> columnNames
[ " $column" ]);
347 $image = (in_array( $this- >sortkey, $columns ) ? $this- >fetch_sort_image() : '');
348 $name = implode(' / ', $build );
349 eval(' $output .= " ' . $this- >registry->template->fetch(' list_head
') . ' ";');
355 // ###################################################################
357 * Returns the HTML code for a row of data for the bug listing
359 * @param array Bug data array
360 * @param string Additional link params
362 * @return string Row HTML
364 function constructRow( $bug , $params = null)
366 $this- >_processColumns();
368 foreach ( $this- >columns AS $columns )
370 if (sizeof( $columns ) > 1)
373 foreach ( $columns AS $column )
375 $build [] = '<div>' . $this- >_processDataForColumn( $bug , $column , $params ) . '</div>';
377 $data = " \n\t\t
" . implode(" \n\t\t
", $build ) . " \n\t
";
381 $data = $this- >_processDataForColumn( $bug , $columns [0], $params );
383 $fields .= " \n\t
< td
> $data </ td
> ";
386 eval(' $output = " ' . $this- >registry->template->fetch(' trackerhome_bits
') . ' ";');
390 // ###################################################################
392 * Handler for special-case column data
394 * @param array Bug data
395 * @param string Column name
396 * @param string Additional URL params
398 * @return string Processed column data
400 function _processDataForColumn( $bug , $column , $params = null)
405 return '<a href=" showreport
. php
? bugid
= ' . $bug [' bugid
'] . $params . ' ">' . $bug ['summary'] . '</a>';
407 return ( $bug ['userid'] ? $bug ['username'] : _('Guest'));
409 return $bug ['lastposttime'] . " \n\t\t
< div
> " . ( $bug ['lastpost'] ? $bug ['lastpost'] : _('Guest'));
411 return $bug [" $column" ];
415 // ###################################################################
417 * Sets up $this->columns so that the data can be processed more
420 function _processColumns ()
422 if ( is_array ( $this- > columns
))
427 $array = (( $this- > registry
-> userinfo
[ 'userid' ] AND is_array ( $this- > registry
-> userinfo
[ 'columnoptions' ])) ? $this- > registry
-> userinfo
[ 'columnoptions' ] : $this- > registry
-> options
[ 'columnoptions' ]);
429 foreach ( $array AS $column => $position )
433 $this- > columns
[ " $position" ][] = $column ;
437 ksort( $this- >columns);
441 /*=====================================================================*\
442 || ###################################################################
445 || ###################################################################
446 \*=====================================================================*/