Custom fields need to show in Summary page

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
safee
Posts: 29
Joined: 28 Jun 2011, 08:51

Custom fields need to show in Summary page

Post by safee »

Hi

I added some custome fields in mantis. in summary page we are getting details By project, By Resoulation, Time Stats For Resolved Issues , Reporter Effectiveness etc..now customized fields need to show in Administrator > summary page.

can anybody tell me how to do that or is it possible or not ?

Please reply

Thanks
sparkscam
Posts: 2
Joined: 03 Jun 2014, 18:20

Re: Custom fields need to show in Summary page

Post by sparkscam »

I would like to know how to do this as well. Is there some sort of plugin or patch that anyone knows of that will allow showing the custom fields?
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Custom fields need to show in Summary page

Post by atrol »

It's not clear what is meant with "showing custom fields".
You can have a lot of different custom fields with different data types where MantisBT is not able to know what's the meaning of it.

Of course, whatever you want: You have to implement your own logic.
Please use Search before posting and read the Manual
sparkscam
Posts: 2
Joined: 03 Jun 2014, 18:20

Re: Custom fields need to show in Summary page

Post by sparkscam »

Thanks for the reply atrol, I know I'm kind of hijacking the original posters thread and this may not be exactly what the original poster may have wanted but I think it's somewhat similar. I'm a student who is somewhat new to PHP, MySQL, MantisBT, and programming in general. What I am asking for is help on displaying information on the custom fields similar to how information is displayed on the Summary page. For instance the Summary page displays a count of new, resolved, closed, and total issues "By Priority", "By Resolution", and "By Severity". What I would like help with is displaying information in an identical way to these data types(Enum I believe?) from custom fields.

I've looked at the summary_api.php and the summary_page.php and it appears that there is a function called "summary_print_by_enum" that is used. I've looked into it and I'm not sure how to adapt that function to getting the information from the three custom field tables (mantis_custom_field_string_table,mantis_custom_field_table, and mantis_custom_field_project_table) in the database. Especially in a way that would display the issues similarly to the default fields.

An example of the kind of custom field that I am looking to display information on is "Name: Type, Project Count: #1-10, Type: Enumeration, Possible Values: Blue|Yellow|Orange|Green".

Again, I appologize if this is something that requires too much individual information in order to accurately answer,something that is very basic, or something that shouldn't really be discussed on the forum but any help would be appreciated!
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Custom fields need to show in Summary page

Post by atrol »

Sorry, I have not enough time to provide such kind of support.
You could start studying code in core/custom_field_api.php, e.g. function custom_field_distinct_values ...
Please use Search before posting and read the Manual
kthl
Posts: 2
Joined: 13 Oct 2014, 08:48

Re: Custom fields need to show in Summary page

Post by kthl »

Hi All

Has there been any progress with this issue? My employer is using a custom field to help capture causes of issues (e.g. Enhancement request, Coding error, etc...). We’d like to include reporting on this in the summary page.

I’ve worked out how to do this with changes to config_inc.php and summary_page.php. However, if someone has already enhanced MantisBT to allow custom fields to be included in the summary page that would be preferable.

I’m new to this board so if the question has been answered elsewhere, a pointer in the right direction would be appreciated.

Thanks.
kthl
Posts: 2
Joined: 13 Oct 2014, 08:48

Re: Custom fields need to show in Summary page

Post by kthl »

Dear All

Following on from previous email, what I did was:

i) Define a function "summary_print_by_custom_field()" in config_inc.php

ii) Added <?php summary_print_by_custom_field($t_orcttab) ?> to summary_page.php underneath <?php summary_print_by_category() ?>

summary_print_by_custom_field() is provided in the attachment. Anyone who wants to make use of this code is welcome to do so. However, please note the terms and conditions.
Attachments
func_def.txt
Definition of summary_print_by_custom_field()
(8.83 KiB) Downloaded 1339 times
gopir
Posts: 1
Joined: 06 Aug 2015, 11:46

Re: Custom fields need to show in Summary page

Post by gopir »

