[ 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.category.php 3246 2007-02-09 09:10:12Z 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 category related issues. 37 * 38 * @version 1.0 39 * @author João Prado Maia <jpm@mysql.com> 40 */ 41 42 class Category 43 { 44 /** 45 * Method used to get the full details of a category. 46 * 47 * @access public 48 * @param integer $prc_id The category ID 49 * @return array The information about the category provided 50 */ 51 function getDetails($prc_id) 52 { 53 $stmt = "SELECT 54 * 55 FROM 56 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 57 WHERE 58 prc_id=" . Misc::escapeInteger($prc_id); 59 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 60 if (PEAR::isError($res)) { 61 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 62 return ""; 63 } else { 64 return $res; 65 } 66 } 67 68 69 /** 70 * Method used to remove all categories related to a set of 71 * specific projects. 72 * 73 * @access public 74 * @param array $ids The project IDs to be removed 75 * @return boolean Whether the removal worked or not 76 */ 77 function removeByProjects($ids) 78 { 79 $items = @implode(", ", Misc::escapeInteger($ids)); 80 $stmt = "DELETE FROM 81 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 82 WHERE 83 prc_prj_id IN ($items)"; 84 $res = $GLOBALS["db_api"]->dbh->query($stmt); 85 if (PEAR::isError($res)) { 86 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 87 return false; 88 } else { 89 return true; 90 } 91 } 92 93 94 /** 95 * Method used to remove user-selected categories from the 96 * database. 97 * 98 * @access public 99 * @return boolean Whether the removal worked or not 100 */ 101 function remove() 102 { 103 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 104 $stmt = "DELETE FROM 105 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 106 WHERE 107 prc_id IN ($items)"; 108 $res = $GLOBALS["db_api"]->dbh->query($stmt); 109 if (PEAR::isError($res)) { 110 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 111 return false; 112 } else { 113 return true; 114 } 115 } 116 117 118 /** 119 * Method used to update the values stored in the database. 120 * Typically the user would modify the title of the category in 121 * the application and this method would be called. 122 * 123 * @access public 124 * @return integer 1 if the update worked properly, any other value otherwise 125 */ 126 function update() 127 { 128 if (Validation::isWhitespace($_POST["title"])) { 129 return -2; 130 } 131 $stmt = "UPDATE 132 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 133 SET 134 prc_title='" . Misc::escapeString($_POST["title"]) . "' 135 WHERE 136 prc_prj_id=" . Misc::escapeInteger($_POST["prj_id"]) . " AND 137 prc_id=" . Misc::escapeInteger($_POST["id"]); 138 $res = $GLOBALS["db_api"]->dbh->query($stmt); 139 if (PEAR::isError($res)) { 140 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 141 return -1; 142 } else { 143 return 1; 144 } 145 } 146 147 148 /** 149 * Method used to add a new category to the application. 150 * 151 * @access public 152 * @return integer 1 if the update worked properly, any other value otherwise 153 */ 154 function insert() 155 { 156 if (Validation::isWhitespace($_POST["title"])) { 157 return -2; 158 } 159 $stmt = "INSERT INTO 160 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 161 ( 162 prc_prj_id, 163 prc_title 164 ) VALUES ( 165 " . Misc::escapeInteger($_POST["prj_id"]) . ", 166 '" . Misc::escapeString($_POST["title"]) . "' 167 )"; 168 $res = $GLOBALS["db_api"]->dbh->query($stmt); 169 if (PEAR::isError($res)) { 170 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 171 return -1; 172 } else { 173 return 1; 174 } 175 } 176 177 178 /** 179 * Method used to get the full list of categories associated with 180 * a specific project. 181 * 182 * @access public 183 * @param integer $prj_id The project ID 184 * @return array The full list of categories 185 */ 186 function getList($prj_id) 187 { 188 $stmt = "SELECT 189 prc_id, 190 prc_title 191 FROM 192 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 193 WHERE 194 prc_prj_id=" . Misc::escapeInteger($prj_id) . " 195 ORDER BY 196 prc_title ASC"; 197 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 198 if (PEAR::isError($res)) { 199 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 200 return ""; 201 } else { 202 return $res; 203 } 204 } 205 206 207 /** 208 * Method used to get an associative array of the list of 209 * categories associated with a specific project. 210 * 211 * @access public 212 * @param integer $prj_id The project ID 213 * @return array The associative array of categories 214 */ 215 function getAssocList($prj_id) 216 { 217 static $list; 218 219 if (!empty($list[$prj_id])) { 220 return $list[$prj_id]; 221 } 222 223 $stmt = "SELECT 224 prc_id, 225 prc_title 226 FROM 227 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 228 WHERE 229 prc_prj_id=" . Misc::escapeInteger($prj_id) . " 230 ORDER BY 231 prc_title ASC"; 232 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 233 if (PEAR::isError($res)) { 234 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 235 return ""; 236 } else { 237 $list[$prj_id] = $res; 238 return $res; 239 } 240 } 241 242 243 /** 244 * Method used to get the title for a specific project category. 245 * 246 * @access public 247 * @param integer $prc_id The category ID 248 * @return string The category title 249 */ 250 function getTitle($prc_id) 251 { 252 $stmt = "SELECT 253 prc_title 254 FROM 255 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category 256 WHERE 257 prc_id=" . Misc::escapeInteger($prc_id); 258 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 259 if (PEAR::isError($res)) { 260 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 261 return ""; 262 } else { 263 return $res; 264 } 265 } 266 } 267 268 // benchmarking the included file (aka setup time) 269 if (APP_BENCHMARK) { 270 $GLOBALS['bench']->setMarker('Included Category Class'); 271 }
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 |