View Issue Details

IDProjectCategoryView StatusLast Update
0009096mantisbttaggingpublic2017-10-18 16:23
ReportertimjAssigned Tovboctor 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target Version1.3.0-rc.2Fixed in Version1.3.0-rc.2 
Summary0009096: Adding "tags" to $g_view_issues_page_columns does not work
Description

If "tags" is added to the list of columns to show on the issue view page (via the $g_view_issues_page_columns configuration variable), Mantis appears to recognise it (the column header shows capitalised "Tags") but the column is full of the string "@tags@" instead of the tags for the bugs.

Tagsmantishub, patch

Relationships

has duplicate 0011122 closedrombert add "Tag" column to possible columns 
has duplicate 0017822 closedatrol Tags is missing from column customization 
related to 0023494 closedatrol Wrong class name for tags output 

Activities

vboctor

vboctor

2008-07-13 15:32

manager   ~0018459

The tags field is not currently supported. I agree that it should.

djcarr

djcarr

2009-03-18 22:31

reporter   ~0021106

Last edited: 2009-03-19 04:15

I would really appreciate the 'tags' field to be supported too! Thank you!

PS - I wrote an SQL Query to get tags into a report and it's very simple if you can use the group_concat() function for MySQL. Other databases have different approaches to concatenate multiple rows into 1 field. So this may need specific code for different backends, and for other backends secondary queries may be needed.

2009-03-30 20:00

 

mantis-1.1.6-add_tags.diff (5,941 bytes)
diff -r -b -c -C10 mantis-1.1.6-original/config_defaults_inc.php mantis-1.1.6/config_defaults_inc.php
*** mantis-1.1.6-original/config_defaults_inc.php	2008-12-09 11:20:28.000000000 -0800
--- mantis-1.1.6/config_defaults_inc.php	2009-03-30 15:42:35.000000000 -0700
***************
*** 500,520 ****
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	# Some of the columns specified here can be removed automatically if they conflict with other configuration.
  	# For example, sponsorship_total will be removed if sponsorships are disabled.
  	# To include custom field 'xyz', include the column name as 'custom_xyz'.
  	#
  	# Standard Column Names (i.e. names to choose from):
  	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
  	# resolution, fixed_in_version, view_state, os, os_build, platform, version, date_submitted, attachment,
  	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count