kthl wrote:Dear All

Following on from previous email, what I did was:

i) Define a function "summary_print_by_custom_field()" in config_inc.php

ii) Added <?php summary_print_by_custom_field($t_orcttab) ?> to summary_page.php underneath <?php summary_print_by_category() ?>

summary_print_by_custom_field() is provided in the attachment. Anyone who wants to make use of this code is welcome to do so. However, please note the terms and conditions.
Some how the db query in the function doesn't seem to work and hence will not update the total closed, total open and other bugs count.
Can you please look into this once.
newbe
Posts: 13
Joined: 14 Mar 2014, 16:06

Re: Custom fields need to show in Summary page

Post by newbe »

Hi folks,
I added the code from kthl and it worked "somehow" on my local test installation , the bugs count is faulty, too.
Test installation means server and database and Mantis user are running on the same machine. After transferring this to the productive system I get the following error message:

>>>>>>>>>>>>>>>>>
APPLICATION ERROR #401
Datenbankabfrage fehlgeschlagen. Die Reportmeldung lautet #0: für die Abfrage: SELECT b.id, b.status
FROM mantis_bug_table AS b
INNER JOIN mantis_custom_field_string_table AS s
ON b.id = s.bug_id WHERE s.field_id = 10 AND s.value LIKE "%|?|%".

Bitte benutzen Sie die „Zurück“-Taste Ihres Browsers, um auf die vorhergehende Seite zurückzukehren. Dort können Sie den hier angezeigten Eintrag korrigieren oder eine andere Aktion ausführen. Über das Menü können Sie auch direkt zu einer anderen Aktion wechseln.
<<<<<<<<<<<<<<<<<
On the productive system the database is accessed by a remote machine in the network.

The code of "summary_page.php" in both cases is identical. The error message appears immediately, timeouts and max. file sizes I already increased due to problems with file uploading. I'm working with V2.5.0 of Mantis.

Hopefully there are ideas where to search further.

Cheers Uli
amphetamine
Posts: 113
Joined: 05 Jun 2019, 00:17

Re: Custom fields need to show in Summary page

Post by amphetamine »

anyone who may share the template for current version 2.21.1
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Custom fields need to show in Summary page

Post by cas »

if you use this add-on, please adjust one line within the function to ensure it works correctly:
$b_query .= " " . "AND s.value LIKE \"%|" . $possible_value . "|%\"";
should read:
$b_query .= " " . "AND s.value LIKE \"%" . $possible_value . "%\"";
amphetamine
Posts: 113
Joined: 05 Jun 2019, 00:17

Re: Custom fields need to show in Summary page

Post by amphetamine »

2.22
INTERNAL APPLICATION ERROR
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Custom fields need to show in Summary page

Post by cas »

In summary page add the following section:

Code: Select all

	<!-- BY CUSTOM FIELD -->
	<div class="space-10"></div>
	<div class="widget-box table-responsive">
		<table class="table table-hover table-bordered table-condensed table-striped">
		<thead>
			<tr>
				<th class="width-35"><?php echo 'By custom_field' ?></th>
				<?php echo $t_summary_header ?>
			</tr>
		</thead>
		<?php summary_print_by_custom_field($t_filter) ?>
	</table>
	</div>
right after:

Code: Select all

	<!-- BY CATEGORY -->
	<div class="space-10"></div>
	<div class="widget-box table-responsive">
		<table class="table table-hover table-bordered table-condensed table-striped">
		<thead>
			<tr>
				<th class="width-35"><?php echo lang_get( 'by_category' ) ?></th>
				<?php echo $t_summary_header ?>
			</tr>
		</thead>
		<?php summary_print_by_category( $t_filter ) ?>
	</table>
	</div>
Next create a file called custom_functions_inc.php within the /config directory.
Content of that file should be:

Code: Select all

