[example] Deadline custom field on View Issuses Page

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
cwirek
Posts: 1
Joined: 30 May 2006, 18:20

[example] Deadline custom field on View Issuses Page

Post 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.
ANR Daemon
Posts: 5
Joined: 09 Aug 2006, 22:53

Post by ANR Daemon »

Need to be pinned!
Sorry for my terrible english...
Post Reply