! 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
  	
  	# A configuration option that identifies the columns to be show on the print issues page.
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	$g_print_issues_page_columns = array ( 'selection', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
  
  	# A configuration option that identifies the columns to be include in the CSV export.
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	$g_csv_columns = array ( 'id', 'project_id', 'reporter_id', 'handler_id', 'priority', 'severity', 'reproducibility', 'version', 'projection', 'category', 'date_submitted', 'eta', 'os', 'os_build', 'platform', 'view_state', 'last_updated', 'summary', 'status', 'resolution', 'fixed_in_version', 'duplicate_id' );
--- 500,520 ----
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	# Some of the columns specified here can be removed automatically if they conflict with other configuration.
  	# For example, sponsorship_total will be removed if sponsorships are disabled.
  	# To include custom field 'xyz', include the column name as 'custom_xyz'.
  	#
  	# Standard Column Names (i.e. names to choose from):
  	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
  	# resolution, fixed_in_version, view_state, os, os_build, platform, version, date_submitted, attachment,
  	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count
! 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary', 'tags' );
  	
  	# A configuration option that identifies the columns to be show on the print issues page.
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	$g_print_issues_page_columns = array ( 'selection', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
  
  	# A configuration option that identifies the columns to be include in the CSV export.
  	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
  	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
  	$g_csv_columns = array ( 'id', 'project_id', 'reporter_id', 'handler_id', 'priority', 'severity', 'reproducibility', 'version', 'projection', 'category', 'date_submitted', 'eta', 'os', 'os_build', 'platform', 'view_state', 'last_updated', 'summary', 'status', 'resolution', 'fixed_in_version', 'duplicate_id' );
diff -r -b -c -C10 mantis-1.1.6-original/core/columns_api.php mantis-1.1.6/core/columns_api.php
*** mantis-1.1.6-original/core/columns_api.php	2008-12-09 11:20:28.000000000 -0800
--- mantis-1.1.6/core/columns_api.php	2009-03-30 15:41:02.000000000 -0700
***************
*** 646,656 ****
--- 646,676 ----
  	
  	# --------------------
  	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
  	function print_column_target_version( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
  		echo '<td>';
  		if ( access_has_bug_level( config_get( 'roadmap_view_threshold' ), $p_row['id'] ) ) {
  			echo $p_row['target_version'];
  		}
  		echo '</td>';
  	}
+ 
+     function print_column_title_tags( $p_sort, $p_dir, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+         if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+             echo "\t<td>";
+             echo 'Tags';
+             echo "</td>\n";
+         }
+     }
+ 
+     function print_column_tags( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+         $tags = tag_bug_get_attached($p_row['id']);
+         echo '<td class="left">';
+         reset($tags);
+         while (list($key, $tag) = each($tags))
+         {
+             echo "<a href=\"tag_view_page.php?tag_id=" . $tag['id'] . "\">" . $tag['name'] . "</a> ";
+         }
+         echo '</td>';
+     }
+ 
  ?>
BrianEnigma

BrianEnigma

2009-03-30 20:04

reporter   ~0021323

Attached is a patch for my solution to the issue in Mantis 1.1.6. It gets the job done, but may or may not be the most efficient or best way to go about doing so. Specifically, for each bug row that is displayed in the View Issues list, a SQL query is performed to grab its tags. There may be a way to do this better within the original query to populate the page (with an inner-join or somesuch). That being said, it works just fine for our smallish intranet installation.

dominik

dominik

2010-11-10 08:21

reporter  

plugin_ColumnTags.patch (7,529 bytes)
From ae8b6f5892fca750666dbd681063a5e52a86159b Mon Sep 17 00:00:00 2001
From: Dominik Blunk <dominik@blunk.ch>
Date: Wed, 10 Nov 2010 13:28:26 +0100
Subject: [PATCH] This plugin allows the usage of "Tags" as column on pages like "view issues", "CSV export" or "Excel export".
 After installing the plugin the column "tags" may be added/removed as usual under "Configuration - Manage Columns"

---
 csv_export.php                          |   14 +++++-
 excel_xml_export.php                    |   14 +++++-
 plugins/ColumnTags/ColumnTags.class.php |   80 ++++++++++++++++++++++++++++++
 plugins/ColumnTags/ColumnTags.php       |   81 +++++++++++++++++++++++++++++++
 4 files changed, 187 insertions(+), 2 deletions(-)
 create mode 100644 plugins/ColumnTags/ColumnTags.class.php
 create mode 100644 plugins/ColumnTags/ColumnTags.php

diff --git a/csv_export.php b/csv_export.php
index 2116db2..0dbd2d1 100644
--- a/csv_export.php
+++ b/csv_export.php
@@ -113,7 +113,19 @@
 				echo csv_escape_string($t_value);
 			} else {
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row->$t_column );
+				if( function_exists( $t_function ) ) {
+					echo $t_function( $t_row->$t_column );
+				}
+				else {
+					ob_start();
+					$t_plugin_columns = columns_get_plugin_columns();
+					if ( isset( $t_plugin_columns[ $t_column ] ) ) {
+						$t_column_object = $t_plugin_columns[ $t_column ];
+						print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
+					}
+					$t_value = ob_get_clean();
+					echo csv_escape_string($t_value);
+				}
 			}
 		}
 
diff --git a/excel_xml_export.php b/excel_xml_export.php
index 13469e4..872ff70 100644
--- a/excel_xml_export.php
+++ b/excel_xml_export.php
@@ -94,7 +94,19 @@
 							echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row->$t_column );
+							if( function_exists( $t_function ) ) {
+								echo $t_function( $t_row->$t_column );
+							}
+							else {
+								ob_start();
+								$t_plugin_columns = columns_get_plugin_columns();
+								if ( isset( $t_plugin_columns[ $t_column ] ) ) {
+									$t_column_object = $t_plugin_columns[ $t_column ];
+									print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
+								}
+								$t_value = ob_get_clean();
+								echo excel_prepare_string( $t_value );
+							}
 						}
 					}
 				}
