[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> custom_function_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   * Custom Function API
  19   *
  20   * @package CoreAPI
  21   * @subpackage CustomFunctionAPI
  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 bug_api.php
  27   * @uses bugnote_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 history_api.php
  35   * @uses html_api.php
  36   * @uses icon_api.php
  37   * @uses lang_api.php
  38   * @uses prepare_api.php
  39   * @uses print_api.php
  40   * @uses string_api.php
  41   * @uses utility_api.php
  42   * @uses version_api.php
  43   */
  44  
  45  require_api( 'bug_api.php' );
  46  require_api( 'bugnote_api.php' );
  47  require_api( 'category_api.php' );
  48  require_api( 'columns_api.php' );
  49  require_api( 'config_api.php' );
  50  require_api( 'constant_inc.php' );
  51  require_api( 'custom_field_api.php' );
  52  require_api( 'helper_api.php' );
  53  require_api( 'history_api.php' );
  54  require_api( 'html_api.php' );
  55  require_api( 'icon_api.php' );
  56  require_api( 'lang_api.php' );
  57  require_api( 'prepare_api.php' );
  58  require_api( 'print_api.php' );
  59  require_api( 'string_api.php' );
  60  require_api( 'utility_api.php' );
  61  require_api( 'version_api.php' );
  62  
  63  # ## Custom Function API ###
  64  # Checks the provided bug and determines whether it should be included in the changelog
  65  # or not.
  66  # returns true: to include, false: to exclude.
  67  function custom_function_default_changelog_include_issue( $p_issue_id ) {
  68      $t_issue = bug_get( $p_issue_id );
  69  
  70      return( ( $t_issue->resolution >= config_get( 'bug_resolution_fixed_threshold' ) &&
  71          $t_issue->resolution < config_get( 'bug_resolution_not_fixed_threshold' ) &&
  72          $t_issue->status >= config_get( 'bug_resolved_status_threshold' ) ) );
  73  }
  74  
  75  # Prints one entry in the changelog.
  76  function custom_function_default_changelog_print_issue( $p_issue_id, $p_issue_level = 0 ) {
  77      static $t_status;
  78  
  79      $t_bug = bug_get( $p_issue_id );
  80  
  81      if( $t_bug->category_id ) {
  82          $t_category_name = category_get_name( $t_bug->category_id );
  83      } else {
  84          $t_category_name = '';
  85      }
  86  
  87      $t_category = is_blank( $t_category_name ) ? '' : '<strong>[' . string_display_line( $t_category_name ) . ']</strong> ';
  88      echo utf8_str_pad( '', $p_issue_level * 6, '&#160;' ), '- ', string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
  89  
  90      if( $t_bug->handler_id != 0 ) {
  91          echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
  92      }
  93  
  94      if( !isset( $t_status[$t_bug->status] ) ) {
  95          $t_status[$t_bug->status] = get_enum_element( 'status', $t_bug->status );
  96      }
  97      echo ' - ', $t_status[$t_bug->status], '.<br />';
  98  }
  99  
 100  # Checks the provided bug and determines whether it should be included in the roadmap or not.
 101  # returns true: to include, false: to exclude.
 102  function custom_function_default_roadmap_include_issue( $p_issue_id ) {
 103      return true;
 104  }
 105  
 106  # Prints one entry in the roadmap.
 107  function custom_function_default_roadmap_print_issue( $p_issue_id, $p_issue_level = 0 ) {
 108      static $t_status;
 109  
 110      $t_bug = bug_get( $p_issue_id );
 111  
 112      if( bug_is_resolved( $p_issue_id ) ) {
 113          $t_strike_start = '<span class="strike">';
 114          $t_strike_end = '</span>';
 115      } else {
 116          $t_strike_start = $t_strike_end = '';
 117      }
 118  
 119      if( $t_bug->category_id ) {
 120          $t_category_name = category_get_name( $t_bug->category_id );
 121      } else {
 122          $t_category_name = '';
 123      }
 124  
 125      $t_category = is_blank( $t_category_name ) ? '' : '<strong>[' . string_display_line( $t_category_name ) . ']</strong> ';
 126  
 127      echo utf8_str_pad( '', $p_issue_level * 6, '&#160;' ), '- ', $t_strike_start, string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
 128  
 129      if( $t_bug->handler_id != 0 ) {
 130          echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
 131      }
 132  
 133      if( !isset( $t_status[$t_bug->status] ) ) {
 134          $t_status[$t_bug->status] = get_enum_element( 'status', $t_bug->status );
 135      }
 136      echo ' - ', $t_status[$t_bug->status], $t_strike_end, '.<br />';
 137  }
 138  
 139  # format the bug summary.
 140  function custom_function_default_format_issue_summary( $p_issue_id, $p_context = 0 ) {
 141      switch( $p_context ) {
 142          case SUMMARY_CAPTION:
 143              $t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
 144              break;
 145          case SUMMARY_FIELD:
 146              $t_string = bug_format_id( $p_issue_id ) . ': ' . string_display_line_links( bug_get_field( $p_issue_id, 'summary' ) );
 147              break;
 148          case SUMMARY_EMAIL:
 149              $t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
 150              break;
 151          default:
 152              $t_string = string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
 153              break;
 154      }
 155      return $t_string;
 156  }
 157  
 158  # Hook to validate field issue data before updating
 159  # Verify that the proper fields are set with the appropriate values before proceeding
 160  # to change the status.
 161  # In case of invalid data, this function should call trigger_error()
 162  # p_issue_id is the issue number that can be used to get the existing state
 163  # p_new_issue_data is an object (BugData) with the appropriate fields updated
 164  function custom_function_default_issue_update_validate( $p_issue_id, $p_new_issue_data, $p_bugnote_text ) {
 165  }
 166  
 167  # Hook to notify after an issue has been updated.
 168  # In case of errors, this function should call trigger_error()
 169  # p_issue_id is the issue number that can be used to get the existing state
 170  function custom_function_default_issue_update_notify( $p_issue_id ) {
 171  }
 172  
 173  # Hook to validate field settings before creating an issue
 174  # Verify that the proper fields are set before proceeding to create an issue
 175  # In case of errors, this function should call trigger_error()
 176  # p_new_issue_data is an object (BugData) with the appropriate fields updated
 177  function custom_function_default_issue_create_validate( $p_new_issue_data ) {
 178  }
 179  
 180  # Hook to notify after aa issue has been created.
 181  # In case of errors, this function should call trigger_error()
 182  # p_issue_id is the issue number that can be used to get the existing state
 183  function custom_function_default_issue_create_notify( $p_issue_id ) {
 184  }
 185  
 186  # Hook to validate field settings before deleting an issue.
 187  # Verify that the issue can be deleted before the actual deletion.
 188  # In the case that the issue should not be deleted, this function should
 189  # call trigger_error().
 190  # p_issue_id is the issue number that can be used to get the existing state
 191  function custom_function_default_issue_delete_validate( $p_issue_id ) {
 192  }
 193  
 194  # Hook to notify after an issue has been deleted.
 195  # p_issue_data is the issue data (BugData) that reflects the last status of the
 196  # issue before it was deleted.
 197  function custom_function_default_issue_delete_notify( $p_issue_data ) {
 198  }
 199  
 200  # Hook for authentication
 201  # can MantisBT update the password
 202  function custom_function_default_auth_can_change_password() {
 203      $t_can_change = array(
 204          PLAIN,
 205          CRYPT,
 206          CRYPT_FULL_SALT,
 207          MD5,
 208      );
 209      if( in_array( config_get( 'login_method' ), $t_can_change ) ) {
 210          return true;
 211      } else {
 212          return false;
 213      }
 214  }
 215  
 216  # returns an array of the column names to be displayed.
 217  # The column names to use are those of the field names in the bug table.
 218  # In addition, you can use the following:
 219  # - "selection" for selection checkboxes.
 220  # - "edit" for icon to open the edit page.
 221  # - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
 222  #   current project.  In case of "All Projects, the field will be empty where it is
 223  #   not applicable.
 224  # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 225  # $p_user_id: The user id or null for current logged in user.
 226  function custom_function_default_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE, $p_user_id = null ) {
 227      $t_project_id = helper_get_current_project();
 228  
 229      if( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
 230          $t_columns = config_get( 'csv_columns', '', $p_user_id, $t_project_id );
 231      } else if( $p_columns_target == COLUMNS_TARGET_EXCEL_PAGE ) {
 232          $t_columns = config_get( 'excel_columns', '', $p_user_id, $t_project_id );
 233      } else if( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
 234          $t_columns = config_get( 'view_issues_page_columns', '', $p_user_id, $t_project_id );
 235      } else {
 236          $t_columns = config_get( 'print_issues_page_columns', '', $p_user_id, $t_project_id );
 237      }
 238  
 239      $t_columns = columns_remove_invalid( $t_columns, columns_get_all( $t_project_id ) );
 240  
 241      return $t_columns;
 242  }
 243  
 244  # Print the title of a column given its name.
 245  # $p_column: custom_xxx for custom field xxx, or otherwise field name as in bug table.
 246  # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 247  function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 248      global $t_sort, $t_dir;
 249  
 250      $t_custom_field = column_get_custom_field_name( $p_column );
 251      if( $t_custom_field !== null ) {
 252          if( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 253              echo '<td>';
 254          }
 255  
 256          $t_field_id = custom_field_get_id_from_name( $t_custom_field );
 257          if( $t_field_id === false ) {
 258              echo '@', $t_custom_field, '@';
 259          } else {
 260              $t_def = custom_field_get_definition( $t_field_id );
 261              $t_custom_field = lang_get_defaulted( $t_def['name'] );
 262  
 263              if( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 264                  print_view_bug_sort_link( $t_custom_field, $p_column, $t_sort, $t_dir, $p_columns_target );
 265                  print_sort_icon( $t_dir, $t_sort, $p_column );
 266              } else {
 267                  echo $t_custom_field;
 268              }
 269          }
 270  
 271          if( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 272              echo '</td>';
 273          }
 274      } else {
 275          $t_plugin_columns = columns_get_plugin_columns();
 276  
 277          $t_function = 'print_column_title_' . $p_column;
 278          if( function_exists( $t_function ) ) {
 279              $t_function( $t_sort, $t_dir, $p_columns_target );
 280  
 281          } else if ( isset( $t_plugin_columns[ $p_column ] ) ) {
 282              $t_column_object = $t_plugin_columns[ $p_column ];
 283              print_column_title_plugin( $p_column, $t_column_object, $t_sort, $t_dir, $p_columns_target );
 284  
 285          } else {
 286              echo '<td>';
 287              print_view_bug_sort_link( column_get_title( $p_column ), $p_column, $t_sort, $t_dir, $p_columns_target );
 288              print_sort_icon( $t_dir, $t_sort, $p_column );
 289              echo '</td>';
 290          }
 291      }
 292  }
 293  
 294  # Print the value of the custom field (if the field is applicable to the project of
 295  # the specified issue and the current user has read access to it.
 296  # see custom_function_default_print_column_title() for rules about column names.
 297  # $p_column: name of field to show in the column.
 298  # $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 299  # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 300  function custom_function_default_print_column_value( $p_column, $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 301      if( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 302          $t_column_start = '';
 303          $t_column_end = '';
 304          $t_column_empty = '';
 305      } else {
 306          $t_column_start = '<td>';
 307          $t_column_end = '</td>';
 308          $t_column_empty = '&#160;';
 309      }
 310  
 311      $t_custom_field = column_get_custom_field_name( $p_column );
 312      if( $t_custom_field !== null ) {
 313          echo $t_column_start;
 314  
 315          $t_field_id = custom_field_get_id_from_name( $t_custom_field );
 316          if( $t_field_id === false ) {
 317              echo '@', $t_custom_field, '@';
 318          } else {
 319              $t_issue_id = $p_bug->id;
 320              $t_project_id = $p_bug->project_id;
 321  
 322              if( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
 323                  $t_def = custom_field_get_definition( $t_field_id );
 324                  print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
 325              } else {
 326                  // field is not linked to project
 327                  echo $t_column_empty;
 328              }
 329          }
 330          echo $t_column_end;
 331      } else {
 332          $t_plugin_columns = columns_get_plugin_columns();
 333  
 334          if( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
 335              $t_function = 'print_column_' . $p_column;
 336          } else {
 337              $t_function = 'csv_format_' . $p_column;
 338          }
 339  
 340          if( function_exists( $t_function ) ) {
 341              if( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
 342                  $t_function( $p_bug, $p_columns_target );
 343              } else {
 344                  $t_function( $p_bug->$p_column );
 345              }
 346  
 347          } else if ( isset( $t_plugin_columns[ $p_column ] ) ) {
 348              $t_column_object = $t_plugin_columns[ $p_column ];
 349              print_column_plugin( $t_column_object, $p_bug, $p_columns_target );
 350  
 351          } else {
 352              if( isset( $p_bug->$p_column ) ) {
 353                  echo $t_column_start . string_display_line( $p_bug->$p_column ) . $t_column_end;
 354              } else {
 355                  echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
 356              }
 357          }
 358      }
 359  }
 360  
 361  # Construct an enumeration for all versions for the current project.
 362  # The enumeration will be empty if current project is ALL PROJECTS.
 363  # Enumerations format is: "abc|lmn|xyz"
 364  # To use this in a custom field type "=versions" in the possible values field.
 365  function custom_function_default_enum_versions() {
 366      $t_versions = version_get_all_rows( helper_get_current_project() );
 367  
 368      $t_enum = array();
 369      foreach( $t_versions as $t_version ) {
 370          $t_enum[] = $t_version['version'];
 371      }
 372  
 373      $t_possible_values = implode( '|', $t_enum );
 374  
 375      return $t_possible_values;
 376  }
 377  
 378  # Construct an enumeration for released versions for the current project.
 379  # The enumeration will be empty if current project is ALL PROJECTS.
 380  # Enumerations format is: "abc|lmn|xyz"
 381  # To use this in a custom field type "=released_versions" in the possible values field.
 382  function custom_function_default_enum_released_versions() {
 383      $t_versions = version_get_all_rows( helper_get_current_project() );
 384  
 385      $t_enum = array();
 386      foreach( $t_versions as $t_version ) {
 387          if( $t_version['released'] == 1 ) {
 388              $t_enum[] = $t_version['version'];
 389          }
 390      }
 391  
 392      $t_possible_values = implode( '|', $t_enum );
 393  
 394      return $t_possible_values;
 395  }
 396  
 397  # Construct an enumeration for released versions for the current project.
 398  # The enumeration will be empty if current project is ALL PROJECTS.
 399  # Enumerations format is: "abc|lmn|xyz"
 400  # To use this in a custom field type "=future_versions" in the possible values field.
 401  function custom_function_default_enum_future_versions() {
 402      $t_versions = version_get_all_rows( helper_get_current_project() );
 403  
 404      $t_enum = array();
 405      foreach( $t_versions as $t_version ) {
 406          if( $t_version['released'] == 0 ) {
 407              $t_enum[] = $t_version['version'];
 408          }
 409      }
 410  
 411      $t_possible_values = implode( '|', $t_enum );
 412  
 413      return $t_possible_values;
 414  }
 415  
 416  # Construct an enumeration for all categories for the current project.
 417  # The enumeration will be empty if current project is ALL PROJECTS.
 418  # Enumerations format is: "abc|lmn|xyz"
 419  # To use this in a custom field type "=categories" in the possible values field.
 420  function custom_function_default_enum_categories() {
 421      $t_categories = category_get_all_rows( helper_get_current_project() );
 422  
 423      $t_enum = array();
 424      foreach( $t_categories as $t_category ) {
 425          $t_enum[] = $t_category['category'];
 426      }
 427  
 428      $t_possible_values = implode( '|', $t_enum );
 429  
 430      return $t_possible_values;
 431  }
 432  
 433  # This function prints the custom buttons on the current view page based on specified bug id
 434  # and the context.  The printing of the buttons will typically call html_button() from
 435  # html_api.php.  For each button, this function needs to generate the enclosing '<td>' and '</td>'.
 436  function custom_function_default_print_bug_view_page_custom_buttons( $p_bug_id ) {
 437  }


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