]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_sort.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
27 * @author Iris Studios, Inc.
28 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
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
= 'lastpost' ;
94 $this- > direction
= $this- > registry
-> in
[ 'as' ];
95 if (! in_array ( $this- > direction
, array ( 'asc' , 'desc' )))
97 $this- > direction
= 'desc' ;
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 (" . ( isset ( $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 ] . ( $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 'id' => $lang- > string ( 'Bug ID' ),
177 'summary' => $lang- > string ( 'Summary' ),
178 'reporter' => $lang- > string ( 'Reporter' ),
179 'product' => $lang- > string ( 'Product' ),
180 'status' => $lang- > string ( 'Status' ),
181 'resolution' => $lang- > string ( 'Resolution' ),
182 'priority' => $lang- > string ( 'Priority' ),
183 'severity' => $lang- > string ( 'Severity' ),
184 'lastpost' => $lang- > string ( 'Last Post Time' )
193 return $keys [ " $key" ];
197 // ###################################################################
199 * Returns a multi-dimensional array with sort by keys indexing arrays
200 * with 'image' and 'href' keys that store the values from
201 * fetch_sort_image() and fetch_sort_link(), respectively
205 * @param string Extra GET parameters to pass to fetch_sort_link()
207 * @return array Array as described above
209 function fetch_display_array( $params = null)
211 $return = $this- >fetch_by_text(false);
213 foreach ( $return AS $key => $nil )
215 $return [" $key" ] = array ( 'image' => ( $this- > sortkey
== $key ? $this- > fetch_sort_image () : '' ), 'href' => $this- > fetch_sort_link ( $key , $params , true ));
221 // ###################################################################
223 * Returns the entire <img> tag for the sort arrow
227 * @return string HTML <img> tag
229 function fetch_sort_image ()
231 return '<img src="templates/images/arrow_' . $this- > fetch_sort_direction () . '.gif" alt="" style="vertical-align: top; border: none" />' ;
234 // ###################################################################
236 * Returns the href value for an <a> tag by generating all the necessary
237 * bits and concat'ing it onto an extra string of GETs (optional)
241 * @param string Sorting key
242 * @param string Additional GET parameters
243 * @param bool Highlight the current sortkey if that's passed?
245 * @return string HREF
247 function fetch_sort_link ( $key , $params = null , $highlight = false )
254 return $this- > page
. '.php?' . $params . 'by=' . $key . '&as=' . (( $this- > sortkey
== $key AND $highlight ) ? $this- > fetch_opposite_sort_direction () . '" class="select' : $this- > fetch_sort_direction ());
257 // ###################################################################
259 * Returns the OPPOSITE direction to sort when you click on a link
263 * @return string Either asc or desc
265 function fetch_opposite_sort_direction ()
267 if ( $this- > direction
== 'asc' )
277 // ###################################################################
279 * Returns the current sorted direction for the image path
283 * @return string Either asc or desc
285 function fetch_sort_direction ()
287 return $this- > direction
;
291 /*=====================================================================*\
292 || ###################################################################
295 || ###################################################################
296 \*=====================================================================*/