diff --git a/plugins/ColumnTags/ColumnTags.class.php b/plugins/ColumnTags/ColumnTags.class.php
new file mode 100644
index 0000000..5f2e6c1
--- /dev/null
+++ b/plugins/ColumnTags/ColumnTags.class.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Class ColumnTags
+ *
+ * This model class represents the logic for the column "tags"
+ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
+ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
+ * @link http://www.acc-solutions.ch
+ * @package model
+ */
+
+/**
+ *	ColumnTags column class
+ */
+class ColumnTags extends MantisColumn {
+
+	/**
+	 * Column title, as displayed to the user.
+	 */
+	public $title = 'Tags';
+
+	/**
+	 * Column name, as selected in the manage columns interfaces.
+	 */
+	public $column = 'tags';
+
+	/**
+	 * Column is sortable by the user.  Setting this to true implies that
+	 * the column will properly implement the sortquery() method.
+	 */
+	public $sortable = true;
+
+	/**
+	 * Build the SQL query elements 'join' and 'order' as used by
+	 * core/filter_api.php to create the filter sorting query.
+	 * @param string Sorting order ('ASC' or 'DESC')
+	 * @return array Keyed-array with query elements; see developer guide
+	 */
+	public function sortquery( $p_dir ) {
+		$t_tags_table = db_get_table( 'mantis_tag_table' );
+		return array( 'join' => 'left join mantis_bug_tag_table on (mantis_bug_table.id = mantis_bug_tag_table.bug_id)
+								left join mantis_tag_table on (mantis_tag_table.id = mantis_bug_tag_table.tag_id)',
+					  'order' => 'mantis_tag_table.name ' . $p_dir );
+	}
+
+	/**
+	 * Allow plugin columns to pre-cache data for all issues
+	 * that will be shown in a given view.  This is preferable to
+	 * the alternative option of querying the database for each
+	 * issue as the display() method is called.
+	 * @param array Bug objects
+	 */
+	public function cache( $p_bugs ) {}
+
+	/**
+	 * Function to display column data for a given bug row.
+	 * @param object Bug object
+	 * @param int Column display target
+	 */
+	public function display( $p_bug, $p_columns_target ) {
+		$t_tags = tag_bug_get_attached($p_bug->id);
+		if ($p_columns_target == COLUMNS_TARGET_CSV_PAGE) {
+			$i = 0;
+			foreach( $t_tags as $t_tag ) {
+				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
+				print ( string_display( $t_tag['name'] ) );
+				$i++;
+			}
+		}
+		else {
+			$i = 0;
+			foreach( $t_tags as $t_tag ) {
+				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
+				tag_display_link( $t_tag );
+				$i++;
+			}
+		}
+	}
+}
+
diff --git a/plugins/ColumnTags/ColumnTags.php b/plugins/ColumnTags/ColumnTags.php
new file mode 100644
index 0000000..4ba6651
--- /dev/null
+++ b/plugins/ColumnTags/ColumnTags.php
@@ -0,0 +1,81 @@
+<?PHP
+/**
+ * Mantis plugin ColumnTags
+ *
+ * This model class represents the business logic associated with the ColumnTags plugin
+ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
+ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
+ * @link http://www.acc-solutions.ch
+ * @package model
+ */
+require_once ('ColumnTags.class.php');
+
+/**
+ * ColumnTags plugin class
+ */
+class ColumnTagsPlugin extends MantisPlugin {
+
+	/**
+	 * Define name, version etc. of custom plugin
+	 *
+	 * @return void
+	 */
+	public function register() {
+		$this->name = 'Column Tags';																# Proper name of plugin
+		$this->description = 'Allow usage of Tags as Column on View Issues Page, CSV export etc.';	# Short description of the plugin
+		$this->page = '';																			# Default plugin page (when clicking on manage plugin page)
+		$this->version = '1.0';																		# Plugin version string
+		$this->requires = array( 'MantisCore' => '1.2.0' );											# Plugin dependencies, array of basename => version pairs. Should always depend on an appropriate version of MantisBT
+		$this->author = 'ACC Solutions AG';															# Author/team name
+		$this->contact = 'dev@acc-solutions.ch';													# Author/team e-mail address
+		$this->url = 'http://www.acc-solutions.ch';													# Support webpage
+	}
+
+	/**
+	 * Plugin configuration options
+	 *
+	 * @return array
+	 */
+	function config( ) {
+		return array( );
+	}
+
+	/**
+	 * Declaration of events that this plugin will trigger
+	 *
+	 * @return void
+	 */
+	function events( ) {
+		return array( );
+	}
+
+	/**
+	 * Declaration (assignment) of hooks (which events triggers which function)
+	 *
+	 * @return void
+	 */
+	function hooks( ) {
+		return array( 'EVENT_FILTER_COLUMNS' => 'get_tags_column' );
+	}
+
+	/**
+	 * Plugin initialisation
+	 *
+	 * @return void
+	 */
+	function init( ) {
+	}
+
+	/**
+	 * Return tag column
+	 * Plugin specific function
+	 *
+	 * @param string $p_event event name triggering the method
+	 * @param string $p_bug_id bug id
+	 * @return string
+	 */
+	function get_tags_column( $p_event, $p_bug_id ) {
+		# must correspond to an existing class name
+		return array( 'ColumnTags' );
+	}
+}
-- 
1.7.3.1.msysgit.0

plugin_ColumnTags.patch (7,529 bytes)
dominik

dominik

2010-11-10 08:38

reporter  

