[ 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.news.php 3246 2007-02-09 09:10:12Z glen $ 29 // 30 31 32 class News 33 { 34 /** 35 * Method used to get the list of news entries available in the 36 * system for a given project. 37 * 38 * @access public 39 * @param integer $prj_id The project ID 40 * @return array The list of news entries 41 */ 42 function getListByProject($prj_id, $show_full_message = FALSE) 43 { 44 $stmt = "SELECT 45 * 46 FROM 47 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news, 48 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_news 49 WHERE 50 prn_nws_id=nws_id AND 51 prn_prj_id=" . Misc::escapeInteger($prj_id) . " AND 52 nws_status='active' 53 ORDER BY 54 nws_created_date DESC 55 LIMIT 56 0, 3"; 57 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 58 if (PEAR::isError($res)) { 59 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 60 return ""; 61 } else { 62 for ($i = 0; $i < count($res); $i++) { 63 $res[$i]['nws_created_date'] = Date_API::getSimpleDate($res[$i]["nws_created_date"]); 64 if ((!$show_full_message) && (strlen($res[$i]['nws_message']) > 300)) { 65 $next_space = strpos($res[$i]['nws_message'], ' ', 254); 66 if (empty($next_space)) { 67 $next_space = strpos($res[$i]['nws_message'], "\n", 254); 68 } 69 if (($next_space > 0) && (($next_space - 255) < 50)) { 70 $cut = $next_space; 71 } else { 72 $cut = 255; 73 } 74 $res[$i]['nws_message'] = substr($res[$i]['nws_message'], 0, $cut) . '...'; 75 } 76 $res[$i]['nws_message'] = nl2br(htmlspecialchars($res[$i]['nws_message'])); 77 } 78 return $res; 79 } 80 } 81 82 83 /** 84 * Method used to add a project association to a news entry. 85 * 86 * @access public 87 * @param integer $nws_id The news ID 88 * @param integer $prj_id The project ID 89 * @return void 90 */ 91 function addProjectAssociation($nws_id, $prj_id) 92 { 93 $stmt = "INSERT INTO 94 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_news 95 ( 96 prn_nws_id, 97 prn_prj_id 98 ) VALUES ( 99 " . Misc::escapeInteger($nws_id) . ", 100 " . Misc::escapeInteger($prj_id) . " 101 )"; 102 $GLOBALS["db_api"]->dbh->query($stmt); 103 } 104 105 106 /** 107 * Method used to add a news entry to the system. 108 * 109 * @access public 110 * @return integer 1 if the insert worked, -1 otherwise 111 */ 112 function insert() 113 { 114 if (Validation::isWhitespace($_POST["title"])) { 115 return -2; 116 } 117 if (Validation::isWhitespace($_POST["message"])) { 118 return -3; 119 } 120 $stmt = "INSERT INTO 121 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 122 ( 123 nws_usr_id, 124 nws_created_date, 125 nws_title, 126 nws_message, 127 nws_status 128 ) VALUES ( 129 " . Auth::getUserID() . ", 130 '" . Date_API::getCurrentDateGMT() . "', 131 '" . Misc::escapeString($_POST["title"]) . "', 132 '" . Misc::escapeString($_POST["message"]) . "', 133 '" . Misc::escapeString($_POST["status"]) . "' 134 )"; 135 $res = $GLOBALS["db_api"]->dbh->query($stmt); 136 if (PEAR::isError($res)) { 137 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 138 return -1; 139 } else { 140 $new_news_id = $GLOBALS["db_api"]->get_last_insert_id(); 141 // now populate the project-news mapping table 142 foreach ($_POST['projects'] as $prj_id) { 143 News::addProjectAssociation($new_news_id, $prj_id); 144 } 145 return 1; 146 } 147 } 148 149 150 /** 151 * Method used to remove a news entry from the system. 152 * 153 * @access public 154 * @return boolean 155 */ 156 function remove() 157 { 158 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 159 $stmt = "DELETE FROM 160 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 161 WHERE 162 nws_id IN ($items)"; 163 $res = $GLOBALS["db_api"]->dbh->query($stmt); 164 if (PEAR::isError($res)) { 165 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 166 return false; 167 } else { 168 News::removeProjectAssociations($_POST['items']); 169 return true; 170 } 171 } 172 173 174 /** 175 * Method used to remove the project associations for a given 176 * news entry. 177 * 178 * @access public 179 * @param integer $nws_id The news ID 180 * @param integer $prj_id The project ID 181 * @return boolean 182 */ 183 function removeProjectAssociations($nws_id, $prj_id=FALSE) 184 { 185 if (!is_array($nws_id)) { 186 $nws_id = array($nws_id); 187 } 188 $items = @implode(", ", Misc::escapeInteger($nws_id)); 189 $stmt = "DELETE FROM 190 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_news 191 WHERE 192 prn_nws_id IN ($items)"; 193 if ($prj_id) { 194 $stmt .= " AND prn_prj_id=" . Misc::escapeInteger($prj_id); 195 } 196 $res = $GLOBALS["db_api"]->dbh->query($stmt); 197 if (PEAR::isError($res)) { 198 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 199 return false; 200 } else { 201 return true; 202 } 203 } 204 205 206 /** 207 * Method used to update a news entry in the system. 208 * 209 * @access public 210 * @return integer 1 if the update worked, -1 otherwise 211 */ 212 function update() 213 { 214 if (Validation::isWhitespace($_POST["title"])) { 215 return -2; 216 } 217 if (Validation::isWhitespace($_POST["message"])) { 218 return -3; 219 } 220 $stmt = "UPDATE 221 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 222 SET 223 nws_title='" . Misc::escapeString($_POST["title"]) . "', 224 nws_message='" . Misc::escapeString($_POST["message"]) . "', 225 nws_status='" . Misc::escapeString($_POST["status"]) . "' 226 WHERE 227 nws_id=" . Misc::escapeInteger($_POST["id"]); 228 $res = $GLOBALS["db_api"]->dbh->query($stmt); 229 if (PEAR::isError($res)) { 230 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 231 return -1; 232 } else { 233 // remove all of the associations with projects, then add them all again 234 News::removeProjectAssociations($_POST['id']); 235 foreach ($_POST['projects'] as $prj_id) { 236 News::addProjectAssociation($_POST['id'], $prj_id); 237 } 238 return 1; 239 } 240 } 241 242 243 /** 244 * Method used to get the details of a news entry for a given news ID. 245 * 246 * @access public 247 * @param integer $nws_id The news entry ID 248 * @return array The news entry details 249 */ 250 function getDetails($nws_id) 251 { 252 $stmt = "SELECT 253 * 254 FROM 255 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 256 WHERE 257 nws_id=" . Misc::escapeInteger($nws_id); 258 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 259 if (PEAR::isError($res)) { 260 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 261 return ""; 262 } else { 263 // get all of the project associations here as well 264 $res['projects'] = array_keys(News::getAssociatedProjects($res['nws_id'])); 265 $res['nws_message'] = nl2br(htmlspecialchars($res['nws_message'])); 266 return $res; 267 } 268 } 269 270 271 /** 272 * Method used to get the details of a news entry for a given news ID. 273 * 274 * @access public 275 * @param integer $nws_id The news entry ID 276 * @return array The news entry details 277 */ 278 function getAdminDetails($nws_id) 279 { 280 $stmt = "SELECT 281 * 282 FROM 283 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 284 WHERE 285 nws_id=" . Misc::escapeInteger($nws_id); 286 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 287 if (PEAR::isError($res)) { 288 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 289 return ""; 290 } else { 291 // get all of the project associations here as well 292 $res['projects'] = array_keys(News::getAssociatedProjects($res['nws_id'])); 293 return $res; 294 } 295 } 296 297 298 /** 299 * Method used to get the list of news entries available in the system. 300 * 301 * @access public 302 * @return array The list of news entries 303 */ 304 function getList() 305 { 306 $stmt = "SELECT 307 nws_id, 308 nws_title, 309 nws_status 310 FROM 311 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "news 312 ORDER BY 313 nws_title ASC"; 314 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 315 if (PEAR::isError($res)) { 316 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 317 return ""; 318 } else { 319 // get the list of associated projects 320 for ($i = 0; $i < count($res); $i++) { 321 $res[$i]['projects'] = implode(", ", array_values(News::getAssociatedProjects($res[$i]['nws_id']))); 322 } 323 return $res; 324 } 325 } 326 327 328 /** 329 * Method used to get the list of associated projects for a given 330 * news entry. 331 * 332 * @access public 333 * @param integer $nws_id The news ID 334 * @return array The list of projects 335 */ 336 function getAssociatedProjects($nws_id) 337 { 338 $stmt = "SELECT 339 prj_id, 340 prj_title 341 FROM 342 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project, 343 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_news 344 WHERE 345 prj_id=prn_prj_id AND 346 prn_nws_id=" . Misc::escapeInteger($nws_id); 347 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 348 if (PEAR::isError($res)) { 349 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 350 return array(); 351 } else { 352 return $res; 353 } 354 } 355 } 356 357 // benchmarking the included file (aka setup time) 358 if (APP_BENCHMARK) { 359 $GLOBALS['bench']->setMarker('Included News Class'); 360 }
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 |