Problems with defining custom dynamic values

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
silmic05
Posts: 6
Joined: 21 Jul 2011, 07:46

Problems with defining custom dynamic values

Post by silmic05 »

Hi all,

I'm a beginner in Mantis, but I have to do some customizations for my office.

Ok, the problem is that we need some dynamic custom fields which can read from the database
from selfmade tables like "mantis_custom_field_table_device". I have already created the table
with the fields ID, Type and Device.

I have found in the manuel the point http://docs.mantisbt.org/master/en/admi ... DS.DYNAMIC
and based on that I created a custom function in custom_function_api.php. It is already able to read the data
from the database (tested by an echo output) but it cannot write it to an array and I don't what can be the problem.

The source code:

Code: Select all

<?php
function custom_function_override_enum_devices() {
	global $g_db;
	$rows = array();
	
	$query = "SELECT * 
	          FROM mantis_custom_field_table_device";
	
	$result = db_query_bound($query);
	
	echo "Query Ergebnis: ". $result ."<br />";
	
	if( !$result ) {
		db_error( $query );
		echo 'SQL query syntax Fehler';
		trigger_error( ERROR_DB_QUERY_FAILED, ERROR );
		return false;
	} else {
		$count = $result->RecordCount();
		
		echo "Anz.: ". $count ."<br />";
		
		for ($i=0; $i<$count; $i++) {
			$row = db_fetch_array( $result);
			echo "Device ".$i.": ". $row['Device'] ."<br />";
			
			$rows[$i] = $row['Device'];
			$rows[$i+2] = "test";
			
		}
	}	

	$t_possible_values = implode( '|', $rows );

	return $t_possible_values; 	
}
?>
In Mantis itself I have created an custom field "test" with type: "Enumeration" and possible values: "=devices".
The output of the test echos is:
Query Ergebnis: DeviceID,Type,Device 1,aaaa,testA 2,bbbbb,testB
Anz.: 2
Device 0:
Device 1:
and a dropdown list with blank|test|blank|test



The Mantis version I am testing this is 1.2.5

It would be nice if somebody could help me, because I don't find where the problem is?

Many thanks

Michael
silmic05
Posts: 6
Joined: 21 Jul 2011, 07:46

Re: Problems with defining custom dynamic values

Post by silmic05 »

I have found out that $result is losing his data after the first echo output. So therefore it's reasonable
that there could be no data in the array. BUT why does this happen.

Can anybody help me, please?
silmic05
Posts: 6
Joined: 21 Jul 2011, 07:46

Re: Problems with defining custom dynamic values

Post by silmic05 »

it works! :D

Code: Select all

function custom_function_override_enum_devices() {
	global $g_db;
	$t_enum = array();

	$query = "SELECT Device
	          FROM mantis_custom_field_device_table";
	
	$res = db_query_bound($query);	
	
	$count = $res->RecordCount();
	for ($i=0; $i<$count; $i++) {
		$row = db_fetch_array( $res);
		$t_enum[] = $row['Device'];
	}

	$t_possible_values = implode( '|', $t_enum );

	return $t_possible_values; 
}
working on MantisBT v. 1.2.5
Post Reply