Page 1 of 1

[example] Deadline custom field on View Issuses Page

Posted: 30 May 2006, 19:28
by cwirek
Hello,

Topic: [example for beginners] Deadline custom field on View Issuses Page - using custom functions

I've added Deadline date custom field to my project. I display it on view issues page with following rules:
- if Deadline is expired, the date is displayed on the red
- if Issue is closed or resolved, text 'DONE!' is displayed instead of deadline date

Mantis version: 1.0.3

1. In Mantis main directory create 'custom_functions_inc.php' file.

2. From 'custom_function_api.php' in 'core' directory copy following functions:

- custom_function_default_get_columns_to_view
- custom_function_default_print_column_value

to 'custom_functions_inc.php' file.

3. In 'custom_functions_inc.php' file:

rename:
custom_function_default_get_columns_to_view
to:
custom_function_override_get_columns_to_view

rename:
custom_function_default_print_column_value
to:
custom_function_override_print_column_value

4. In custom_function_override_get_columns_to_view function, find and add:

Code: Select all

	(...)
            $t_columns[] = 'severity';
            $t_columns[] = 'status';
            $t_columns[] = 'last_updated';
            $t_columns[] = 'custom_Deadline'; // <- ADDED
            $t_columns[] = 'summary';
	(...)
5. In custom_function_override_print_column_value function:

Find:

Code: Select all

if ( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
    $t_def = custom_field_get_definition( $t_field_id );
    print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
} else {
    // field is not linked to project
    echo $t_column_empty;
}
Replace with:

Code: Select all

if ( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
    $t_def = custom_field_get_definition( $t_field_id );
    if ( strpos( $p_column, 'custom_Deadline' ) === 0 && ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) )
    {
        if ( $p_issue_row['status'] < 80 )       // resolved = 80, closed = 90
        {
            $current_date = strtotime( date( "Y-m-d" ) );
            $deadline_date = custom_field_get_value( $t_field_id, $t_issue_id );
            if ( $current_date >= $deadline_date )
            {
               echo '<b><font color="red">';
               print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
               echo '</font></b>';
            }
            else
            {
                print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
            }
        }
        else
        {
            echo '<b>';
            echo 'DONE!';
            echo '</b>';
        }
    }
    else
    {
        print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
    }
} else {
    // field is not linked to project
    echo $t_column_empty;
}
Thank You.

Posted: 10 Aug 2006, 00:17
by ANR Daemon
Need to be pinned!