<?php
function summary_print_by_custom_field(array $p_filter = nul){
	// Initialise
	$t_mantis_bug_table = db_get_table( 'mantis_bug_table' );
	$t_mantis_custom_field_table = db_get_table( 'mantis_custom_field_table' );
	$t_mantis_custom_field_project_table = db_get_table( 'mantis_custom_field_project_table' );
	$t_mantis_custom_field_string_table = db_get_table( 'mantis_custom_field_string_table' );
	$t_project_id = helper_get_current_project();
	// ------------------------------------------------------------------------------------------- 
	// i) Select details of the custom fields.
	// Create SQL statement that will select values of custom fields.
	// ------------------------------------------------------------------------------------------- 
	if ($t_project_id <> ALL_PROJECTS) {
		$f_query  = "SELECT f.id, f.name, f.possible_values
				FROM $t_mantis_custom_field_table AS f
                INNER JOIN $t_mantis_custom_field_project_table AS p
                ON f.id = p.field_id
                WHERE p.project_id = $t_project_id
                ORDER BY f.name";
	} else {
		$f_query = "SELECT id, name, possible_values
                FROM $t_mantis_custom_field_table
                ORDER BY name";
	}
	$f_result = db_query($f_query);
	// ------------------------------------------------------------------------------------------- 
	// ii) For each custom field, display a table giving summary details for that field.
	// Achieved using following while loop.
	// -------------------------------------------------------------------------------------------
	while($f_row = db_fetch_array($f_result)) {

		$b_query_header  = "SELECT b.id, b.status
                        FROM $t_mantis_bug_table AS b
                        INNER JOIN $t_mantis_custom_field_string_table AS s
                        ON b.id = s.bug_id";
		// -----------------------------------------------------------------------------------------
		// Either select records for a particular project or, if all projects required, use
		//
		// NOTE: $f_row['id'] is the identifier of the custom field in $t_mantis_custom_field_table.     	
		// -----------------------------------------------------------------------------------------
		if ($t_project_id <> ALL_PROJECTS) {
			$b_query_header .= " " . "WHERE b.project_id = $t_project_id";
			$b_query_header .= " " . "AND   s.field_id =" . " " .  $f_row['id']; 
		} else {
			$b_query_header .= " " . "WHERE s.field_id =" . " " .  $f_row['id']; 
		}
		// -----------------------------------------------------------------------------------------
		// All possible values of the custom field will be held in an array, $possible_values.
		// $f_row['possible_values'] contains these values as a string with the values divided by
		// -----------------------------------------------------------------------------------------
		$possible_values = explode('|', $f_row['possible_values']);

		foreach ($possible_values as $possible_value) {
			// Initialise
			$label = string_display_line( $possible_value );
			$t_bugs_open = 0;
			$t_bugs_resolved = 0;
			$t_bugs_closed = 0;
			$t_bugs_total = 0;
			// See comments below.
			$t_resolved_val = config_get( 'bug_resolved_status_threshold' );
			$t_closed_val = config_get( 'bug_closed_status_threshold' );
			$b_query  = $b_query_header; // See above for value of $b_query_header
			$b_query .= " " . "AND s.value LIKE \"%" . $possible_value .  "%\"";
			$b_result = db_query($b_query);
			// -----------------------------------------------------------------------------------------
			// iii)	For each table count the number of open, resolved or closed bugs associated with
			// 	this $possible_value.
			//
			// -----------------------------------------------------------------------------------------
			while( $b_row = db_fetch_array( $b_result ) ) {
				$t_bugs_total++;
				if ($b_row['status'] < $t_resolved_val) {
					$t_bugs_open++;
				} else {
					if (($b_row['status'] >= $t_resolved_val) AND ($b_row['status'] < $t_closed_val)) {
						$t_bugs_resolved++;
					} else {
						$t_bugs_closed++;
					}
				}
			}
			$t_bugs_ratio = summary_helper_get_bugratio( $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total_count);
			summary_helper_print_row(string_display_line($f_row['name']), $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total,$t_bugs_ratio[0], $t_bugs_ratio[1] );
		} 
	}
}
Still is not perfect since existing filters are not applied but at least you will not get the Internal Application Error. :mrgreen:
Post Reply