plugin_ColumnTags_slightly_improved.patch (17,089 bytes)
From ae8b6f5892fca750666dbd681063a5e52a86159b Mon Sep 17 00:00:00 2001
From: Dominik Blunk <dominik@blunk.ch>
Date: Wed, 10 Nov 2010 13:28:26 +0100
Subject: [PATCH 1/2] This plugin allows the usage of "Tags" as column on pages like "view issues", "CSV export" or "Excel export".
 After installing the plugin the column "tags" may be added/removed as usual under "Configuration - Manage Columns"

---
 csv_export.php                          |   14 +++++-
 excel_xml_export.php                    |   14 +++++-
 plugins/ColumnTags/ColumnTags.class.php |   80 ++++++++++++++++++++++++++++++
 plugins/ColumnTags/ColumnTags.php       |   81 +++++++++++++++++++++++++++++++
 4 files changed, 187 insertions(+), 2 deletions(-)
 create mode 100644 plugins/ColumnTags/ColumnTags.class.php
 create mode 100644 plugins/ColumnTags/ColumnTags.php

diff --git a/csv_export.php b/csv_export.php
index 2116db2..0dbd2d1 100644
--- a/csv_export.php
+++ b/csv_export.php
@@ -113,7 +113,19 @@
 				echo csv_escape_string($t_value);
 			} else {
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row->$t_column );
+				if( function_exists( $t_function ) ) {
+					echo $t_function( $t_row->$t_column );
+				}
+				else {
+					ob_start();
+					$t_plugin_columns = columns_get_plugin_columns();
+					if ( isset( $t_plugin_columns[ $t_column ] ) ) {
+						$t_column_object = $t_plugin_columns[ $t_column ];
+						print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
+					}
+					$t_value = ob_get_clean();
+					echo csv_escape_string($t_value);
+				}
 			}
 		}
 
diff --git a/excel_xml_export.php b/excel_xml_export.php
index 13469e4..872ff70 100644
--- a/excel_xml_export.php
+++ b/excel_xml_export.php
@@ -94,7 +94,19 @@
 							echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row->$t_column );
+							if( function_exists( $t_function ) ) {
+								echo $t_function( $t_row->$t_column );
+							}
+							else {
+								ob_start();
+								$t_plugin_columns = columns_get_plugin_columns();
+								if ( isset( $t_plugin_columns[ $t_column ] ) ) {
+									$t_column_object = $t_plugin_columns[ $t_column ];
+									print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
+								}
+								$t_value = ob_get_clean();
+								echo excel_prepare_string( $t_value );
+							}
 						}
 					}
 				}
