[ Index ] |
PHP Cross Reference of Eventum |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */ 3 // +----------------------------------------------------------------------+ 4 // | Eventum - Issue Tracking System | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB | 7 // | | 8 // | This program is free software; you can redistribute it and/or modify | 9 // | it under the terms of the GNU General Public License as published by | 10 // | the Free Software Foundation; either version 2 of the License, or | 11 // | (at your option) any later version. | 12 // | | 13 // | This program is distributed in the hope that it will be useful, | 14 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 // | GNU General Public License for more details. | 17 // | | 18 // | You should have received a copy of the GNU General Public License | 19 // | along with this program; if not, write to: | 20 // | | 21 // | Free Software Foundation, Inc. | 22 // | 59 Temple Place - Suite 330 | 23 // | Boston, MA 02111-1307, USA. | 24 // +----------------------------------------------------------------------+ 25 // | Authors: João Prado Maia <jpm@mysql.com> | 26 // +----------------------------------------------------------------------+ 27 // 28 // @(#) $Id: class.priority.php 3387 2007-10-15 10:09:10Z glen $ 29 // 30 31 require_once (APP_INC_PATH . "class.error_handler.php"); 32 require_once (APP_INC_PATH . "class.misc.php"); 33 require_once (APP_INC_PATH . "class.validation.php"); 34 35 /** 36 * Class to handle project priority related issues. 37 * 38 * @version 1.0 39 * @author João Prado Maia <jpm@mysql.com> 40 */ 41 42 class Priority 43 { 44 /** 45 * Method used to quickly change the ranking of a reminder entry 46 * from the administration screen. 47 * 48 * @access public 49 * @param integer $pri_id The reminder entry ID 50 * @param string $rank_type Whether we should change the reminder ID down or up (options are 'asc' or 'desc') 51 * @return boolean 52 */ 53 function changeRank($prj_id, $pri_id, $rank_type) 54 { 55 // check if the current rank is not already the first or last one 56 $ranking = Priority::_getRanking($prj_id); 57 $ranks = array_values($ranking); 58 $ids = array_keys($ranking); 59 $last = end($ids); 60 $first = reset($ids); 61 if ((($rank_type == 'asc') && ($pri_id == $first)) || 62 (($rank_type == 'desc') && ($pri_id == $last))) { 63 return false; 64 } 65 66 if ($rank_type == 'asc') { 67 $diff = -1; 68 } else { 69 $diff = 1; 70 } 71 $new_rank = $ranking[$pri_id] + $diff; 72 if (in_array($new_rank, $ranks)) { 73 // switch the rankings here... 74 $index = array_search($new_rank, $ranks); 75 $replaced_pri_id = $ids[$index]; 76 $stmt = "UPDATE 77 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 78 SET 79 pri_rank=" . Misc::escapeInteger($ranking[$pri_id]) . " 80 WHERE 81 pri_prj_id=" . Misc::escapeInteger($prj_id) . " AND 82 pri_id=" . Misc::escapeInteger($replaced_pri_id); 83 $GLOBALS["db_api"]->dbh->query($stmt); 84 } 85 $stmt = "UPDATE 86 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 87 SET 88 pri_rank=" . Misc::escapeInteger($new_rank) . " 89 WHERE 90 pri_prj_id=" . Misc::escapeInteger($prj_id) . " AND 91 pri_id=" . Misc::escapeInteger($pri_id); 92 $GLOBALS["db_api"]->dbh->query($stmt); 93 return true; 94 } 95 96 97 /** 98 * Returns an associative array with the list of reminder IDs and 99 * their respective ranking. 100 * 101 * @access private 102 * @param integer $prj_id The ID of the project 103 * @return array The list of reminders 104 */ 105 function _getRanking($prj_id) 106 { 107 $stmt = "SELECT 108 pri_id, 109 pri_rank 110 FROM 111 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 112 WHERE 113 pri_prj_id=" . Misc::escapeInteger($prj_id) . " 114 ORDER BY 115 pri_rank ASC"; 116 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 117 if (PEAR::isError($res)) { 118 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 119 return array(); 120 } else { 121 return $res; 122 } 123 } 124 125 126 /** 127 * Method used to get the full details of a priority. 128 * 129 * @access public 130 * @param integer $pri_id The priority ID 131 * @return array The information about the priority provided 132 */ 133 function getDetails($pri_id) 134 { 135 $stmt = "SELECT 136 * 137 FROM 138 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 139 WHERE 140 pri_id=" . Misc::escapeInteger($pri_id); 141 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 142 if (PEAR::isError($res)) { 143 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 144 return ""; 145 } else { 146 return $res; 147 } 148 } 149 150 151 /** 152 * Method used to remove all priorities related to a set of 153 * specific projects. 154 * 155 * @access public 156 * @param array $ids The project IDs to be removed 157 * @return boolean Whether the removal worked or not 158 */ 159 function removeByProjects($ids) 160 { 161 $items = @implode(", ", Misc::escapeInteger($ids)); 162 $stmt = "DELETE FROM 163 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 164 WHERE 165 pri_prj_id IN ($items)"; 166 $res = $GLOBALS["db_api"]->dbh->query($stmt); 167 if (PEAR::isError($res)) { 168 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 169 return false; 170 } else { 171 return true; 172 } 173 } 174 175 176 /** 177 * Method used to remove user-selected priorities from the 178 * database. 179 * 180 * @access public 181 * @return boolean Whether the removal worked or not 182 */ 183 function remove() 184 { 185 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 186 $stmt = "DELETE FROM 187 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 188 WHERE 189 pri_id IN ($items)"; 190 $res = $GLOBALS["db_api"]->dbh->query($stmt); 191 if (PEAR::isError($res)) { 192 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 193 return false; 194 } else { 195 return true; 196 } 197 } 198 199 200 /** 201 * Method used to update the values stored in the database. 202 * Typically the user would modify the title of the priority in 203 * the application and this method would be called. 204 * 205 * @access public 206 * @return integer 1 if the update worked properly, any other value otherwise 207 */ 208 function update() 209 { 210 if (Validation::isWhitespace($_POST["title"])) { 211 return -2; 212 } 213 $stmt = "UPDATE 214 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 215 SET 216 pri_title='" . Misc::escapeString($_POST["title"]) . "', 217 pri_rank=" . Misc::escapeInteger($_POST['rank']) . " 218 WHERE 219 pri_prj_id=" . Misc::escapeInteger($_POST["prj_id"]) . " AND 220 pri_id=" . Misc::escapeInteger($_POST["id"]); 221 $res = $GLOBALS["db_api"]->dbh->query($stmt); 222 if (PEAR::isError($res)) { 223 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 224 return -1; 225 } else { 226 return 1; 227 } 228 } 229 230 231 /** 232 * Method used to add a new priority to the application. 233 * 234 * @access public 235 * @return integer 1 if the update worked properly, any other value otherwise 236 */ 237 function insert() 238 { 239 if (Validation::isWhitespace($_POST["title"])) { 240 return -2; 241 } 242 $stmt = "INSERT INTO 243 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 244 ( 245 pri_prj_id, 246 pri_title, 247 pri_rank 248 ) VALUES ( 249 " . Misc::escapeInteger($_POST["prj_id"]) . ", 250 '" . Misc::escapeString($_POST["title"]) . "', 251 " . Misc::escapeInteger($_POST['rank']) . " 252 )"; 253 $res = $GLOBALS["db_api"]->dbh->query($stmt); 254 if (PEAR::isError($res)) { 255 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 256 return -1; 257 } else { 258 return 1; 259 } 260 } 261 262 263 /** 264 * Method used to get the full list of priorities associated with 265 * a specific project. 266 * 267 * @access public 268 * @param integer $prj_id The project ID 269 * @return array The full list of priorities 270 */ 271 function getList($prj_id) 272 { 273 $stmt = "SELECT 274 pri_id, 275 pri_title, 276 pri_rank 277 FROM 278 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 279 WHERE 280 pri_prj_id=" . Misc::escapeInteger($prj_id) . " 281 ORDER BY 282 pri_rank ASC"; 283 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 284 if (PEAR::isError($res)) { 285 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 286 return ""; 287 } else { 288 return $res; 289 } 290 } 291 292 293 /** 294 * Method used to get the title for a priority ID. 295 * 296 * @access public 297 * @param integer $pri_id The priority ID 298 * @return string The priority title 299 */ 300 function getTitle($pri_id) 301 { 302 $stmt = "SELECT 303 pri_title 304 FROM 305 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 306 WHERE 307 pri_id=" . Misc::escapeInteger($pri_id); 308 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 309 if (PEAR::isError($res)) { 310 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 311 return ""; 312 } else { 313 return $res; 314 } 315 } 316 317 318 /** 319 * Method used to get the list of priorities as an associative array in the 320 * style of (id => title) 321 * 322 * @access public 323 * @param integer $prj_id The project ID 324 * @return array The list of priorities 325 */ 326 function getAssocList($prj_id) 327 { 328 static $list; 329 330 if (count(@$list[$prj_id]) > 0) { 331 return $list[$prj_id]; 332 } 333 334 $stmt = "SELECT 335 pri_id, 336 pri_title 337 FROM 338 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 339 WHERE 340 pri_prj_id=" . Misc::escapeInteger($prj_id) . " 341 ORDER BY 342 pri_rank ASC"; 343 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 344 if (PEAR::isError($res)) { 345 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 346 return ""; 347 } else { 348 $list[$prj_id] = $res; 349 return $res; 350 } 351 } 352 353 /** 354 * Method used to get the pri_id of a project by priority title. 355 * 356 * @access public 357 * @param integer $prj_id The project ID 358 * @param integer $pri_id The priority ID 359 * @param string $pri_title The priority title 360 * @return integer $pri_id The priority ID 361 */ 362 function getPriorityID($prj_id, $pri_title) 363 { 364 $stmt = "SELECT 365 pri_id 366 FROM 367 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority 368 WHERE 369 pri_prj_id=" . Misc::escapeInteger($prj_id) . " 370 AND pri_title = '" . Misc::escapeString($pri_title) . "'"; 371 372 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 373 if (PEAR::isError($res)) { 374 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 375 return null; 376 } else { 377 return $res; 378 } 379 } 380 } 381 382 // benchmarking the included file (aka setup time) 383 if (APP_BENCHMARK) { 384 $GLOBALS['bench']->setMarker('Included Priority Class'); 385 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 19 21:21:33 2007 | Cross-referenced by PHPXref 0.7 |