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 ?
"
156 SELECT * FROM " . TABLE_PREFIX
. "{$this->sortkey} AS {$this->sortkey}
157 RIGHT JOIN " . TABLE_PREFIX
. "bug AS bug
158 ON (bug.{$this->sortkey} = {$this->sortkey}.{$this->sortkey}id)
160 (is_array($where) ?
"
161 AND " . implode("\nAND ", $where) : "") . "
162 ORDER BY {$this->sortkey}.displayorder " . strtoupper($this->direction
) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction
) . ($limit ?
"
170 // ###################################################################
172 * Returns the display text for a given sort order key
174 * @access public static
176 * @param string Sort order key, or FALSE for the array
178 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
180 function fetch_by_text($key)
185 'lastpost' => _('Last Post Time'),
186 'bugid' => _('Bug ID'),
187 'summary' => _('Summary'),
188 'reporter' => _('Reporter'),
189 'product' => _('Product'),
190 'version' => _('Version'),
191 'status' => _('Status'),
192 'resolution' => _('Resolution'),
193 'priority' => _('Priority'),
194 'severity' => _('Severity')
203 return $keys["$key"];
207 // ###################################################################
209 * Returns the display text for a given sort order direction
211 * @access public static
213 * @param string Sort direction, or FALSE for the array
215 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
217 function fetch_as_text($key)
222 'desc' => _('Descending'),
223 'asc' => _('Ascending')
232 return $keys["$key"];
236 // ###################################################################
238 * Returns a multi-dimensional array with sort by keys indexing arrays
239 * with 'image' and 'href' keys that store the values from
240 * fetch_sort_image() and fetch_sort_link(), respectively
244 * @param string Extra GET parameters to pass to fetch_sort_link()
246 * @return array Array as described above
248 function fetch_display_array($params = null
)
250 $return = $this->fetch_by_text(false
);
252 foreach ($return AS $key => $nil)
254 $return["$key"] = array('image' => ($this->sortkey
== $key ?
$this->fetch_sort_image() : ''), 'href' => $this->fetch_sort_link($key, $params, true
));
260 // ###################################################################
262 * Returns the entire <img> tag for the sort arrow
266 * @return string HTML <img> tag
268 function fetch_sort_image()
270 return '<img src="templates/images/arrow_' . $this->fetch_sort_direction() . '.gif" alt="" style="vertical-align: top; border: none" />';
273 // ###################################################################
275 * Returns the href value for an <a> tag by generating all the necessary
276 * bits and concat'ing it onto an extra string of GETs (optional)
280 * @param string Sorting key
281 * @param string Additional GET parameters
282 * @param bool Highlight the current sortkey if that's passed?
284 * @return string HREF
286 function fetch_sort_link($key, $params = null
, $highlight = false
)
293 return $this->page
. '.php?' . $params . 'by=' . $key . '&as=' . (($this->sortkey
== $key AND $highlight) ?
$this->fetch_opposite_sort_direction() . '" class="select' : $this->fetch_sort_direction());
296 // ###################################################################
298 * Returns the OPPOSITE direction to sort when you click on a link
302 * @return string Either asc or desc
304 function fetch_opposite_sort_direction()
306 if ($this->direction
== 'asc')
316 // ###################################################################
318 * Returns the current sorted direction for the image path
322 * @return string Either asc or desc
324 function fetch_sort_direction()
326 return $this->direction
;
329 // ###################################################################
331 * Returns the HTML code for bug listing table column headers
333 * @param bool Include the sort links/image?
334 * @param string Additional GET params to pass to fetch_sort_link()
336 * @return string HTML code
338 function constructColumnHeaders($sortable, $params = null
)
340 $this->_processColumns();
343 foreach ($this->columns
AS $columns)
346 foreach ($columns AS $column)
348 $build[] = ($sortable ?
'<a href="' . $this->fetch_sort_link($column, $params, true
) . '">' . $this->registry
->columnNames
["$column"] . '</a>' : $this->registry
->columnNames
["$column"]);
350 $image = (in_array($this->sortkey
, $columns) ?
$this->fetch_sort_image() : '');
351 $name = implode(' / ', $build);
352 eval('$output .= "' . $this->registry
->template
->fetch('list_head') . '";');
358 // ###################################################################
360 * Returns the HTML code for a row of data for the bug listing
362 * @param array Bug data array
363 * @param string Additional link params
365 * @return string Row HTML
367 function constructRow($bug, $params = null
)
369 $this->_processColumns();
371 foreach ($this->columns
AS $columns)
373 if (sizeof($columns) > 1)
376 foreach ($columns AS $column)
378 $build[] = '<div>' . $this->_processDataForColumn($bug, $column, $params) . '</div>';
380 $data = "\n\t\t" . implode("\n\t\t", $build) . "\n\t";
384 $data = $this->_processDataForColumn($bug, $columns[0], $params);
386 $fields .= "\n\t<td>$data</td>";
389 eval('$output = "' . $this->registry
->template
->fetch('trackerhome_bits') . '";');
393 // ###################################################################
395 * Handler for special-case column data
397 * @param array Bug data
398 * @param string Column name
399 * @param string Additional URL params
401 * @return string Processed column data
403 function _processDataForColumn($bug, $column, $params = null
)
408 return '<a href="showreport.php?bugid=' . $bug['bugid'] . $params . '">' . $bug['summary'] . '</a>';
410 return ($bug['userid'] ?
$bug['username'] : _('Guest'));
412 return $bug['lastposttime'] . "\n\t\t<div>" . _('by') . ' ' . ($bug['lastpost'] ?
$bug['lastpost'] : _('Guest'));
414 return $bug["$column"];
418 // ###################################################################
420 * Sets up $this->columns so that the data can be processed more
423 function _processColumns()
425 if (is_array($this->columns
))
430 $array = (($this->registry
->userinfo
['userid'] AND is_array($this->registry
->userinfo
['columnoptions'])) ?
$this->registry
->userinfo
['columnoptions'] : $this->registry
->options
['columnoptions']);
432 foreach ($array AS $column => $position)
436 $this->columns
["$position"][] = $column;
440 ksort($this->columns
);
444 /*=====================================================================*\
445 || ###################################################################
448 || ###################################################################
449 \*=====================================================================*/