diff --git a/plugins/ColumnTags/ColumnTags.class.php b/plugins/ColumnTags/ColumnTags.class.php
new file mode 100644
index 0000000..5f2e6c1
--- /dev/null
+++ b/plugins/ColumnTags/ColumnTags.class.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Class ColumnTags
+ *
+ * This model class represents the logic for the column "tags"
+ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
+ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
+ * @link http://www.acc-solutions.ch
+ * @package model
+ */
+
+/**
+ *	ColumnTags column class
+ */
+class ColumnTags extends MantisColumn {
+
+	/**
+	 * Column title, as displayed to the user.
+	 */
+	public $title = 'Tags';
+
+	/**
+	 * Column name, as selected in the manage columns interfaces.
+	 */
+	public $column = 'tags';
+
+	/**
+	 * Column is sortable by the user.  Setting this to true implies that
+	 * the column will properly implement the sortquery() method.
+	 */
+	public $sortable = true;
+
+	/**
+	 * Build the SQL query elements 'join' and 'order' as used by
+	 * core/filter_api.php to create the filter sorting query.
+	 * @param string Sorting order ('ASC' or 'DESC')
+	 * @return array Keyed-array with query elements; see developer guide
+	 */
+	public function sortquery( $p_dir ) {
+		$t_tags_table = db_get_table( 'mantis_tag_table' );
+		return array( 'join' => 'left join mantis_bug_tag_table on (mantis_bug_table.id = mantis_bug_tag_table.bug_id)
+								left join mantis_tag_table on (mantis_tag_table.id = mantis_bug_tag_table.tag_id)',
+					  'order' => 'mantis_tag_table.name ' . $p_dir );
+	}
+
+	/**
+	 * Allow plugin columns to pre-cache data for all issues
+	 * that will be shown in a given view.  This is preferable to
+	 * the alternative option of querying the database for each
+	 * issue as the display() method is called.
+	 * @param array Bug objects
+	 */
+	public function cache( $p_bugs ) {}
+
+	/**
+	 * Function to display column data for a given bug row.
+	 * @param object Bug object
+	 * @param int Column display target
+	 */
+	public function display( $p_bug, $p_columns_target ) {
+		$t_tags = tag_bug_get_attached($p_bug->id);
+		if ($p_columns_target == COLUMNS_TARGET_CSV_PAGE) {
+			$i = 0;
+			foreach( $t_tags as $t_tag ) {
+				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
+				print ( string_display( $t_tag['name'] ) );
+				$i++;
+			}
+		}
+		else {
+			$i = 0;
+			foreach( $t_tags as $t_tag ) {
+				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
+				tag_display_link( $t_tag );
+				$i++;
+			}
+		}
+	}
+}
+
diff --git a/plugins/ColumnTags/ColumnTags.php b/plugins/ColumnTags/ColumnTags.php
new file mode 100644
index 0000000..4ba6651
--- /dev/null
+++ b/plugins/ColumnTags/ColumnTags.php
@@ -0,0 +1,81 @@
+<?PHP
+/**
+ * Mantis plugin ColumnTags
+ *
+ * This model class represents the business logic associated with the ColumnTags plugin
+ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
+ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
+ * @link http://www.acc-solutions.ch
+ * @package model
+ */
+require_once ('ColumnTags.class.php');
+
+/**
+ * ColumnTags plugin class
+ */
+class ColumnTagsPlugin extends MantisPlugin {
+
+	/**
+	 * Define name, version etc. of custom plugin
+	 *
+	 * @return void
+	 */
+	public function register() {
+		$this->name = 'Column Tags';																# Proper name of plugin
+		$this->description = 'Allow usage of Tags as Column on View Issues Page, CSV export etc.';	# Short description of the plugin
+		$this->page = '';																			# Default plugin page (when clicking on manage plugin page)
+		$this->version = '1.0';																		# Plugin version string
+		$this->requires = array( 'MantisCore' => '1.2.0' );											# Plugin dependencies, array of basename => version pairs. Should always depend on an appropriate version of MantisBT
+		$this->author = 'ACC Solutions AG';															# Author/team name
+		$this->contact = 'dev@acc-solutions.ch';													# Author/team e-mail address
+		$this->url = 'http://www.acc-solutions.ch';													# Support webpage
+	}
+
+	/**
+	 * Plugin configuration options
+	 *
+	 * @return array
+	 */
+	function config( ) {
+		return array( );
+	}
+
+	/**
+	 * Declaration of events that this plugin will trigger
+	 *
+	 * @return void
+	 */
+	function events( ) {
+		return array( );
+	}
+
+	/**
+	 * Declaration (assignment) of hooks (which events triggers which function)
+	 *
+	 * @return void
+	 */
+	function hooks( ) {
+		return array( 'EVENT_FILTER_COLUMNS' => 'get_tags_column' );
+	}
+
+	/**
+	 * Plugin initialisation
+	 *
+	 * @return void
+	 */
+	function init( ) {
+	}
+
+	/**
+	 * Return tag column
+	 * Plugin specific function
+	 *
+	 * @param string $p_event event name triggering the method
+	 * @param string $p_bug_id bug id
+	 * @return string
+	 */
+	function get_tags_column( $p_event, $p_bug_id ) {
+		# must correspond to an existing class name
+		return array( 'ColumnTags' );
+	}
+}
-- 
1.7.3.1.msysgit.0


From e1e23da1ed7ea47de32cabb4af41017cff979725 Mon Sep 17 00:00:00 2001
From: Dominik Blunk <dominik@blunk.ch>
Date: Wed, 10 Nov 2010 14:34:02 +0100
Subject: [PATCH 2/2] Fetch table names from configuration for sorting query

---
 plugin_ColumnTags.patch                 |  241 +++++++++++++++++++++++++++++++
 plugins/ColumnTags/ColumnTags.class.php |    8 +-
 2 files changed, 246 insertions(+), 3 deletions(-)
 create mode 100644 plugin_ColumnTags.patch

