[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> custom_function_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: custom_function_api.php,v 1.32.2.1 2007-10-13 22:35:22 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  25  
  26      require_once ( $t_core_dir . 'prepare_api.php' );
  27  
  28      ### Custom Function API ###
  29  
  30      # --------------------
  31      # Checks the provided bug and determines whether it should be included in the changelog
  32      # or not.
  33      # returns true: to include, false: to exclude.
  34      function custom_function_default_changelog_include_issue( $p_issue_id ) {
  35          $t_issue = bug_get( $p_issue_id );
  36  
  37          return ( ( $t_issue->duplicate_id == 0 ) && ( $t_issue->resolution == FIXED ) &&
  38              ( $t_issue->status >= config_get( 'bug_resolved_status_threshold' ) ) );
  39      }
  40  
  41  
  42      # --------------------
  43      # Prints one entry in the changelog.
  44  	function custom_function_default_changelog_print_issue( $p_issue_id, $p_issue_level = 0 ) {
  45          $t_bug = bug_get( $p_issue_id );
  46  
  47          $t_category = is_blank( $t_bug->category ) ? '' : '<b>[' . $t_bug->category . ']</b> ';
  48          echo str_pad( '', $p_issue_level * 6, '&nbsp;' ), '- ', string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
  49  
  50          if ( $t_bug->handler_id != 0 ) {
  51              echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
  52          }
  53  
  54          echo ' - ', get_enum_element( 'status', $t_bug->status ), '.<br />';
  55      }
  56  
  57      # --------------------
  58      # Checks the provided bug and determines whether it should be included in the roadmap or not.
  59      # returns true: to include, false: to exclude.
  60  	function custom_function_default_roadmap_include_issue( $p_issue_id ) {
  61          $t_issue = bug_get( $p_issue_id );
  62  
  63          return ( $t_issue->duplicate_id == 0 );
  64      }
  65  
  66      # --------------------
  67      # Prints one entry in the roadmap.
  68  	function custom_function_default_roadmap_print_issue( $p_issue_id, $p_issue_level = 0 ) {
  69          $t_bug = bug_get( $p_issue_id );
  70          
  71          if ( bug_is_resolved( $p_issue_id ) ) {
  72              $t_strike_start = '<strike>';
  73              $t_strike_end = '</strike>';
  74          } else {
  75              $t_strike_start = $t_strike_end = '';
  76          }
  77          
  78          $t_category = is_blank( $t_bug->category ) ? '' : '<b>[' . $t_bug->category . ']</b> ';
  79          echo str_pad( '', $p_issue_level * 6, '&nbsp;' ), '- ', $t_strike_start, string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
  80  
  81          if ( $t_bug->handler_id != 0 ) {
  82              echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
  83          }
  84  
  85          echo ' - ', get_enum_element( 'status', $t_bug->status ), $t_strike_end, '.<br />';
  86      }
  87  
  88      # --------------------
  89      # format the bug summary.
  90  	function custom_function_default_format_issue_summary( $p_issue_id, $p_context=0 ) {
  91          switch ( $p_context ) {
  92              case SUMMARY_CAPTION:
  93                  $t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
  94                  break;
  95              case SUMMARY_FIELD:
  96                  $t_string = bug_format_id( $p_issue_id ) . ': ' . string_display_line_links( bug_get_field( $p_issue_id, 'summary' ) );
  97                  break;
  98              case SUMMARY_EMAIL:
  99                  $t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
 100                  break;
 101              default:
 102                  $t_string = string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
 103                  break;
 104          }
 105          return $t_string;
 106      }
 107  
 108      # --------------------
 109      # Register a checkin in source control by adding a history entry and a note
 110      # This can be overriden to do extra work.
 111      # The issue status/resolution would only be set if the issue is fixed, and hence $p_fixed is passed as true.
 112  	function custom_function_default_checkin( $p_issue_id, $p_comment, $p_file, $p_new_version, $p_fixed ) {
 113          if ( bug_exists( $p_issue_id ) ) {
 114              history_log_event_special( $p_issue_id, CHECKIN, $p_file, $p_new_version );
 115              bugnote_add( $p_issue_id, $p_comment, 0, VS_PRIVATE == config_get( 'source_control_notes_view_status' ) );
 116  
 117              $t_status = config_get( 'source_control_set_status_to' );
 118              if ( ( OFF != $t_status ) && $p_fixed ) {
 119                  bug_set_field( $p_issue_id, 'status', $t_status );
 120                  bug_set_field( $p_issue_id, 'resolution', config_get( 'source_control_set_resolution_to' ) );
 121              }
 122          }
 123      }
 124  
 125      # --------------------
 126      # Hook to validate field issue data before updating
 127      # Verify that the proper fields are set with the appropriate values before proceeding
 128      # to change the status.
 129      # In case of invalid data, this function should call trigger_error()
 130      # p_issue_id is the issue number that can be used to get the existing state
 131      # p_new_issue_data is an object (BugData) with the appropriate fields updated
 132  	function custom_function_default_issue_update_validate( $p_issue_id, $p_new_issue_data, $p_bugnote_text ) {
 133      }
 134  
 135      # --------------------
 136      # Hook to notify after an issue has been updated.
 137      # In case of errors, this function should call trigger_error()
 138      # p_issue_id is the issue number that can be used to get the existing state
 139  	function custom_function_default_issue_update_notify( $p_issue_id ) {
 140      }
 141  
 142      # --------------------
 143      # Hook to validate field settings before creating an issue
 144      # Verify that the proper fields are set before proceeding to create an issue
 145      # In case of errors, this function should call trigger_error()
 146      # p_new_issue_data is an object (BugData) with the appropriate fields updated
 147  	function custom_function_default_issue_create_validate( $p_new_issue_data ) {
 148      }
 149  
 150      # --------------------
 151      # Hook to notify after aa issue has been created.
 152      # In case of errors, this function should call trigger_error()
 153      # p_issue_id is the issue number that can be used to get the existing state
 154  	function custom_function_default_issue_create_notify( $p_issue_id ) {
 155      }
 156  
 157      # --------------------
 158      # Hook to validate field settings before deleting an issue.
 159      # Verify that the issue can be deleted before the actual deletion.
 160      # In the case that the issue should not be deleted, this function should
 161      # call trigger_error().
 162      # p_issue_id is the issue number that can be used to get the existing state
 163  	function custom_function_default_issue_delete_validate( $p_issue_id ) {
 164      }
 165  
 166      # --------------------
 167      # Hook to notify after an issue has been deleted.
 168      # p_issue_data is the issue data (BugData) that reflects the last status of the
 169      # issue before it was deleted.
 170  	function custom_function_default_issue_delete_notify( $p_issue_data ) {
 171      }
 172  
 173      # --------------------
 174      # Hook for authentication
 175      # can Mantis update the password
 176      function custom_function_default_auth_can_change_password( ) {
 177          $t_can_change = array( PLAIN, CRYPT, CRYPT_FULL_SALT, MD5 );
 178          if ( in_array( config_get( 'login_method' ), $t_can_change ) ) {
 179              return true;
 180          } else {
 181              return false;
 182          }
 183      }
 184  
 185      # --------------------
 186      # returns an array of the column names to be displayed.
 187      # The column names to use are those of the field names in the bug table.
 188      # In addition, you can use the following:
 189      # - "selection" for selection checkboxes.
 190      # - "edit" for icon to open the edit page.
 191      # - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
 192      #   current project.  In case of "All Projects, the field will be empty where it is
 193      #   not applicable.
 194      # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 195  	function custom_function_default_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 196          if ( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
 197              $t_columns = config_get( 'csv_columns' );
 198          } else if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
 199              $t_columns = config_get( 'view_issues_page_columns' );
 200          } else {
 201              $t_columns = config_get( 'print_issues_page_columns' );
 202          }
 203  
 204          return $t_columns;
 205      }
 206  
 207      # --------------------
 208      # Print the title of a column given its name.
 209      # $p_column: custom_xxx for custom field xxx, or otherwise field name as in bug table.
 210      # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 211  	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 212          global $t_sort, $t_dir;
 213  
 214          if ( strpos( $p_column, 'custom_' ) === 0 ) {
 215              $t_custom_field = substr( $p_column, 7 );
 216  
 217              if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 218                  echo '<td>';
 219              }
 220  
 221              $t_field_id = custom_field_get_id_from_name( $t_custom_field );
 222              if ( $t_field_id === false ) {
 223                  echo '@', $t_custom_field, '@';
 224              } else {
 225                  $t_def = custom_field_get_definition( $t_field_id );
 226                  $t_custom_field = lang_get_defaulted( $t_def['name'] );
 227  
 228                  if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 229                      print_view_bug_sort_link( $t_custom_field, $p_column, $t_sort, $t_dir, $p_columns_target );
 230                      print_sort_icon( $t_dir, $t_sort, $p_column );
 231                  } else {
 232                      echo $t_custom_field;
 233                  }
 234              }
 235  
 236              if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
 237                  echo '</td>';
 238              }
 239          } else {
 240              $t_function = 'print_column_title_' . $p_column;
 241              if ( function_exists( $t_function ) ) {
 242                  $t_function( $t_sort, $t_dir, $p_columns_target );
 243              } else {
 244                  echo '<td>';
 245                  print_view_bug_sort_link( lang_get_defaulted( $p_column ), $p_column, $t_sort, $t_dir, $p_columns_target );
 246                  print_sort_icon( $t_dir, $t_sort, $p_column );
 247                  echo '</td>';
 248              }
 249          }
 250      }
 251  
 252      # --------------------
 253      # Print the value of the custom field (if the field is applicable to the project of
 254      # the specified issue and the current user has read access to it.
 255      # see custom_function_default_print_column_title() for rules about column names.
 256      # $p_column: name of field to show in the column.
 257      # $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 258      # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 259  	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 260          if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 261              $t_column_start = '';
 262              $t_column_end = '';
 263              $t_column_empty = '';
 264          } else {
 265              $t_column_start = '<td>';
 266              $t_column_end = '</td>';
 267              $t_column_empty = '&nbsp;';
 268          }
 269  
 270          if ( strpos( $p_column, 'custom_' ) === 0 ) {
 271              echo $t_column_start;
 272              $t_custom_field = substr( $p_column, 7 );
 273  
 274              $t_field_id = custom_field_get_id_from_name( $t_custom_field );
 275              if ( $t_field_id === false ) {
 276                  echo '@', $t_custom_field, '@';
 277              } else {
 278                  $t_issue_id = $p_issue_row['id'];
 279                  $t_project_id = $p_issue_row['project_id'];
 280  
 281                  if ( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
 282                      $t_def = custom_field_get_definition( $t_field_id );
 283                      print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
 284                  } else {
 285                      // field is not linked to project
 286                      echo $t_column_empty;
 287                  }
 288              }
 289              echo $t_column_end;
 290          } else {
 291              if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
 292                  $t_function = 'print_column_' . $p_column;
 293              } else {
 294                  $t_function = 'csv_format_' . $p_column;
 295              }
 296  
 297              if ( function_exists( $t_function ) ) {
 298                  if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
 299                      $t_function( $p_issue_row, $p_columns_target );
 300                  } else {
 301                      $t_function( $p_issue_row[$p_column] );
 302                  }
 303              } else {
 304                  if ( isset( $p_issue_row[$p_column] ) ) {
 305                      echo $t_column_start . $p_issue_row[$p_column] . $t_column_end;
 306                  } else {
 307                      echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
 308                  }
 309              }
 310          }
 311      }
 312  
 313      # --------------------
 314      # Construct an enumeration for all versions for the current project.
 315      # The enumeration will be empty if current project is ALL PROJECTS.
 316      # Enumerations format is: "abc|lmn|xyz"
 317      # To use this in a custom field type "=versions" in the possible values field.
 318  	function custom_function_default_enum_versions() {
 319          $t_versions = version_get_all_rows( helper_get_current_project() );
 320  
 321          $t_enum = array();
 322          foreach( $t_versions as $t_version ) {
 323              $t_enum[] = $t_version['version'];
 324          }
 325  
 326          $t_possible_values = implode( '|', $t_enum );
 327  
 328          return $t_possible_values;
 329      }
 330  
 331      # --------------------
 332      # Construct an enumeration for released versions for the current project.
 333      # The enumeration will be empty if current project is ALL PROJECTS.
 334      # Enumerations format is: "abc|lmn|xyz"
 335      # To use this in a custom field type "=released_versions" in the possible values field.
 336      function custom_function_default_enum_released_versions() {
 337          $t_versions = version_get_all_rows( helper_get_current_project() );
 338  
 339          $t_enum = array();
 340          foreach( $t_versions as $t_version ) {
 341              if ( $t_version['released'] == 1 ) {
 342                  $t_enum[] = $t_version['version'];
 343              }
 344          }
 345  
 346          $t_possible_values = implode( '|', $t_enum );
 347  
 348          return $t_possible_values;
 349      }
 350  
 351      # --------------------
 352      # Construct an enumeration for released versions for the current project.
 353      # The enumeration will be empty if current project is ALL PROJECTS.
 354      # Enumerations format is: "abc|lmn|xyz"
 355      # To use this in a custom field type "=future_versions" in the possible values field.
 356  	function custom_function_default_enum_future_versions() {
 357          $t_versions = version_get_all_rows( helper_get_current_project() );
 358  
 359          $t_enum = array();
 360          foreach( $t_versions as $t_version ) {
 361              if ( $t_version['released'] == 0 ) {
 362                  $t_enum[] = $t_version['version'];
 363              }
 364          }
 365  
 366          $t_possible_values = implode( '|', $t_enum );
 367  
 368          return $t_possible_values;
 369      }
 370  
 371      # --------------------
 372      # Construct an enumeration for all categories for the current project.
 373      # The enumeration will be empty if current project is ALL PROJECTS.
 374      # Enumerations format is: "abc|lmn|xyz"
 375      # To use this in a custom field type "=categories" in the possible values field.
 376  	function custom_function_default_enum_categories() {
 377          $t_categories = category_get_all_rows( helper_get_current_project() );
 378  
 379          $t_enum = array();
 380          foreach( $t_categories as $t_category ) {
 381              $t_enum[] = $t_category['category'];
 382          }
 383  
 384          $t_possible_values = implode( '|', $t_enum );
 385  
 386          return $t_possible_values;
 387      }
 388  
 389      # --------------------
 390      # This function prints the custom buttons on the current view page based on specified bug id
 391      # and the context.  The printing of the buttons will typically call html_button() from
 392      # html_api.php.  For each button, this function needs to generate the enclosing '<td>' and '</td>'.
 393      function custom_function_default_print_bug_view_page_custom_buttons( $p_bug_id ) {
 394      }
 395  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics