Creating a my view filter that will filter on custom fields

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
kec161
Posts: 10
Joined: 25 Jan 2006, 16:31

Creating a my view filter that will filter on custom fields

Post by kec161 »

How would I go about creating a filter on the my_view_page.php that filters on a custom field?

I have a field called Unit Tester that contains the name of the developer that tested the code.

1. I've modified config_inc.php to add a new view box:

Code: Select all

	$g_my_view_boxes = array (
		'assigned'      => '1',
		'unassigned'    => '2',
		'reported'      => '3',
		'resolved'      => '4',
		'recent_mod'	=> '5',
		'monitored'		=> '6',
		'feedback'		=> '0',
		'verify'		=> '0',
		'ready_test'     => '7',
	);

2. I added the title text to custom_strings_inc.php

Code: Select all

$s_my_view_title_ready_test = "Waiting For Me To Unit Test";
The part I'm having trouble with is changing core/my_view_inc.php. Initially I tried

Code: Select all

	$c_filter['ready_test'] = array(
		'custom_Unit Tester' => Array('0' => $t_current_user_id),
		'show_category'		=> Array ( '0' => META_FILTER_ANY ),
		'show_severity'		=> Array ( '0' => META_FILTER_ANY ),
		'show_status'		=> Array ( '0' => META_FILTER_ANY ),
		'highlight_changed'	=> $t_default_show_changed,
		'reporter_id'		=> Array ( '0' => META_FILTER_ANY ),
		'handler_id'		=> Array ( '0' => META_FILTER_ANY ),
		'show_resolution'	=> Array ( '0' => META_FILTER_ANY ),
		'show_build'		=> Array ( '0' => META_FILTER_ANY ),
		'show_version'		=> Array ( '0' => META_FILTER_ANY ),
		'hide_status'		=> Array ( '0' => $t_hide_status_default ),
		'user_monitor'		=> Array ( '0' => META_FILTER_ANY ),
	);
	$url_link_parameters['ready_test'] = 'custom_Unit Tester=' . $t_current_user_id;

I also tried substituting "Unit Tester" for "custom_Unit Tester" but it didn't work.

I saw note 225 in http://manual.mantisbt.org/manual.confi ... ttings.php and attempted:

Code: Select all

	$c_filter['ready_test'] = array(
		'custom_fields' => Array('custom_Unit Tester' => Array( '0' => $t_current_user_id)),
		'show_category'		=> Array ( '0' => META_FILTER_ANY ),
		'show_severity'		=> Array ( '0' => META_FILTER_ANY ),
		'show_status'		=> Array ( '0' => META_FILTER_ANY ),
		'highlight_changed'	=> $t_default_show_changed,
		'reporter_id'		=> Array ( '0' => META_FILTER_ANY ),
		'handler_id'		=> Array ( '0' => META_FILTER_ANY ),
		'show_resolution'	=> Array ( '0' => META_FILTER_ANY ),
		'show_build'		=> Array ( '0' => META_FILTER_ANY ),
		'show_version'		=> Array ( '0' => META_FILTER_ANY ),
		'hide_status'		=> Array ( '0' => $t_hide_status_default ),
		'user_monitor'		=> Array ( '0' => META_FILTER_ANY ),
	);
	$url_link_parameters['ready_test'] = 'custom_unit tester=' . $t_current_user_id;

I tried substituting "Unit Tester" for "custom_Unit Tester" for this too but still no luck.

Has anyone done this before that can help me? Any help would be appreciated.

Thanks,
Kira (kira.fernandes@gmail.com)
kec161
Posts: 10
Joined: 25 Jan 2006, 16:31

Post by kec161 »

Any help at all would be appreciated. I could figure it out if someone pointed me in the right direction.
atomoid
Posts: 108
Joined: 18 Aug 2005, 00:46
Location: santa cruz, ca

Post by atomoid »

Have you tried the manual thread on this? although the info may be a bit outdated and i havent tried it myself...
http://manual.mantisbt.org/manual.confi ... ttings.php

doh! sorry! i didnt read your entire post...

but looking at your code, i dont think its legal to have a space in your variable, you might want to it "custom_unit_tester" everywhere it exists in the code (or whatever it is named 'under the hood'). also the '=' in "custom_unit tester=" looks like a typo.
kec161
Posts: 10
Joined: 25 Jan 2006, 16:31

Post by kec161 »

Thanks for the reply! I was busy doing other stuff and finally got around to trying your suggestions but it still doesn't work correctly.

FYI - Using spaces in custom field names is actually valid (see http://forums.mantisbt.org/viewtopic.ph ... highlight=).

Also, the = in

Code: Select all

$url_link_parameters['ready_test'] = 'custom_unit tester=' . $t_current_user_id;
is also valid. What this line is doing is specifying what query to run when the user clicks the link above the list of issues.

Any other suggestions? Anyone?

~ Kira
kec161
Posts: 10
Joined: 25 Jan 2006, 16:31

Figured it out.

Post by kec161 »

I figured out what I was doing wrong. I was suppose to put the numeric id of the field not the field name. The following works (it goes in the my_view_inc.php file):

Code: Select all

	
	$unit_tester_field_id = 16;
	$unit_test_status_field_id = 31;
	$ready_testing_text = "Ready for Testing";
	$username = current_user_get_field( 'username' );
	$c_filter['ready_test'] = array(
		'custom_fields' => Array($unit_test_status_field_id => Array('0' => $ready_testing_text),
								 $unit_tester_field_id => Array( '0' => $username)),
		'show_category'		=> Array ( '0' => META_FILTER_ANY ),
		'show_severity'		=> Array ( '0' => META_FILTER_ANY ),
		'show_status'		=> Array ( '0' => META_FILTER_ANY ),
		'highlight_changed'	=> $t_default_show_changed,
		'reporter_id'		=> Array ( '0' => META_FILTER_ANY ),
		'handler_id'		=> Array ( '0' => META_FILTER_ANY ),
		'show_resolution'	=> Array ( '0' => META_FILTER_ANY ),
		'show_build'		=> Array ( '0' => META_FILTER_ANY ),
		'show_version'		=> Array ( '0' => META_FILTER_ANY ),
		'hide_status'		=> Array ( '0' => $t_hide_status_default ),
		'user_monitor'		=> Array ( '0' => META_FILTER_ANY ),
	);
	$url_link_parameters['ready_test'] = 'custom_field_'.$unit_tester_field_id.'=' . $username. '&custom_field_'.$unit_test_status_field_id.'='.$ready_testing_text;
The variables

Code: Select all

	$unit_tester_field_id = 16;
	$unit_test_status_field_id = 31;
	$ready_testing_text = "Ready for Testing";
can all go in the config_inc.php file, I put them in the code above for completeness.
Post Reply