diff --git a/plugin_ColumnTags.patch b/plugin_ColumnTags.patch
new file mode 100644
index 0000000..d3571c6
--- /dev/null
+++ b/plugin_ColumnTags.patch
@@ -0,0 +1,241 @@
+From ae8b6f5892fca750666dbd681063a5e52a86159b Mon Sep 17 00:00:00 2001
+From: Dominik Blunk <dominik@blunk.ch>
+Date: Wed, 10 Nov 2010 13:28:26 +0100
+Subject: [PATCH] This plugin allows the usage of "Tags" as column on pages like "view issues", "CSV export" or "Excel export".
+ After installing the plugin the column "tags" may be added/removed as usual under "Configuration - Manage Columns"
+
+---
+ csv_export.php                          |   14 +++++-
+ excel_xml_export.php                    |   14 +++++-
+ plugins/ColumnTags/ColumnTags.class.php |   80 ++++++++++++++++++++++++++++++
+ plugins/ColumnTags/ColumnTags.php       |   81 +++++++++++++++++++++++++++++++
+ 4 files changed, 187 insertions(+), 2 deletions(-)
+ create mode 100644 plugins/ColumnTags/ColumnTags.class.php
+ create mode 100644 plugins/ColumnTags/ColumnTags.php
+
+diff --git a/csv_export.php b/csv_export.php
+index 2116db2..0dbd2d1 100644
+--- a/csv_export.php
++++ b/csv_export.php
+@@ -113,7 +113,19 @@
+ 				echo csv_escape_string($t_value);
+ 			} else {
+ 				$t_function = 'csv_format_' . $t_column;
+-				echo $t_function( $t_row->$t_column );
++				if( function_exists( $t_function ) ) {
++					echo $t_function( $t_row->$t_column );
++				}
++				else {
++					ob_start();
++					$t_plugin_columns = columns_get_plugin_columns();
++					if ( isset( $t_plugin_columns[ $t_column ] ) ) {
++						$t_column_object = $t_plugin_columns[ $t_column ];
++						print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
++					}
++					$t_value = ob_get_clean();
++					echo csv_escape_string($t_value);
++				}
+ 			}
+ 		}
+ 
+diff --git a/excel_xml_export.php b/excel_xml_export.php
+index 13469e4..872ff70 100644
+--- a/excel_xml_export.php
++++ b/excel_xml_export.php
+@@ -94,7 +94,19 @@
+ 							echo excel_format_custom_field( $t_row->id, $t_row->project_id, $t_custom_field );
+ 						} else {
+ 							$t_function = 'excel_format_' . $t_column;
+-							echo $t_function( $t_row->$t_column );
++							if( function_exists( $t_function ) ) {
++								echo $t_function( $t_row->$t_column );
++							}
++							else {
++								ob_start();
++								$t_plugin_columns = columns_get_plugin_columns();
++								if ( isset( $t_plugin_columns[ $t_column ] ) ) {
++									$t_column_object = $t_plugin_columns[ $t_column ];
++									print_column_plugin( $t_column_object, $t_row, COLUMNS_TARGET_CSV_PAGE );
++								}
++								$t_value = ob_get_clean();
++								echo excel_prepare_string( $t_value );
++							}
+ 						}
+ 					}
+ 				}
+diff --git a/plugins/ColumnTags/ColumnTags.class.php b/plugins/ColumnTags/ColumnTags.class.php
+new file mode 100644
+index 0000000..5f2e6c1
+--- /dev/null
++++ b/plugins/ColumnTags/ColumnTags.class.php
+@@ -0,0 +1,80 @@
++<?php
++/**
++ * Class ColumnTags
++ *
++ * This model class represents the logic for the column "tags"
++ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
++ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
++ * @link http://www.acc-solutions.ch
++ * @package model
++ */
++
++/**
++ *	ColumnTags column class
++ */
++class ColumnTags extends MantisColumn {
++
++	/**
++	 * Column title, as displayed to the user.
++	 */
++	public $title = 'Tags';
++
++	/**
++	 * Column name, as selected in the manage columns interfaces.
++	 */
++	public $column = 'tags';
++
++	/**
++	 * Column is sortable by the user.  Setting this to true implies that
++	 * the column will properly implement the sortquery() method.
++	 */
++	public $sortable = true;
++
++	/**
++	 * Build the SQL query elements 'join' and 'order' as used by
++	 * core/filter_api.php to create the filter sorting query.
++	 * @param string Sorting order ('ASC' or 'DESC')
++	 * @return array Keyed-array with query elements; see developer guide
++	 */
++	public function sortquery( $p_dir ) {
++		$t_tags_table = db_get_table( 'mantis_tag_table' );
++		return array( 'join' => 'left join mantis_bug_tag_table on (mantis_bug_table.id = mantis_bug_tag_table.bug_id)
++								left join mantis_tag_table on (mantis_tag_table.id = mantis_bug_tag_table.tag_id)',
++					  'order' => 'mantis_tag_table.name ' . $p_dir );
++	}
++
++	/**
++	 * Allow plugin columns to pre-cache data for all issues
++	 * that will be shown in a given view.  This is preferable to
++	 * the alternative option of querying the database for each
++	 * issue as the display() method is called.
++	 * @param array Bug objects
++	 */
++	public function cache( $p_bugs ) {}
++
++	/**
++	 * Function to display column data for a given bug row.
++	 * @param object Bug object
++	 * @param int Column display target
++	 */
++	public function display( $p_bug, $p_columns_target ) {
++		$t_tags = tag_bug_get_attached($p_bug->id);
++		if ($p_columns_target == COLUMNS_TARGET_CSV_PAGE) {
++			$i = 0;
++			foreach( $t_tags as $t_tag ) {
++				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
++				print ( string_display( $t_tag['name'] ) );
++				$i++;
++			}
++		}
++		else {
++			$i = 0;
++			foreach( $t_tags as $t_tag ) {
++				print( $i > 0 ? config_get( 'tag_separator' ) . ' ' : '' );
++				tag_display_link( $t_tag );
++				$i++;
++			}
++		}
++	}
++}
++
+diff --git a/plugins/ColumnTags/ColumnTags.php b/plugins/ColumnTags/ColumnTags.php
+new file mode 100644
+index 0000000..4ba6651
+--- /dev/null
++++ b/plugins/ColumnTags/ColumnTags.php
+@@ -0,0 +1,81 @@
++<?PHP
++/**
++ * Mantis plugin ColumnTags
++ *
++ * This model class represents the business logic associated with the ColumnTags plugin
++ * @author Dominik Blunk <dominik.blunk@acc-solutions.ch>
++ * @copyright Copyright (c) 2010 - 2011, ACC Solutions AG
++ * @link http://www.acc-solutions.ch
++ * @package model
++ */
++require_once ('ColumnTags.class.php');
++
++/**
++ * ColumnTags plugin class
++ */
++class ColumnTagsPlugin extends MantisPlugin {
++
++	/**
++	 * Define name, version etc. of custom plugin
++	 *
++	 * @return void
++	 */
++	public function register() {
++		$this->name = 'Column Tags';																# Proper name of plugin
++		$this->description = 'Allow usage of Tags as Column on View Issues Page, CSV export etc.';	# Short description of the plugin
++		$this->page = '';																			# Default plugin page (when clicking on manage plugin page)
++		$this->version = '1.0';																		# Plugin version string
++		$this->requires = array( 'MantisCore' => '1.2.0' );											# Plugin dependencies, array of basename => version pairs. Should always depend on an appropriate version of MantisBT
++		$this->author = 'ACC Solutions AG';															# Author/team name
++		$this->contact = 'dev@acc-solutions.ch';													# Author/team e-mail address
++		$this->url = 'http://www.acc-solutions.ch';													# Support webpage
++	}
++
++	/**
++	 * Plugin configuration options
++	 *
++	 * @return array
++	 */
++	function config( ) {
++		return array( );
++	}
++
++	/**
++	 * Declaration of events that this plugin will trigger
++	 *
++	 * @return void
++	 */
++	function events( ) {
++		return array( );
++	}
++
++	/**
++	 * Declaration (assignment) of hooks (which events triggers which function)
++	 *
++	 * @return void
++	 */
++	function hooks( ) {
++		return array( 'EVENT_FILTER_COLUMNS' => 'get_tags_column' );
++	}
++
++	/**
++	 * Plugin initialisation
++	 *
++	 * @return void
++	 */
++	function init( ) {
++	}
++
++	/**
++	 * Return tag column
++	 * Plugin specific function
++	 *
++	 * @param string $p_event event name triggering the method
++	 * @param string $p_bug_id bug id
++	 * @return string
++	 */
++	function get_tags_column( $p_event, $p_bug_id ) {
++		# must correspond to an existing class name
++		return array( 'ColumnTags' );
++	}
++}
+-- 
+1.7.3.1.msysgit.0
+
diff --git a/plugins/ColumnTags/ColumnTags.class.php b/plugins/ColumnTags/ColumnTags.class.php
index 5f2e6c1..e9d381d 100644
--- a/plugins/ColumnTags/ColumnTags.class.php
+++ b/plugins/ColumnTags/ColumnTags.class.php
@@ -37,10 +37,12 @@ class ColumnTags extends MantisColumn {
 	 * @return array Keyed-array with query elements; see developer guide
 	 */
 	public function sortquery( $p_dir ) {
+		$t_bug_tags_table = db_get_table( 'mantis_bug_tag_table' );
 		$t_tags_table = db_get_table( 'mantis_tag_table' );
-		return array( 'join' => 'left join mantis_bug_tag_table on (mantis_bug_table.id = mantis_bug_tag_table.bug_id)
-								left join mantis_tag_table on (mantis_tag_table.id = mantis_bug_tag_table.tag_id)',
-					  'order' => 'mantis_tag_table.name ' . $p_dir );
+		$t_bugs_table = db_get_table( 'mantis_bug_table' );
+		return array( 'join' => 'left join ' . $t_bug_tags_table . ' on (' . $t_bugs_table . '.id = ' . $t_bug_tags_table . '.bug_id)
+								left join ' . $t_tags_table . ' on (' . $t_tags_table . '.id = ' . $t_bug_tags_table . '.tag_id)',
+					  'order' => $t_tags_table . '.name ' . $p_dir );
 	}
 
 	/**
-- 
1.7.3.1.msysgit.0

dominik

dominik

2010-11-10 08:42

reporter   ~0027326

Attached a patch agains current master 1.2.x:

Plugin "ColumnTags" which allows the usage of the column "tags" on pages like "view issues", "CSV export" and "Excel export". Just install the plugin and configure the new column under "Configuration - Manage Columns" (as usual).

The mantis core files csv_export.php and excel_export.php needed a little change to call the plugin routines (if available)

Sorting is also supported.

Feedback is welcome!

Have fun
Dominik

Alain Frisch

Alain Frisch

2011-05-17 06:36

reporter   ~0028786

I've applied plugin_ColumnTags.patch (against Mantis 1.2.4) and installed the new plugin, but I cannot use the "tags" columns. I still get:

Field "view_issues" contains invalid field "tags".

Alain Frisch

Alain Frisch

2011-05-17 07:31

reporter   ~0028787

Sorry, it works fine. The name seems to be "columntags_tags", not "tags", though.

wayne_chen

wayne_chen

2011-05-25 22:46

reporter   ~0028836

Dear sir, I applied plugin_ColumnTags.patch (against Mantis 1.2.3). But failed to installed the plugin. There are some error message shown on the plugin page:

SYSTEM WARNING: include_once(/var/www/html/koobe/plugins/ColumnTags/ColumnTags.php) [function.include-once]: failed to open stream: Permission denied

SYSTEM WARNING: include_once() [function.include]: Failed opening '/var/www/html/koobe/plugins/ColumnTags/ColumnTags.php' for inclusion (include_path='/var/www/html/koobe/core/:/var/www/html/koobe/library:.:/usr/share/pear:/usr/share/php:/var/www/html/koobe/plugins/MantisGraph/core/')

I checked the permission, and all files have 755 right. Could anyone please give a hand? Many thanks!

vboctor

vboctor

2016-03-24 01:55

manager   ~0052853

PR: https://github.com/mantisbt/mantisbt/pull/747

Related Changesets

MantisBT: master 272624e1

2016-03-25 00:13:16

luke


Committer: vboctor Details Diff
Support tags column in View, Print, Csv, Excel

Fixes 0009096
mod - core/columns_api.php Diff File
mod - core/csv_api.php Diff File
mod - core/excel_api.php Diff File
mod - core/tag_api.php Diff File
mod - print_all_bug_page_word.php Diff File

Issue History

Date Modified Username Field Change
2008-04-22 04:08 timj New Issue
2008-07-13 15:32 vboctor Note Added: 0018459
2008-07-13 15:32 vboctor Status new => acknowledged
2009-03-18 22:31 djcarr Note Added: 0021106
2009-03-19 04:11 djcarr Note Edited: 0021106
2009-03-19 04:15 djcarr Note Edited: 0021106
2009-03-30 20:00 BrianEnigma File Added: mantis-1.1.6-add_tags.diff
2009-03-30 20:04 BrianEnigma Note Added: 0021323
2009-04-20 18:54 BrianEnigma Tag Attached: patch
2010-11-10 08:21 dominik File Added: plugin_ColumnTags.patch
2010-11-10 08:38 dominik File Added: plugin_ColumnTags_slightly_improved.patch
2010-11-10 08:42 dominik Note Added: 0027326
2011-05-17 06:36 Alain Frisch Note Added: 0028786
2011-05-17 07:31 Alain Frisch Note Added: 0028787
2011-05-25 22:46 wayne_chen Note Added: 0028836
2011-12-14 04:11 rombert Relationship added has duplicate 0011122
2014-10-30 12:43 atrol Relationship added has duplicate 0017822
2014-10-30 12:44 atrol Tag Attached: mantishub
2016-03-24 01:55 vboctor Assigned To => community
2016-03-24 01:55 vboctor Status acknowledged => assigned
2016-03-24 01:55 vboctor Note Added: 0052853
2016-03-24 01:59 vboctor Category customization => tagging
2016-03-25 00:15 vboctor Changeset attached => MantisBT master 272624e1
2016-03-25 00:15 vboctor Assigned To community => vboctor
2016-03-25 00:15 vboctor Status assigned => resolved
2016-03-25 00:15 vboctor Resolution open => fixed
2016-03-25 00:15 vboctor Fixed in Version => 1.3.0-rc.2
2016-03-27 09:53 atrol Target Version => 1.3.0-rc.2
2016-06-12 00:42 vboctor Status resolved => closed
2017-10-18 16:23 atrol Relationship added related to 0023494