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 bug.*, vote.votefor, vote.voteagainst FROM " . TABLE_PREFIX
. "bug AS bug
142 LEFT JOIN " . TABLE_PREFIX
. "vote AS vote
143 ON (bug.bugid = vote.bugid)
145 (is_array($where) ?
"
146 AND " . implode("\nAND ", $where) : "") . "
147 ORDER BY " . $querykeys[ $this->sortkey
] . " " . strtoupper($this->direction
) . ($this->sortkey
!= 'lastpost' ?
", " . $querykeys['lastpost'] . " " . strtoupper($this->direction
) : "") . ($limit ?
"
157 $key = ($this->sortkey
!= 'component' ?
$this->sortkey
: 'product');
159 SELECT $key.*, bug.*, vote.votefor, vote.voteagainst FROM " . TABLE_PREFIX
. "$key AS $key
160 RIGHT JOIN " . TABLE_PREFIX
. "bug AS bug
161 ON (bug.$key = $key.{$key}id)
162 LEFT JOIN " . TABLE_PREFIX
. "vote AS vote
163 ON (bug.bugid = vote.bugid)
165 (is_array($where) ?
"
166 AND " . implode("\nAND ", $where) : "") . "
167 ORDER BY $key.displayorder " . strtoupper($this->direction
) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction
) . ($limit ?
"
172 SELECT bug.*, vote.votefor, vote.voteagainst FROM " . TABLE_PREFIX
. "bug AS bug
173 LEFT JOIN " . TABLE_PREFIX
. "vote AS vote
174 ON (bug.bugid = vote.bugid)
176 (is_array($where) ?
"
177 AND " . implode("\nAND ", $where) : "") . "
178 ORDER BY vote.votefor " . strtoupper($this->direction
) . ", vote.voteagainst " . strtoupper($this->fetch_opposite_sort_direction()) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction
) . ($limit ?
"
186 // ###################################################################
188 * Returns the display text for a given sort order key
190 * @access public static
192 * @param string Sort order key, or FALSE for the array
194 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
196 function fetch_by_text($key)
201 'lastpost' => _('Last Post Time'),
202 'bugid' => _('Bug ID'),
203 'summary' => _('Summary'),
204 'reporter' => _('Reporter'),
205 'product' => _('Product'),
206 'component' => _('Component'),
207 'version' => _('Version'),
208 'status' => _('Status'),
209 'resolution' => _('Resolution'),
210 'priority' => _('Priority'),
211 'severity' => _('Severity'),
212 'votes' => _('Votes')
221 return $keys["$key"];
225 // ###################################################################
227 * Returns the display text for a given sort order direction
229 * @access public static
231 * @param string Sort direction, or FALSE for the array
233 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
235 function fetch_as_text($key)
240 'desc' => _('Descending'),
241 'asc' => _('Ascending')
250 return $keys["$key"];
254 // ###################################################################
256 * Returns a multi-dimensional array with sort by keys indexing arrays
257 * with 'image' and 'href' keys that store the values from
258 * fetch_sort_image() and fetch_sort_link(), respectively
262 * @param string Extra GET parameters to pass to fetch_sort_link()
264 * @return array Array as described above
266 function fetch_display_array($params = null
)
268 $return = $this->fetch_by_text(false
);
270 foreach ($return AS $key => $nil)
272 $return["$key"] = array('image' => ($this->sortkey
== $key ?
$this->fetch_sort_image() : ''), 'href' => $this->fetch_sort_link($key, $params, true
));
278 // ###################################################################
280 * Returns the entire <img> tag for the sort arrow
284 * @return string HTML <img> tag
286 function fetch_sort_image()
288 return '<img src="templates/images/arrow_' . $this->fetch_sort_direction() . '.gif" alt="" style="vertical-align: top; border: none" />';
291 // ###################################################################
293 * Returns the href value for an <a> tag by generating all the necessary
294 * bits and concat'ing it onto an extra string of GETs (optional)
298 * @param string Sorting key
299 * @param string Additional GET parameters
300 * @param bool Highlight the current sortkey if that's passed?
302 * @return string HREF
304 function fetch_sort_link($key, $params = null
, $highlight = false
)
311 return $this->page
. '.php?' . $params . 'by=' . $key . '&as=' . (($this->sortkey
== $key AND $highlight) ?
$this->fetch_opposite_sort_direction() . '" class="select' : $this->fetch_sort_direction());
314 // ###################################################################
316 * Returns the OPPOSITE direction to sort when you click on a link
320 * @return string Either asc or desc
322 function fetch_opposite_sort_direction()
324 if ($this->direction
== 'asc')
334 // ###################################################################
336 * Returns the current sorted direction for the image path
340 * @return string Either asc or desc
342 function fetch_sort_direction()
344 return $this->direction
;
347 // ###################################################################
349 * Returns the HTML code for bug listing table column headers
351 * @param bool Include the sort links/image?
352 * @param string Additional GET params to pass to fetch_sort_link()
354 * @return string HTML code
356 function constructColumnHeaders($sortable, $params = null
)
358 $this->_processColumns();
361 foreach ($this->columns
AS $columns)
364 foreach ($columns AS $column)
366 $build[] = ($sortable ?
'<a href="' . $this->fetch_sort_link($column, $params, true
) . '">' . $this->registry
->columnNames
["$column"] . '</a>' : $this->registry
->columnNames
["$column"]);
368 $image = ((in_array($this->sortkey
, $columns) AND $sortable) ?
$this->fetch_sort_image() : '');
369 $name = implode(' / ', $build);
370 eval('$output .= "' . $this->registry
->template
->fetch('list_head') . '";');
376 // ###################################################################
378 * Returns the HTML code for a row of data for the bug listing
380 * @param array Bug data array
381 * @param string Additional link params
383 * @return string Row HTML
385 function constructRow($bug, $params = null
)
387 $this->_processColumns();
389 foreach ($this->columns
AS $columns)
391 if (sizeof($columns) > 1)
394 foreach ($columns AS $column)
396 $build[] = $this->_processDataForColumn($bug, $column, $params, true
);
398 $data = "\n\t\t" . implode("\n\t\t", $build) . "\n\t";
402 $data = $this->_processDataForColumn($bug, $columns[0], $params, false
);
404 $fields .= "\n\t<td>$data</td>";
407 eval('$output = "' . $this->registry
->template
->fetch('trackerhome_bits') . '";');
411 // ###################################################################
413 * Handler for special-case column data
415 * @param array Bug data
416 * @param string Column name
417 * @param string Additional URL params
418 * @param bool Will this column have multiple data sets?
420 * @return string Processed column data
422 function _processDataForColumn($bug, $column, $params = null
, $multi = false
)
424 $open = ($multi ?
'<div>' : '');
425 $close = ($multi ?
'</div>' : '');
429 return $open . '<a href="showreport.php?bugid=' . $bug['bugid'] . $params . '">' . $bug['summary'] . '</a>' . $close;
431 return $open . ($bug['userid'] ?
$bug['username'] : _('Guest')) . $close;
433 return "\n\t\t<div>" . $bug['lastposttime'] . "</div>\n\t\t<div>" . _('by') . ' ' . ($bug['lastpost'] ?
$bug['lastpost'] : _('Guest')) . "</div>\n\t";
435 return "\n\t\t<div>" . _('For:') . ' ' . $bug['votefor'] . "</div>\n\t\t<div>" . _('Against:') . ' ' . $bug['voteagainst'] . "</div>\n\t";
437 return $open . $bug["$column"] . $close;
441 // ###################################################################
443 * Sets up $this->columns so that the data can be processed more
446 function _processColumns()
448 if (is_array($this->columns
))
453 $array = (($this->registry
->userinfo
['userid'] AND is_array($this->registry
->userinfo
['columnoptions'])) ?
$this->registry
->userinfo
['columnoptions'] : $this->registry
->options
['columnoptions']);
455 foreach ($array AS $column => $position)
459 $this->columns
["$position"][] = $column;
463 ksort($this->columns
);
467 /*=====================================================================*\
468 || ###################################################################
471 || ###################################################################
472 \*=====================================================================*/