[ 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: Bryan Alsdorf <bryan@mysql.com> | 26 // +----------------------------------------------------------------------+ 27 // 28 // 29 30 31 /** 32 * Class to handle determining which columns should be displayed and in what order 33 * on a page (e.g. Issue Listing page). 34 * 35 * @author Bryan Alsdorf <bryan@mysql.com> 36 * @version 1.0 37 */ 38 39 class Display_Column 40 { 41 /** 42 * Returns the columns that should be displayed for the specified page. 43 * This method will remove columns that should not be displayed, due to 44 * lack of customer integration or insufficient role. 45 * 46 * @access public 47 * @param integer $prj_id The ID of the project. 48 * @param string $page The page to return columns for. 49 * @return array An array of columns that should be displayed. 50 */ 51 function getColumnsToDisplay($prj_id, $page) 52 { 53 static $returns; 54 55 // poor man's caching system 56 if (!empty($returns[$prj_id][$page])) { 57 return $returns[$prj_id][$page]; 58 } 59 60 $current_role = Auth::getCurrentRole(); 61 $data = Display_Column::getSelectedColumns($prj_id, $page); 62 $has_customer_integration = Customer::hasCustomerIntegration($prj_id); 63 $only_with_customers = array('iss_customer_id', 'support_level'); 64 65 // remove groups if there are no groups in the system. 66 if (count(Group::getAssocList($prj_id)) < 1) { 67 unset($data['iss_grp_id']); 68 } 69 // remove category column if there are no categories in the system 70 if (count(Category::getAssocList($prj_id)) < 1) { 71 unset($data['prc_title']); 72 } 73 // remove custom fields column if there are no custom fields 74 if (count(Custom_Field::getFieldsToBeListed($prj_id)) < 1) { 75 unset($data['custom_fields']); 76 } 77 // remove customer field if user has a role of customer 78 if ($current_role == User::getRoleID("Customer")) { 79 unset($data['iss_customer_id']); 80 } 81 82 foreach ($data as $field => $info) { 83 // remove fields based on role 84 if ($info['min_role'] > $current_role) { 85 unset($data[$field]); 86 continue; 87 } 88 // remove fields based on customer integration 89 if (!$has_customer_integration && (in_array($field, $only_with_customers))) { 90 unset($data[$field]); 91 continue; 92 } 93 // get title 94 $data[$field] = Display_Column::getColumnInfo($page, $field); 95 } 96 $returns[$prj_id][$page] = $data; 97 return $data; 98 } 99 100 101 /** 102 * Returns the columns that have been selected to be displayed on the specified page. This list 103 * contains all selected columns, even if they won't actually be displayed. 104 * 105 * @access public 106 * @param integer $prj_id The ID of the project. 107 * @param string $page The page to return columns for. 108 * @return array An array of columns that should be displayed. 109 */ 110 function getSelectedColumns($prj_id, $page) 111 { 112 static $returns; 113 114 // poor man's caching system 115 if (!empty($returns[$prj_id][$page])) { 116 return $returns[$prj_id][$page]; 117 } 118 119 $stmt = "SELECT 120 ctd_field, 121 ctd_min_role, 122 ctd_rank 123 FROM 124 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "columns_to_display 125 WHERE 126 ctd_prj_id = $prj_id AND 127 ctd_page = '$page' 128 ORDER BY 129 ctd_rank"; 130 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt, false, array(), DB_FETCHMODE_ASSOC); 131 if (PEAR::isError($res)) { 132 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 133 return array(); 134 } else { 135 $returns[$prj_id][$page] = array(); 136 foreach ($res as $field_name => $row) { 137 $returns[$prj_id][$page][$field_name] = Display_Column::getColumnInfo($page, $field_name); 138 $returns[$prj_id][$page][$field_name]['min_role'] = $row['ctd_min_role']; 139 $returns[$prj_id][$page][$field_name]['rank'] = $row['ctd_rank']; 140 } 141 return $returns[$prj_id][$page]; 142 } 143 } 144 145 146 /** 147 * Returns the info of the column 148 * 149 * @access public 150 * @param string $page The name of the page. 151 * @param string $column The name of the column 152 * @return string Info on the column 153 */ 154 function getColumnInfo($page, $column) 155 { 156 $columns = Display_Column::getAllColumns($page); 157 return $columns[$column]; 158 } 159 160 161 /** 162 * Returns all columns available for a page 163 * 164 * @access public 165 * @param string $page The name of the page 166 * @return array An array of columns 167 */ 168 function getAllColumns($page) 169 { 170 $columns = array( 171 "list_issues" => array( 172 "pri_rank" => array( 173 "title" => ev_gettext("Priority") 174 ), 175 "iss_id" => array( 176 "title" => ev_gettext("Issue ID") 177 ), 178 "usr_full_name" => array( 179 "title" => ev_gettext("Reporter") 180 ), 181 "iss_grp_id" => array( 182 "title" => ev_gettext("Group") 183 ), 184 "assigned" => array( 185 "title" => ev_gettext("Assigned") 186 ), 187 "time_spent" => array( 188 "title" => ev_gettext("Time Spent") 189 ), 190 "iss_percent_complete" => array( 191 "title" => ev_gettext("% Complete"), 192 "default_role" => 9 193 ), 194 "iss_dev_time" => array( 195 "title" => ev_gettext("Est Dev Time"), 196 "default_role" => 9 197 ), 198 "prc_title" => array( 199 "title" => ev_gettext("Category") 200 ), 201 "pre_title" => array( 202 "title" => ev_gettext("Release") 203 ), 204 "iss_customer_id" => array( 205 "title" => ev_gettext("Customer") 206 ), 207 "support_level" => array( 208 "title" => ev_gettext("Support Level") 209 ), 210 "sta_rank" => array( 211 "title" => ev_gettext("Status") 212 ), 213 "sta_change_date" => array( 214 "title" => ev_gettext("Status Change Date") 215 ), 216 "last_action_date" => array( 217 "title" => ev_gettext("Last Action Date") 218 ), 219 "custom_fields" => array( 220 "title" => ev_gettext("Custom Fields") 221 ), 222 "iss_summary" => array( 223 "title" => ev_gettext("Summary"), 224 "align" => "left", 225 "width" => '30%' 226 ), 227 "iss_expected_resolution_date" => array( 228 "title" => ev_gettext("Expected Resolution Date") 229 ) 230 ) 231 ); 232 return $columns[$page]; 233 } 234 235 236 /** 237 * Saves settings on which columns should be displayed. 238 * 239 * @access public 240 * @return integer 1 if settings were saved successfully, -1 if there was an error. 241 */ 242 function save() 243 { 244 $page = Misc::escapeString($_REQUEST['page']); 245 $prj_id = Misc::escapeInteger($_REQUEST['prj_id']); 246 247 $ranks = $_REQUEST['rank']; 248 asort($ranks); 249 250 // delete current entries 251 $stmt = "DELETE FROM 252 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "columns_to_display 253 WHERE 254 ctd_prj_id = $prj_id AND 255 ctd_page = '$page'"; 256 $res = $GLOBALS["db_api"]->dbh->query($stmt); 257 if (PEAR::isError($res)) { 258 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 259 return -1; 260 } 261 $rank = 1; 262 foreach ($ranks as $field_name => $requested_rank) { 263 $sql = "INSERT INTO 264 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "columns_to_display 265 SET 266 ctd_prj_id = $prj_id, 267 ctd_page = '$page', 268 ctd_field = '$field_name', 269 ctd_min_role = " . $_REQUEST['min_role'][$field_name] . ", 270 ctd_rank = $rank"; 271 $res = $GLOBALS["db_api"]->dbh->query($sql); 272 if (PEAR::isError($res)) { 273 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 274 return -1; 275 } 276 $rank++; 277 } 278 return 1; 279 } 280 281 282 /** 283 * Adds records in database for new project. 284 * 285 * @param integer $prj_id The ID of the project. 286 */ 287 function setupNewProject($prj_id) 288 { 289 $page = 'list_issues'; 290 $columns = Display_Column::getAllColumns($page); 291 $rank = 1; 292 foreach ($columns as $field_name => $column) { 293 if (!empty($column['default_role'])) { 294 $min_role = $column['default_role']; 295 } else { 296 $min_role = 1; 297 } 298 $stmt = "INSERT INTO 299 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "columns_to_display 300 SET 301 ctd_prj_id = $prj_id, 302 ctd_page = '$page', 303 ctd_field = '$field_name', 304 ctd_min_role = $min_role, 305 ctd_rank = $rank"; 306 $res = $GLOBALS["db_api"]->dbh->query($stmt); 307 if (PEAR::isError($res)) { 308 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 309 return -1; 310 } 311 $rank++; 312 } 313 } 314 } 315 316 // benchmarking the included file (aka setup time) 317 if (APP_BENCHMARK) { 318 $GLOBALS['bench']->setMarker('Included Display_Column Class'); 319 }
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 |