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') . "))" . (can_perform('canviewownhidden') ?
" OR (bug.hidden AND bug.userid = " . $this->registry
->userinfo
['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewownhidden') . "))" : "") . ")" .
117 (($this->registry
->options
['hidestatuses'] OR isset($this->registry
->userinfo
['hidestatuses'])) ?
"
118 AND bug.status NOT IN (" . ($this->registry
->userinfo
['hidestatuses'] != '' ?
$this->registry
->userinfo
['hidestatuses'] : $this->registry
->options
['hidestatuses']) . ")" : "");
120 // remap the sort keys to be actual SQL fields
123 'summary' => 'summary',
124 'reporter' => 'userid',
125 'lastpost' => (can_perform('canviewhidden') ?
"lastposttime" : "hiddenlastposttime")
128 switch ($this->sortkey
)
135 SELECT * FROM " . TABLE_PREFIX
. "bug AS bug
137 (is_array($where) ?
"
138 AND " . implode("\nAND ", $where) : "") . "
139 ORDER BY " . $querykeys[ $this->sortkey
] . " " . strtoupper($this->direction
) . ($this->sortkey
!= 'lastpost' ?
", " . $querykeys['lastpost'] . " " . strtoupper($this->direction
) : "") . ($limit ?
"
148 SELECT * FROM " . TABLE_PREFIX
. "{$this->sortkey} AS {$this->sortkey}
149 RIGHT JOIN " . TABLE_PREFIX
. "bug AS bug
150 ON (bug.{$this->sortkey} = {$this->sortkey}.{$this->sortkey}id)
152 (is_array($where) ?
"
153 AND " . implode("\nAND ", $where) : "") . "
154 ORDER BY {$this->sortkey}.displayorder " . strtoupper($this->direction
) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction
) . ($limit ?
"
162 // ###################################################################
164 * Returns the display text for a given sort order key
166 * @access public static
168 * @param string Sort order key, or FALSE for the array
170 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
172 function fetch_by_text($key)
177 'lastpost' => _('Last Post Time'),
179 'summary' => _('Summary'),
180 'reporter' => _('Reporter'),
181 'product' => _('Product'),
182 'status' => _('Status'),
183 'resolution' => _('Resolution'),
184 'priority' => _('Priority'),
185 'severity' => _('Severity')
194 return $keys["$key"];
198 // ###################################################################
200 * Returns the display text for a given sort order direction
202 * @access public static
204 * @param string Sort direction, or FALSE for the array
206 * @return mixed Display text if param is string, or array of all key=>text if param is NULL
208 function fetch_as_text($key)
213 'desc' => _('Descending'),
214 'asc' => _('Ascending')
223 return $keys["$key"];
227 // ###################################################################
229 * Returns a multi-dimensional array with sort by keys indexing arrays
230 * with 'image' and 'href' keys that store the values from
231 * fetch_sort_image() and fetch_sort_link(), respectively
235 * @param string Extra GET parameters to pass to fetch_sort_link()
237 * @return array Array as described above
239 function fetch_display_array($params = null
)
241 $return = $this->fetch_by_text(false
);
243 foreach ($return AS $key => $nil)
245 $return["$key"] = array('image' => ($this->sortkey
== $key ?
$this->fetch_sort_image() : ''), 'href' => $this->fetch_sort_link($key, $params, true
));
251 // ###################################################################
253 * Returns the entire <img> tag for the sort arrow
257 * @return string HTML <img> tag
259 function fetch_sort_image()
261 return '<img src="templates/images/arrow_' . $this->fetch_sort_direction() . '.gif" alt="" style="vertical-align: top; border: none" />';
264 // ###################################################################
266 * Returns the href value for an <a> tag by generating all the necessary
267 * bits and concat'ing it onto an extra string of GETs (optional)
271 * @param string Sorting key
272 * @param string Additional GET parameters
273 * @param bool Highlight the current sortkey if that's passed?
275 * @return string HREF
277 function fetch_sort_link($key, $params = null
, $highlight = false
)
284 return $this->page
. '.php?' . $params . 'by=' . $key . '&as=' . (($this->sortkey
== $key AND $highlight) ?
$this->fetch_opposite_sort_direction() . '" class="select' : $this->fetch_sort_direction());
287 // ###################################################################
289 * Returns the OPPOSITE direction to sort when you click on a link
293 * @return string Either asc or desc
295 function fetch_opposite_sort_direction()
297 if ($this->direction
== 'asc')
307 // ###################################################################
309 * Returns the current sorted direction for the image path
313 * @return string Either asc or desc
315 function fetch_sort_direction()
317 return $this->direction
;
321 /*=====================================================================*\
322 || ###################################################################
325 || ###################################################################
326 \*=====================================================================*/