[ 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.search_profile.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 34 35 class Search_Profile 36 { 37 /** 38 * Method used to remove the search profile record for this user, 39 * for the specified project and profile type. 40 * 41 * @access public 42 * @param integer $usr_id The user ID 43 * @param integer $prj_id The project ID 44 * @param string $type The type of the search profile ('issue' or 'email') 45 * @return boolean 46 */ 47 function remove($usr_id, $prj_id, $type) 48 { 49 $stmt = "DELETE FROM 50 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "search_profile 51 WHERE 52 sep_usr_id=" . Misc::escapeInteger($usr_id) . " AND 53 sep_prj_id=" . Misc::escapeInteger($prj_id) . " AND 54 sep_type='" . Misc::escapeString($type) . "'"; 55 $res = $GLOBALS["db_api"]->dbh->query($stmt); 56 if (PEAR::isError($res)) { 57 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 58 return false; 59 } else { 60 return true; 61 } 62 } 63 64 65 /** 66 * Method used to retrieve a search profile record for this user, 67 * for the specified project and profile type. 68 * 69 * @access public 70 * @param integer $usr_id The user ID 71 * @param integer $prj_id The project ID 72 * @param string $type The type of the search profile ('issue' or 'email') 73 * @return array The user's search profile 74 */ 75 function getProfile($usr_id, $prj_id, $type) 76 { 77 static $returns; 78 79 if (!empty($returns[$usr_id][$prj_id][$type])) { 80 return $returns[$usr_id][$prj_id][$type]; 81 } 82 83 $stmt = "SELECT 84 sep_user_profile 85 FROM 86 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "search_profile 87 WHERE 88 sep_usr_id=" . Misc::escapeInteger($usr_id) . " AND 89 sep_prj_id=" . Misc::escapeInteger($prj_id) . " AND 90 sep_type='" . Misc::escapeString($type) . "'"; 91 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 92 if (PEAR::isError($res)) { 93 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 94 return array(); 95 } else { 96 if (empty($res)) { 97 return array(); 98 } else { 99 $returns[$usr_id][$prj_id][$type] = unserialize($res); 100 return unserialize($res); 101 } 102 } 103 } 104 105 106 /** 107 * Method used to check whether a search profile already exists 108 * or not. 109 * 110 * @access private 111 * @param integer $usr_id The user ID 112 * @param integer $prj_id The project ID 113 * @param string $type The type of the search profile ('issue' or 'email') 114 * @return boolean 115 */ 116 function _exists($usr_id, $prj_id, $type) 117 { 118 $stmt = "SELECT 119 COUNT(*) AS total 120 FROM 121 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "search_profile 122 WHERE 123 sep_usr_id=" . Misc::escapeInteger($usr_id) . " AND 124 sep_prj_id=" . Misc::escapeInteger($prj_id) . " AND 125 sep_type='" . Misc::escapeString($type) . "'"; 126 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 127 if (PEAR::isError($res)) { 128 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 129 return false; 130 } else { 131 if ($res > 0) { 132 return true; 133 } else { 134 return false; 135 } 136 } 137 } 138 139 140 /** 141 * Method used to save a search profile record for this user, for 142 * the specified project, and profile type. 143 * 144 * @access public 145 * @param integer $usr_id The user ID 146 * @param integer $prj_id The project ID 147 * @param string $type The type of the search profile ('issue' or 'email') 148 * @param string $profile The search profile to be saved 149 * @return boolean 150 */ 151 function save($usr_id, $prj_id, $type, $profile) 152 { 153 if (!Search_Profile::_exists($usr_id, $prj_id, $type)) { 154 return Search_Profile::_insert($usr_id, $prj_id, $type, $profile); 155 } else { 156 return Search_Profile::_update($usr_id, $prj_id, $type, $profile); 157 } 158 } 159 160 161 /** 162 * Method used to create a new search profile record for this 163 * user, for the specified project, and profile type. 164 * 165 * @access private 166 * @param integer $usr_id The user ID 167 * @param integer $prj_id The project ID 168 * @param string $type The type of the search profile ('issue' or 'email') 169 * @param string $profile The search profile to be saved 170 * @return boolean 171 */ 172 function _insert($usr_id, $prj_id, $type, $profile) 173 { 174 $stmt = "INSERT INTO 175 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "search_profile 176 ( 177 sep_usr_id, 178 sep_prj_id, 179 sep_type, 180 sep_user_profile 181 ) VALUES ( 182 " . Misc::escapeInteger($usr_id) . ", 183 " . Misc::escapeInteger($prj_id) . ", 184 '" . Misc::escapeString($type) . "', 185 '" . Misc::escapeString(serialize($profile)) . "' 186 )"; 187 $res = $GLOBALS["db_api"]->dbh->query($stmt); 188 if (PEAR::isError($res)) { 189 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 190 return false; 191 } else { 192 return true; 193 } 194 } 195 196 197 /** 198 * Method used to update an existing search profile record for 199 * this user, for the specified project, and profile type. 200 * 201 * @access private 202 * @param integer $usr_id The user ID 203 * @param integer $prj_id The project ID 204 * @param string $type The type of the search profile ('issue' or 'email') 205 * @param string $profile The search profile to be saved 206 * @return boolean 207 */ 208 function _update($usr_id, $prj_id, $type, $profile) 209 { 210 $stmt = "UPDATE 211 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "search_profile 212 SET 213 sep_user_profile='" . Misc::escapeString(serialize($profile)) . "' 214 WHERE 215 sep_usr_id=" . Misc::escapeInteger($usr_id) . " AND 216 sep_prj_id=" . Misc::escapeInteger($prj_id) . " AND 217 sep_type='" . Misc::escapeString($type) . "'"; 218 $res = $GLOBALS["db_api"]->dbh->query($stmt); 219 if (PEAR::isError($res)) { 220 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 221 return false; 222 } else { 223 return true; 224 } 225 } 226 } 227 228 // benchmarking the included file (aka setup time) 229 if (APP_BENCHMARK) { 230 $GLOBALS['bench']->setMarker('Included Search_Profile Class'); 231 }
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 |