[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> excel_api.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Excel API
  19   *
  20   * @package CoreAPI
  21   * @subpackage ExcelAPI
  22   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  23   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  24   * @link http://www.mantisbt.org
  25   *
  26   * @uses authentication_api.php
  27   * @uses bug_api.php
  28   * @uses category_api.php
  29   * @uses columns_api.php
  30   * @uses config_api.php
  31   * @uses constant_inc.php
  32   * @uses custom_field_api.php
  33   * @uses helper_api.php
  34   * @uses lang_api.php
  35   * @uses project_api.php
  36   * @uses user_api.php
  37   */
  38  
  39  require_api( 'authentication_api.php' );
  40  require_api( 'bug_api.php' );
  41  require_api( 'category_api.php' );
  42  require_api( 'columns_api.php' );
  43  require_api( 'config_api.php' );
  44  require_api( 'constant_inc.php' );
  45  require_api( 'custom_field_api.php' );
  46  require_api( 'helper_api.php' );
  47  require_api( 'lang_api.php' );
  48  require_api( 'project_api.php' );
  49  require_api( 'user_api.php' );
  50  
  51  /**
  52   * A method that returns the header for an Excel Xml file.
  53   *
  54   * @param $p_worksheet_title  The worksheet title.
  55   * @returns the header Xml.
  56   */
  57  function excel_get_header( $p_worksheet_title ) {
  58      $p_worksheet_title = preg_replace( '/[\/:*?"<>|]/', '', $p_worksheet_title );
  59      return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?mso-application progid=\"Excel.Sheet\"?>
  60   <Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"
  61   xmlns:x=\"urn:schemas-microsoft-com:office:excel\"
  62   xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"
  63   xmlns:html=\"http://www.w3.org/TR/REC-html40\">\n<Worksheet ss:Name=\"" . urlencode( $p_worksheet_title ) . "\">\n<Table>\n<Column ss:Index=\"1\" ss:AutoFitWidth=\"0\" ss:Width=\"110\"/>\n";
  64  }
  65  
  66  /**
  67   * A method that returns the footer for an Excel Xml file.
  68   * @returns the footer xml.
  69   */
  70  function excel_get_footer() {
  71      return "</Table>\n</Worksheet></Workbook>\n";
  72  }
  73  
  74  /**
  75   * Generates a cell XML for a column title.
  76   * @returns The cell xml.
  77   */
  78  function excel_format_column_title( $p_column_title ) {
  79      return '<Cell><Data ss:Type="String">' . $p_column_title . '</Data></Cell>';
  80  }
  81  
  82  /**
  83   * Generates the xml for the start of an Excel row.
  84   * @returns The Row tag.
  85   */
  86  function excel_get_start_row() {
  87      return '<Row>';
  88  }
  89  
  90  /**
  91   * Generates the xml for the end of an Excel row.
  92   * @returns The Row end tag.
  93   */
  94  function excel_get_end_row() {
  95      return '</Row>';
  96  }
  97  
  98  /**
  99   * Gets an Xml Row that contains all column titles.
 100   * @returns The xml row.
 101   */
 102  function excel_get_titles_row() {
 103      $t_columns = excel_get_columns();
 104      $t_ret = '<Row>';
 105  
 106      foreach( $t_columns as $t_column ) {
 107          $t_custom_field = column_get_custom_field_name( $t_column );
 108          if( $t_custom_field !== null ) {
 109              $t_ret .= excel_format_column_title( lang_get_defaulted( $t_custom_field ) );
 110          } else {
 111              $t_column_title = column_get_title( $t_column );
 112              $t_ret .= excel_format_column_title( $t_column_title );
 113          }
 114      }
 115  
 116      $t_ret .= '</Row>';
 117  
 118      return $t_ret;
 119  }
 120  
 121  /**
 122   * Gets the download file name for the Excel export.  If 'All Projects' selected, default to <username>,
 123   * otherwise default to <projectname>.
 124  * @returns file name without extension
 125  */
 126  function excel_get_default_filename() {
 127      $t_current_project_id = helper_get_current_project();
 128  
 129      if( ALL_PROJECTS == $t_current_project_id ) {
 130          $t_filename = user_get_name( auth_get_current_user_id() );
 131      } else {
 132          $t_filename = project_get_field( $t_current_project_id, 'name' );
 133      }
 134  
 135      return $t_filename;
 136  }
 137  
 138  /**
 139   * Escapes the specified column value and includes it in a Cell Xml.
 140   * @param $p_value The value
 141   * @returns The Cell Xml.
 142   */
 143  function excel_prepare_string( $p_value ) {
 144      $t_type = is_numeric( $p_value ) ? 'Number' : 'String';
 145  
 146      $t_value = str_replace( array ( '&', "\n", '<', '>'), array ( '&amp;', '&#10;', '&lt;', '&gt;' ),  $p_value );
 147      $t_ret = "<Cell><Data ss:Type=\"$t_type\">" . $t_value . "</Data></Cell>\n";
 148  
 149      return $t_ret;
 150  }
 151  
 152  /**
 153   * Gets the columns to be included in the Excel Xml export.
 154   * @returns column names.
 155   */
 156  function excel_get_columns() {
 157      $t_columns = helper_get_columns_to_view( COLUMNS_TARGET_EXCEL_PAGE );
 158      return $t_columns;
 159  }
 160  
 161  #
 162  # Formatting Functions
 163  #
 164  # Names for formatting functions are excel_format_*, where * corresponds to the
 165  # field name as return get excel_get_columns() and by the filter api.
 166  #
 167  /**
 168   * Gets the formatted bug id value.
 169   * @param $p_bug_id  The bug id to be formatted.
 170   * @returns The bug id prefixed with 0s.
 171   */
 172  function excel_format_id( $p_bug_id ) {
 173      return excel_prepare_string( bug_format_id( $p_bug_id ) );
 174  }
 175  
 176  /**
 177   * Gets the formatted project id value.
 178   * @param $p_project_id The project id.
 179   * @returns The project name.
 180   */
 181  function excel_format_project_id( $p_project_id ) {
 182      return excel_prepare_string( project_get_name( $p_project_id ) );
 183  }
 184  
 185  /**
 186   * Gets the formatted reporter id value.
 187   * @param $p_reporter_id The reporter id.
 188   * @returns The reporter user name.
 189   */
 190  function excel_format_reporter_id( $p_reporter_id ) {
 191      return excel_prepare_string( user_get_name( $p_reporter_id ) );
 192  }
 193  
 194  /**
 195   * Gets the formatted number of bug notes.
 196   * @param $p_bugnotes_count  The number of bug notes.
 197   * @returns The number of bug notes.
 198   */
 199  function excel_format_bugnotes_count( $p_bugnotes_count ) {
 200      return excel_prepare_string( $p_bugnotes_count );
 201  }
 202  
 203  /**
 204   * Gets the formatted handler id.
 205   * @param $p_handler_id The handler id.
 206   * @returns The handler user name or empty string.
 207   */
 208  function excel_format_handler_id( $p_handler_id ) {
 209      if( $p_handler_id > 0 ) {
 210          return excel_prepare_string( user_get_name( $p_handler_id ) );
 211      } else {
 212          return excel_prepare_string( '' );
 213      }
 214  }
 215  
 216  /**
 217   * Gets the formatted priority.
 218   * @param $p_priority priority id.
 219   * @returns the priority text.
 220   */
 221  function excel_format_priority( $p_priority ) {
 222      return excel_prepare_string( get_enum_element( 'priority', $p_priority ) );
 223  }
 224  
 225  /**
 226   * Gets the formatted severity.
 227   * @param $p_severity severity id.
 228   * @returns the severity text.
 229   */
 230  function excel_format_severity( $p_severity ) {
 231      return excel_prepare_string( get_enum_element( 'severity', $p_severity ) );
 232  }
 233  
 234  /**
 235   * Gets the formatted reproducibility.
 236   * @param $p_reproducibility reproducibility id.
 237   * @returns the reproducibility text.
 238   */
 239  function excel_format_reproducibility( $p_reproducibility ) {
 240      return excel_prepare_string( get_enum_element( 'reproducibility', $p_reproducibility ) );
 241  }
 242  
 243  /**
 244   * Gets the formatted view state,
 245   * @param $p_view_state The view state (e.g. public vs. private)
 246   * @returns The view state
 247   */
 248  function excel_format_view_state( $p_view_state ) {
 249      return excel_prepare_string( get_enum_element( 'view_state', $p_view_state ) );
 250  }
 251  
 252  /**
 253   * Gets the formatted projection.
 254   * @param $p_projection projection id.
 255   * @returns the projection text.
 256   */
 257  function excel_format_projection( $p_projection ) {
 258      return excel_prepare_string( get_enum_element( 'projection', $p_projection ) );
 259  }
 260  
 261  /**
 262   * Gets the formatted eta.
 263   * @param $p_eta eta id.
 264   * @returns the eta text.
 265   */
 266  function excel_format_eta( $p_eta ) {
 267      return excel_prepare_string( get_enum_element( 'eta', $p_eta ) );
 268  }
 269  
 270  /**
 271   * Gets the status field.
 272   * @param $p_status The status field.
 273   * @returns the formatted status.
 274   */
 275  function excel_format_status( $p_status ) {
 276      return excel_prepare_string( get_enum_element( 'status', $p_status ) );
 277  }
 278  
 279  /**
 280   * Gets the resolution field.
 281   * @param $p_resolution The resolution field.
 282   * @returns the formatted resolution.
 283   */
 284  function excel_format_resolution( $p_resolution ) {
 285      return excel_prepare_string( get_enum_element( 'resolution', $p_resolution ) );
 286  }
 287  
 288  /**
 289   * Gets the formatted version.
 290   * @param $p_version The product version
 291   * @returns the product version.
 292   */
 293  function excel_format_version( $p_version ) {
 294      return excel_prepare_string( $p_version );
 295  }
 296  
 297  /**
 298   * Gets the formatted fixed in version.
 299   * @param $p_fixed_in_version The product fixed in version
 300   * @returns the fixed in version.
 301   */
 302  function excel_format_fixed_in_version( $p_fixed_in_version ) {
 303      return excel_prepare_string( $p_fixed_in_version );
 304  }
 305  
 306  /**
 307   * Gets the formatted target version.
 308   * @param $p_target_version The target version
 309   * @returns the target version.
 310   */
 311  function excel_format_target_version( $p_target_version ) {
 312      return excel_prepare_string( $p_target_version );
 313  }
 314  
 315  /**
 316   * Gets the formatted category.
 317   * @param $p_category The category
 318   * @returns the category.
 319   */
 320  function excel_format_category_id( $p_category_id ) {
 321      return excel_prepare_string( category_full_name( $p_category_id, false ) );
 322  }
 323  
 324  /**
 325   * Gets the formatted operating system.
 326   * @param $p_os The operating system
 327   * @returns the operating system.
 328   */
 329  function excel_format_os( $p_os ) {
 330      return excel_prepare_string( $p_os );
 331  }
 332  
 333  /**
 334   * Gets the formatted operating system build (version).
 335   * @param $p_os The operating system build (version)
 336   * @returns the operating system build (version)
 337   */
 338  function excel_format_os_build( $p_os_build ) {
 339      return excel_prepare_string( $p_os_build );
 340  }
 341  
 342  /**
 343   * Gets the formatted product build,
 344   * @param $p_build The product build
 345   * @returns the product build.
 346   */
 347  function excel_format_build( $p_build ) {
 348      return excel_prepare_string( $p_build );
 349  }
 350  
 351  /**
 352   * Gets the formatted platform,
 353   * @param $p_platform The platform
 354   * @returns the platform.
 355   */
 356  function excel_format_platform( $p_platform ) {
 357      return excel_prepare_string( $p_platform );
 358  }
 359  
 360  /**
 361   * Gets the formatted date submitted.
 362   * @param $p_date_submitted The date submitted
 363   * @returns the date submitted in short date format.
 364   */
 365  function excel_format_date_submitted( $p_date_submitted ) {
 366      return excel_prepare_string( date( config_get( 'short_date_format' ), $p_date_submitted ) );
 367  }
 368  
 369  /**
 370   * Gets the formatted date last updated.
 371   * @param $p_last_updated The date last updated.
 372   * @returns the date last updated in short date format.
 373   */
 374  function excel_format_last_updated( $p_last_updated ) {
 375      return excel_prepare_string( date( config_get( 'short_date_format' ), $p_last_updated ) );
 376  }
 377  
 378  /**
 379   * Gets the summary field.
 380   * @param $p_summary The summary.
 381   * @returns the formatted summary.
 382   */
 383  function excel_format_summary( $p_summary ) {
 384      return excel_prepare_string( $p_summary );
 385  }
 386  
 387  /**
 388   * Gets the formatted selection.
 389   * @param $p_selection The selection value
 390   * @returns An formatted empty string.
 391   */
 392  function excel_format_selection( $p_param ) {
 393      return excel_prepare_string( '' );
 394  }
 395  
 396  /**
 397   * Gets the formatted description field.
 398   * @param $p_description The description.
 399   * @returns The formatted description (multi-line).
 400   */
 401  function excel_format_description( $p_description ) {
 402      return excel_prepare_string( $p_description );
 403  }
 404  
 405  /**
 406   * Gets the formatted 'steps to reproduce' field.
 407   * @param $p_steps_to_reproduce The steps to reproduce.
 408   * @returns The formatted steps to reproduce (multi-line).
 409   */
 410  function excel_format_steps_to_reproduce( $p_steps_to_reproduce ) {
 411      return excel_prepare_string( $p_steps_to_reproduce );
 412  }
 413  
 414  /**
 415   * Gets the formatted 'additional information' field.
 416   * @param $p_additional_information The additional information field.
 417   * @returns The formatted additional information (multi-line).
 418   */
 419  function excel_format_additional_information( $p_additional_information ) {
 420      return excel_prepare_string( $p_additional_information );
 421  }
 422  
 423  /**
 424   * Gets the formatted value for the specified issue id, project and custom field.
 425   * @param $p_issue_id The issue id.
 426   * @param $p_project_id The project id.
 427   * @param $p_custom_field The custom field name (without 'custom_' prefix).
 428   * @returns The custom field value.
 429   */
 430  function excel_format_custom_field( $p_issue_id, $p_project_id, $p_custom_field ) {
 431      $t_field_id = custom_field_get_id_from_name( $p_custom_field );
 432  
 433      if( $t_field_id === false ) {
 434          return excel_prepare_string( '@' . $p_custom_field . '@' );
 435      }
 436  
 437      if( custom_field_is_linked( $t_field_id, $p_project_id ) ) {
 438          $t_def = custom_field_get_definition( $t_field_id );
 439          return excel_prepare_string( string_custom_field_value( $t_def, $t_field_id, $p_issue_id ) );
 440      }
 441  
 442      // field is not linked to project
 443      return excel_prepare_string( '' );
 444  }
 445  
 446  /**
 447   * Gets the formatted due date.
 448   * @param $p_due_date The due date.
 449   * @returns The formatted due date.
 450   */
 451  function excel_format_due_date( $p_due_date ) {
 452      return excel_prepare_string( date( config_get( 'short_date_format' ), $p_due_date ) );
 453  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7