How to Add Fied to Mangament Project Page?

Get help from other users here.

Moderators: Developer, Contributor

danilolutz
Posts: 9
Joined: 12 Apr 2012, 12:26
Contact:

Re: How to Add Fied to Mangament Project Page?

Post by danilolutz »

Hi Guys!!

I resolved my problem and I go show to yours how!

First, I created an extended Column and an extended Field how as follow:

Code: Select all

<?php

class MantisProjectExtendModuleColumn extends MantisColumn {

	public $column = "module_column";
	public $sortable = false;

	private $cache = array();

	public function __construct() {
		$this->title = plugin_lang_get( 'module_label', 'MantisProjectExtend' );
	}

	public function cache( $p_bugs ) {
		if ( count( $p_bugs ) < 1 ) {
			return;
		}

		$t_module_table = plugin_table( 'module', 'MantisProjectExtend' );
		$t_module_project_table = plugin_table( 'module_project', 'MantisProjectExtend' );
		$t_bug_table = db_get_table( 'mantis_bug_table' );
		
		$t_bug_ids = array();
		foreach ( $p_bugs as $t_bug ) {
			$t_bug_ids[] = $t_bug->id;
		}

		$t_bug_ids = implode( ',', $t_bug_ids );

		$t_query  = "SELECT b.id, m.module
                       FROM $t_bug_table b 
					   INNER JOIN $t_module_project_table p ON p.id_project=b.project_id
					   INNER JOIN $t_module_table m ON m.id=p.id_module
                      WHERE b.id IN ( $t_bug_ids )
                      GROUP BY b.id";
		$t_result = db_query_bound( $t_query );

		while ( $t_row = db_fetch_array( $t_result ) ) {
			$this->cache[$t_row['id']] = $t_row['module'];
		}
	}

	public function display( $p_bug, $p_columns_target ) {
		if ( isset( $this->cache[$p_bug->id] ) ) {
			if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ||
				$p_columns_target == COLUMNS_TARGET_PRINT_PAGE
			) {
				echo $this->cache[$p_bug->id];
			} else {
				echo $this->cache[$p_bug->id];
			}
		}
	}

}
And

Code: Select all

<?php

class MantisProjectExtendModuleField extends MantisFilter {

	/**
	 * Field name, as used in the form element and processing.
	 */
	public $field = "module_field";

	/**
	 * Filter title, as displayed to the user.
	 */
	public $title = 'Module';
	
	/**
	 * Filter type, as defined in core/constant_inc.php
	 */
	public $type = FILTER_TYPE_MULTI_INT;
	
	/**
	 * Default filter value, used for non-list filter types.
	 */
    public $default = array();

	/**
	 * Form element size, used for non-boolean filter types.
	 */
	public $size = null;

	/**
	 * Number of columns to use in the bug filter.
	 */
	public $colspan = 1;
	

	public function __construct() {
		$this->title = plugin_lang_get( 'module_label', 'MantisProjectExtend' );
	}	
	
    public static function inputs( $p_inputs=null ) {
		   static $s_inputs = array();

		   if ( func_num_args() ) {
				   $s_inputs = $p_inputs;
		   } else {
				   return $s_inputs;
	 	   }
    }	
	/**
	 * Validate the filter input, returning true if input is
	 * valid, or returning false if invalid.  Invalid inputs will
	 * be replaced with the filter's default value.
	 * @param multi Filter field input
	 * @return boolean Input valid (true) or invalid (false)
	 */
	public function validate( $p_filter_input ) {
	    self::inputs( $p_filter_input );
        return true;
	}

	/**
	 * Build the SQL query elements 'join', 'where', and 'params'
	 * as used by core/filter_api.php to create the filter query.
	 * @param multi Filter field input
	 * @return array Keyed-array with query elements; see developer guide
	 */
	function query( $p_filter_input ) {
		if ( !is_array( $p_filter_input ) ) {
			return;
		}

		$t_modules = array();

		foreach( $p_filter_input as $t_module ) {
			$t_modules[] = $t_module;
		}

		$t_modules = join( ',', $t_modules );
		
		$t_module_project_table = plugin_table( 'module_project', 'MantisProjectExtend' );
		$t_bug_table = db_get_table( 'mantis_bug_table' );
		

		$t_query = array(
			'join' => "INNER JOIN $t_module_project_table ON $t_bug_table.project_id=$t_module_project_table.id_project",
			'where' => "$t_module_project_table.id_module IN ( $t_modules )",
		);

		return $t_query;
	}

	/**
	 * Display the current value of the filter field.
	 * @param multi Filter field input
	 * @return string Current value output
	 */
	function display( $p_filter_value ) { 
		$t_options = $this->options();

		if ( isset( $t_options[ $p_filter_value ] ) ) {
			return $t_options[ $p_filter_value ];
		}

		return $p_filter_value;	
	}

	/**
	 * For list type filters, define a keyed-array of possible
	 * filter options, not including an 'any' value.
	 * @return array Filter options keyed by value=>display
	 */
	public function options() {
		static $s_options = null;
		
		if ( is_null( $s_options ) ) {
			$t_module_table = plugin_table( 'module', 'MantisProjectExtend' );		

			$t_query  = "SELECT id, module FROM $t_module_table
						  ORDER BY module ASC";
			$t_result = db_query_bound( $t_query );

			$res = array();
			while ( $t_row = db_fetch_array( $t_result ) ) {
				$s_options[$t_row['id']] = $t_row['module'];
			}
		}
		return $s_options;
	}
}
The effects of this Class Extends
A "class MantisProjectExtendModuleColumn extends MantisColumn" - Create a column in the result search list, how you set!
A "class MantisProjectExtendModuleField extends MantisFilter" - Create a Field in the search parameters!

Like attachment: extendsEffects

The Full Plugin can be found as attachment!

Special thanks for istvanb!!

Thank all yours for helping!
Attachments
extendsEffects
extendsEffects
extendsEffects.png (31.01 KiB) Viewed 4154 times
MantisProjectExtend.rar
Full Plugin
(7.26 KiB) Downloaded 385 times
Post Reply