[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> csv_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   * CSV API
  19   *
  20   * @package CoreAPI
  21   * @subpackage CSVAPI
  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 config_api.php
  30   * @uses constant_inc.php
  31   * @uses helper_api.php
  32   * @uses project_api.php
  33   * @uses user_api.php
  34   */
  35  
  36  require_api( 'authentication_api.php' );
  37  require_api( 'bug_api.php' );
  38  require_api( 'category_api.php' );
  39  require_api( 'config_api.php' );
  40  require_api( 'constant_inc.php' );
  41  require_api( 'helper_api.php' );
  42  require_api( 'project_api.php' );
  43  require_api( 'user_api.php' );
  44  
  45  /**
  46   * get the csv file new line, can be moved to config in the future
  47   * @return string containing new line character
  48   * @access public
  49   */
  50  function csv_get_newline() {
  51      return "\r\n";
  52  }
  53  
  54  /**
  55   * get the csv file separator, can be moved to config in the future
  56   * @return string
  57   * @access public
  58   */
  59  function csv_get_separator() {
  60      static $s_seperator = null;
  61      if ( $s_seperator === null )
  62          $s_seperator = config_get( 'csv_separator' );
  63      return $s_seperator;
  64  }
  65  
  66  /**
  67   * if all projects selected, default to <username>.csv, otherwise default to
  68   * <projectname>.csv.
  69   * @return string filename
  70   * @access public
  71   */
  72  function csv_get_default_filename() {
  73      $t_current_project_id = helper_get_current_project();
  74  
  75      if( ALL_PROJECTS == $t_current_project_id ) {
  76          $t_filename = user_get_name( auth_get_current_user_id() );
  77      } else {
  78          $t_filename = project_get_field( $t_current_project_id, 'name' );
  79      }
  80  
  81      return $t_filename . '.csv';
  82  }
  83  
  84  /**
  85   * escape a string before writing it to csv file.
  86   * @param type $todo TODO
  87   * @return  TODO
  88   * @access public
  89   */
  90  function csv_escape_string( $p_str ) {
  91          $t_escaped = str_split( '"' . csv_get_separator() . csv_get_newline() );
  92          $t_must_escape = false;
  93          while( ( $t_char = current( $t_escaped ) ) !== false && !$t_must_escape ) {
  94              $t_must_escape = strpos( $p_str, $t_char ) !== false;
  95              next( $t_escaped );
  96          }
  97          if ( $t_must_escape ) {
  98              $p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
  99          }
 100  
 101          return $p_str;
 102  }
 103  
 104  /**
 105   * An array of column names that are used to identify  fields to include and in which order.
 106   * @param type $todo TODO
 107   * @return  TODO
 108   * @access public
 109   */
 110  function csv_get_columns() {
 111      $t_columns = helper_get_columns_to_view( COLUMNS_TARGET_CSV_PAGE );
 112      return $t_columns;
 113  }
 114  
 115  /**
 116   * format bug id
 117   * @param int $p_bug_id bug id
 118   * @return string csv formatted bug
 119   * @access public
 120   */
 121  function csv_format_id( $p_bug_id ) {
 122      return bug_format_id( $p_bug_id );
 123  }
 124  
 125  /**
 126   * returns the project name corresponding to the supplied project id.
 127   * @param int $p_project_id project id
 128   * @return string csv formatted project name
 129   * @access public
 130   */
 131  function csv_format_project_id( $p_project_id ) {
 132      return csv_escape_string( project_get_name( $p_project_id ) );
 133  }
 134  
 135  /**
 136   * returns the reporter name corresponding to the supplied id.
 137   * @param int $p_reporter_id user id
 138   * @return string formatted user name
 139   * @access public
 140   */
 141  function csv_format_reporter_id( $p_reporter_id ) {
 142      return csv_escape_string( user_get_name( $p_reporter_id ) );
 143  }
 144  
 145  /**
 146   * returns the handler name corresponding to the supplied id
 147   * @param int $p_handler_id user id
 148   * @return string formatted user name
 149   * @access public
 150   */
 151  function csv_format_handler_id( $p_handler_id ) {
 152      if( $p_handler_id > 0 ) {
 153          return csv_escape_string( user_get_name( $p_handler_id ) );
 154      }
 155  }
 156  
 157  /**
 158   * return the priority string
 159   * @param int $p_priority
 160   * @return string formatted priority string
 161   * @access public
 162   */
 163  function csv_format_priority( $p_priority ) {
 164      return csv_escape_string( get_enum_element( 'priority', $p_priority ) );
 165  }
 166  
 167  /**
 168   * return the severity string
 169   * @param int $p_severity
 170   * @return string formatted severity string
 171   * @access public
 172   */
 173  function csv_format_severity( $p_severity ) {
 174      return csv_escape_string( get_enum_element( 'severity', $p_severity ) );
 175  }
 176  
 177  /**
 178   * return the reproducability string
 179   * @param int $p_reproducibility
 180   * @return string formatted reproducibility string
 181   * @access public
 182   */
 183  function csv_format_reproducibility( $p_reproducibility ) {
 184      return csv_escape_string( get_enum_element( 'reproducibility', $p_reproducibility ) );
 185  }
 186  
 187  /**
 188   * return the version
 189   * @param string $p_version version string
 190   * @return string formatted version string
 191   * @access public
 192   */
 193  function csv_format_version( $p_version ) {
 194      return csv_escape_string( $p_version );
 195  }
 196  
 197  /**
 198   * return the fixed_in_version
 199   * @param string $p_fixed_in_version fixed in version string
 200   * @return string formatted fixed in version string
 201   * @access public
 202   */
 203  function csv_format_fixed_in_version( $p_fixed_in_version ) {
 204      return csv_escape_string( $p_fixed_in_version );
 205  }
 206  
 207  /**
 208   * return the target_version
 209   * @param string $p_target_version target version string
 210   * @return string formatted target version string
 211   * @access public
 212   */
 213  function csv_format_target_version( $p_target_version ) {
 214      return csv_escape_string( $p_target_version );
 215  }
 216  
 217  /**
 218   * return the projection
 219   * @param int $p_projection
 220   * @return string formatted projection string
 221   * @access public
 222   */
 223  function csv_format_projection( $p_projection ) {
 224      return csv_escape_string( get_enum_element( 'projection', $p_projection ) );
 225  }
 226  
 227  /**
 228   * return the category
 229   * @param int $p_category_id
 230   * @return string formatted category string
 231   * @access public
 232   */
 233  function csv_format_category_id( $p_category_id ) {
 234      return csv_escape_string( category_full_name( $p_category_id, false ) );
 235  }
 236  
 237  /**
 238   * return the date submitted
 239   * @param string $p_date_submitted
 240   * @return string formatted date
 241   * @access public
 242   */
 243  function csv_format_date_submitted( $p_date_submitted ) {
 244      static $s_date_format = null;
 245      if ( $s_date_format === null )
 246          $s_date_format = config_get( 'short_date_format' );
 247      return date( $s_date_format, $p_date_submitted );
 248  }
 249  
 250  /**
 251   * return the eta
 252   * @param int $p_eta eta
 253   * @return string formatted eta
 254   * @access public
 255   */
 256  function csv_format_eta( $p_eta ) {
 257      return csv_escape_string( get_enum_element( 'eta', $p_eta ) );
 258  }
 259  
 260  /**
 261   * return the operating system
 262   * @param string $p_os operating system
 263   * @return string formatted operating system
 264   * @access public
 265   */
 266  function csv_format_os( $p_os ) {
 267      return csv_escape_string( $p_os );
 268  }
 269  
 270  /**
 271   * return the os build (os version)
 272   * @param string $p_os_build operating system build
 273   * @return string formatted operating system build
 274   * @access public
 275   */
 276  function csv_format_os_build( $p_os_build ) {
 277      return csv_escape_string( $p_os_build );
 278  }
 279  
 280  /**
 281   * return the build
 282   * @param string $p_build
 283   * @return string formatted build
 284   * @access public
 285   */
 286  function csv_format_build( $p_build ) {
 287      return csv_escape_string( $p_build );
 288  }
 289  
 290  /**
 291   * return the platform
 292   * @param string $p_platform platform
 293   * @return string formatted platform
 294   * @access public
 295   */
 296  function csv_format_platform( $p_platform ) {
 297      return csv_escape_string( $p_platform );
 298  }
 299  
 300  /**
 301   * return the view state (eg: private / public)
 302   * @param int $p_view_state view state
 303   * @return string formatted view state
 304   * @access public
 305   */
 306  function csv_format_view_state( $p_view_state ) {
 307      return csv_escape_string( get_enum_element( 'view_state', $p_view_state ) );
 308  }
 309  
 310  /**
 311   * return the last updated date
 312   * @param string $p_last_updated last updated
 313   * @return string formated last updated string
 314   * @access public
 315   */
 316  function csv_format_last_updated( $p_last_updated ) {
 317      static $s_date_format = null;
 318      if ( $s_date_format === null )
 319          $s_date_format = config_get( 'short_date_format' );
 320      return date( $s_date_format, $p_last_updated );
 321  }
 322  
 323  /**
 324   * return the summary
 325   * @param string $p_summary summary
 326   * @return string formatted summary
 327   * @access public
 328   */
 329  function csv_format_summary( $p_summary ) {
 330      return csv_escape_string( $p_summary );
 331  }
 332  
 333  /**
 334   * return the description
 335   * @param string $p_description description
 336   * @return string formatted description
 337   * @access public
 338   */
 339  function csv_format_description( $p_description ) {
 340      return csv_escape_string( $p_description );
 341  }
 342  
 343  /**
 344   * return the steps to reproduce
 345   * @param string $p_steps_to_reproduce steps to reproduce
 346   * @return string formatted steps to reproduce
 347   * @access public
 348   */
 349  function csv_format_steps_to_reproduce( $p_steps_to_reproduce ) {
 350      return csv_escape_string( $p_steps_to_reproduce );
 351  }
 352  
 353  /**
 354   * return the additional information
 355   * @param string $p_additional_information
 356   * @return string formatted additional information
 357   * @access public
 358   */
 359  function csv_format_additional_information( $p_additional_information ) {
 360      return csv_escape_string( $p_additional_information );
 361  }
 362  
 363  /**
 364   * return the status string
 365   * @param string $p_status status
 366   * @return string formatted status
 367   * @access public
 368   */
 369  function csv_format_status( $p_status ) {
 370      return csv_escape_string( get_enum_element( 'status', $p_status ) );
 371  }
 372  
 373  /**
 374   * return the resolution string
 375   * @param int $p_resolution resolution
 376   * @return string formatted resolution string
 377   * @access public
 378   */
 379  function csv_format_resolution( $p_resolution ) {
 380      return csv_escape_string( get_enum_element( 'resolution', $p_resolution ) );
 381  }
 382  
 383  /**
 384   * return the duplicate bug id
 385   * @param int $p_duplicate_id
 386   * @return string formatted bug id
 387   * @access public
 388   */
 389  function csv_format_duplicate_id( $p_duplicate_id ) {
 390      return bug_format_id( $p_duplicate_id );
 391  }
 392  
 393  /**
 394   * return the selection
 395   * @param int $p_duplicate_id
 396   * @return string
 397   * @access public
 398   */
 399  function csv_format_selection( $p_duplicate_id ) {
 400      return csv_escape_string( '' );
 401  }
 402  
 403  /**
 404   * return the due date column
 405   * @param int $p_due_date
 406   * @return string
 407   * @access public
 408   */
 409  function csv_format_due_date( $p_due_date ) {
 410      static $s_date_format = null;
 411      if ( $s_date_format === null )
 412          $s_date_format = config_get( 'short_date_format' );
 413      return csv_escape_string( date( $s_date_format, $p_due_date ) );
 414  }
 415  
 416  /**
 417   * return the sponsorship total for an issue
 418   * @param int $p_sponsorship_total
 419   * @return string
 420   * @access public
 421   */
 422  function csv_format_sponsorship_total( $p_sponsorship_total ) {
 423      return number_format( $p_sponsorship_total );
 424  }


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