mantisbt:issue:7900
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mantisbt:issue:7900 [2007/05/01 04:00] – vboctor | mantisbt:issue:7900 [2014/04/08 06:15] (current) – gd71 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Extending Custom Group Actions ====== | ||
| + | **Author:** Victor Boctor | ||
| + | |||
| + | ===== Introduction ===== | ||
| + | |||
| + | In Mantis 1.1.0a3, a new technique for extending the standard set of issue group actions with less work than what was required in previous releases. | ||
| + | |||
| + | ===== Page Title ===== | ||
| + | |||
| + | This function prints the title for the custom page action page. | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * Prints the title for the custom action page. | ||
| + | */ | ||
| + | function action_add_note_print_title() { | ||
| + | echo '< | ||
| + | echo '< | ||
| + | echo lang_get( ' | ||
| + | echo '</ | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Form Fields ===== | ||
| + | |||
| + | This function echos all the form fields. | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * Prints the field within the custom action form. This has an entry for | ||
| + | * every field the user need to supply + the submit button. | ||
| + | * added as rows in a table that is already created by the calling code. | ||
| + | * A row has two columns. | ||
| + | */ | ||
| + | function action_add_note_print_fields() { | ||
| + | echo '< | ||
| + | ?> | ||
| + | <!-- View Status --> | ||
| + | <tr class=" | ||
| + | <td class=" | ||
| + | <?php echo lang_get( ' | ||
| + | </td> | ||
| + | <td> | ||
| + | <?php | ||
| + | if ( access_has_project_level( config_get( ' | ||
| + | < | ||
| + | <?php print_enum_string_option_list( ' | ||
| + | </ | ||
| + | <?php | ||
| + | } else { | ||
| + | echo get_enum_element( ' | ||
| + | echo '< | ||
| + | } | ||
| + | ?> | ||
| + | </td> | ||
| + | </tr> | ||
| + | <?php | ||
| + | echo '< | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Form Validation ===== | ||
| + | |||
| + | This function validates the user inputs for te form parameters and confirms that it is valid. | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * Validates the action on the specified bug id. | ||
| + | | ||
| + | * @returns true Action can be applied. | ||
| + | * @returns array( bug_id => reason for failure ) | ||
| + | */ | ||
| + | function action_add_note_validate( $p_bug_id ) { | ||
| + | $f_bugnote_text = gpc_get_string( ' | ||
| + | |||
| + | if ( is_blank( $f_bugnote_text ) ) { | ||
| + | error_parameters( lang_get( ' | ||
| + | trigger_error( ERROR_EMPTY_FIELD, | ||
| + | } | ||
| + | |||
| + | $t_failed_validation_ids = array(); | ||
| + | $t_add_bugnote_threshold = config_get( ' | ||
| + | $t_bug_id = $p_bug_id; | ||
| + | |||
| + | if ( bug_is_readonly( $t_bug_id ) ) { | ||
| + | $t_failed_validation_ids[$t_bug_id] = lang_get( ' | ||
| + | return $t_failed_validation_ids; | ||
| + | } | ||
| + | |||
| + | if ( !access_has_bug_level( $t_add_bugnote_threshold, | ||
| + | $t_failed_validation_ids[$t_bug_id] = lang_get( ' | ||
| + | return $t_failed_validation_ids; | ||
| + | } | ||
| + | |||
| + | return true; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Process Form ===== | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * Executes the custom action on the specified bug id. | ||
| + | | ||
| + | * @param $p_bug_id | ||
| + | | ||
| + | * @returns true | ||
| + | * @returns array( bug_id => reason for failure ) | ||
| + | */ | ||
| + | function action_add_note_process( $p_bug_id ) { | ||
| + | $f_bugnote_text = gpc_get_string( ' | ||
| + | $f_view_state = gpc_get_int( ' | ||
| + | bugnote_add ( $p_bug_id, $f_bugnote_text, | ||
| + | return true; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Configuration ===== | ||
| + | |||
| + | This steps tells Mantis to load the extension relating to the custom issue group action. | ||
| + | |||
| + | <code php> | ||
| + | # Custom Group Actions | ||
| + | # | ||
| + | # This extensibility model allows developing new group custom actions. | ||
| + | # can be implemented with a totally custom form and action pages or with a | ||
| + | # pre-implemented form and action page and call-outs to some functions. | ||
| + | # functions are to be implemented in a predefined file whose name is based on | ||
| + | # the action name. For example, for an action to add a note, the action would | ||
| + | # be EXT_ADD_NOTE and the file implementing it would be bug_actiongroup_add_note_inc.php. | ||
| + | # See implementation of this file for details. | ||
| + | # | ||
| + | # Sample: | ||
| + | # | ||
| + | # array( | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # ) | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # ) | ||
| + | # | ||
| + | # | ||
| + | # ) | ||
| + | # ); | ||
| + | $g_custom_group_actions = array(0=> | ||
| + | array( ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | </ | ||
