create dynamic custom field

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
costanm
Posts: 19
Joined: 07 Nov 2006, 15:09
Location: Noesis - Portugal

create dynamic custom field

Post by costanm »

Hi,

I would like to create one dynamic custom field that generates all the users with developer acess level.

Is it possible? How can I do it? in wich file should I place such a function?
How can I associate the custom field with that function?

Anyone can help me?

Mantis 1.0.5

Best regards
Nuno Ferreira da Costa
bitplus
Posts: 1
Joined: 28 Dec 2006, 06:58
Location: Guangdong,China

Post by bitplus »

I have a simple way if you don't want to use user_id as the custom field's value.
1. edit /core/custom_function_api.php, add code below:

Code: Select all

function custom_function_default_enum_developers() {
	$t_users = array();
	$p_project_id = helper_get_current_project();
	$p_access = DEVELOPER;
	$t_users = project_get_all_user_rows( $p_project_id, $p_access );

	$t_display = array();
	$t_sort = array();
	$t_show_realname = ( ON == config_get( 'show_realname' ) );
	$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
	foreach ( $t_users as $t_user ) {
		$t_user_name = string_attribute( $t_user['username'] );
		$t_sort_name = strtolower( $t_user_name );
		if ( $t_show_realname && ( $t_user['realname'] <> "" ) ){
			$t_user_name = string_attribute( $t_user['realname'] );
			if ( $t_sort_by_last_name ) {
				$t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
				$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
			} else {
				$t_sort_name = strtolower( $t_user_name );
			}
		}
		$t_display[] = $t_user_name;
		$t_sort[] = $t_sort_name;
	}
	array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
	$t_possible_values = implode( '|', $t_display );

	return $t_possible_values;
}
2. Create a custom field with type "Enumeration" or "Multiselection list" or etc, and set the possible values to "=developers".
3. Of course, you should add the new custom field to your projects. And then, enjoy it!
Post Reply