1.1.8 export description and additional information!WORKING!

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
jkordani
Posts: 8
Joined: 19 Oct 2009, 18:27

1.1.8 export description and additional information!WORKING!

Post by jkordani »

for mantis 1.1.8!!!!
I have created a custom functions file which houses the majority of the functionality necessary to include the description field and the additional info field when exporting to CSV only!!!!! now, from the users point of view, those columns behave exactly like the other native columns when exporting.
this necessitated slight additions to the filter api file and the cvs export file.

the changes are summed up here:
right before the cvs export function goes to fetch rows, it takes the current view filter (code as copied straight out of the api) and adds an attribute to the filter object, namely ['show_additional_fields'] => true. once this filter object is passed into the get rows function, an additional check is made for this attribute (and its state), and if the attribute is set to true, modifies the final sql query to include the fields in the bug_text_table, the table holding the additional info and description fields. After control passes back out to the cvs export function, the attribute is turned off. now, once the export function asks for column titles, it will correctly handle additional information and description fields, and once it asks for values, I strip all commas and newlines (windows and unix, sorry mac).

had I known that 1.1.8 was so old, i probably would have pushed for us to migrate to 1.2.0 rc latest, but.. oh well.

If anyone needs a patch for this, email me, or respond here, and I'll try to make up a generic patch. lord knows I wouldn't know what to do with it otherwise.

Good hunting!

Josh
Mimie
Posts: 22
Joined: 21 Dec 2010, 08:54

Re: 1.1.8 export description and additional information!WORK

Post by Mimie »

Hi jkordani,

Do you mean that you succesfully view other custom fields than the original field found in mantis_bug_table?

Can you specify the step-by-step what to do since I also trying to view some data from other tables, not just from mantis_bug_table also.
Would appreciate your help and explanation for this.

Thanks :)
jkordani
Posts: 8
Joined: 19 Oct 2009, 18:27

Re: 1.1.8 export description and additional information!WORK

Post by jkordani »

In 1.1.8, In the bug view page, the description and additional info fields are not included in bug exports. I added code to make this happen. I believe that custom fields are included by default.

Look up sql join. I had to add a join on the description table against the bug table when getting my fields, and that added the two columns I needed. Since I don't know what other tables you need to pull data from, I can't really give you step by step. I'll see if I can put a patch together and post it for you to review. It will take a few days.
Mimie
Posts: 22
Joined: 21 Dec 2010, 08:54

Re: 1.1.8 export description and additional information!WORK

Post by Mimie »

Ok, lots of thanks :)
jkordani
Posts: 8
Joined: 19 Oct 2009, 18:27

Re: 1.1.8 export description and additional information!WORK

Post by jkordani »

can't attach anything, can't send pms with files,
the download link for my custom functions files, and the patch diff is here:

http://ifile.it/a2ze34u

ignore the garbage text files, the zip was too small for their lower limit.

the patch file is a pair of diffs made against master 1.1.x. this means that it includes all the security features that were added since. I haven't tested it though, but I expect it to work.

also in here are the custom functions I used to do various things, like handle csv exporting and so on. I only wanted to do this to one of my projects so there is a check in there that will only apply to me. I left everything in for reference.

any questions let me know.
Mimie
Posts: 22
Joined: 21 Dec 2010, 08:54

Re: 1.1.8 export description and additional information!WORK

Post by Mimie »

Got it...and analyzing.

many thanks for your help :D
Will further you for any results and errors since i'm using 1.2.x version
jkordani
Posts: 8
Joined: 19 Oct 2009, 18:27

Re: 1.1.8 export description and additional information!WORK

Post by jkordani »

If you outline the problem you are trying to solve I might be able to help you more specifically.
Mimie
Posts: 22
Joined: 21 Dec 2010, 08:54

Re: 1.1.8 export description and additional information!WORK

Post by Mimie »

Hi, good news.

I manage to solve the CSV file by editing some lines at csv_export.php and columns_api

I want to add few field at csv report so i add the columns at columns_api, such that:

Code: Select all

function column_get_title( $p_column ) {
	/*.... some codes.....  Just leave the original codes there, no need to change anything*/
        
       /*Edit at this part*/
	switch( $p_column ) {
		/*...Leave the original case options...*/
		case 'view_state':
			return lang_get( 'view_status' );

		#Added By Mimie
		case 'add_column1':
			return 'My column 1';
                case 'add_column2':
			return 'My column 2';              

		default:
			return lang_get_defaulted( $p_column );
	}
}
And at csv_report.php, add the sql queries to call the row by the column value such that:

Code: Select all

auth_ensure_user_authenticated();

         #Added By Mimie
         #Copied from csv_api - function csv_escape_string( $p_str )
         #This is to make sure the arrangement of chars/long text is wrap in one field and not messed up to other column
         function fix_csv ($p_string){
             $p_str = '"' . str_replace( '"', '""', $p_string ) . '"';
             $p_string = str_replace(",",".",$p_string);
             $p_string = str_replace("<br />"," ",$p_string);
             $p_string = str_replace(""","\"",$p_string);
             $p_string = str_replace("\r\n"," ",$p_string);
             $p_string = str_replace("'"," ",$p_string);
        return $p_string;
        }

	helper_begin_long_process();
Then, at csv export also i called the columns, which i added at columns_api, by:

Code: Select all

# Added Quotes (") around file name.
	header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_filename ) ) . '"' );

	# Get columns to be exported
         #Added By Mimie
        $t_my_column_one = column_get_title('add_column1');
        $t_my column_two = column_get_title('add_column2');

        #This is the array contains value of column details for csv
	$t_columns = csv_get_columns();

        #Added By Mimie
        #I use array_splice function to put my column at specific position in the array.
        #Can also use array_push function to simply put the value to the array
        #Can refer php tutorial/forum
        array_splice($t_columns, -1, 0,array( $t_my_column_one,$t_my_column_two));
        array_splice($t_columns, 10, 0,  $t_my_column_one);
        
       	# export the titles
	$t_first_column = true;
Then, i want to put my rows value that belong to the column, such that:

Code: Select all

# export the rows

	foreach ( $t_rows as $t_row ) {
		$t_first_column = true;


		foreach ( $t_columns as $t_column ) {
			if ( !$t_first_column ) {
				
				echo $t_sep;
				
			} else
				$t_first_column = false;

			$t_custom_field = column_get_custom_field_name( $t_column );
			if ( $t_custom_field !== null ) {
				ob_start();
				$t_column_value_function = 'print_column_value';
				helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
				$t_value = ob_get_clean();
				
				echo csv_escape_string($t_value);
				
			} else if ($t_column == 'My column 1'){

                           $the_bug = $t_row->id;

                           $query = "select column_one from mantis_project_table
                                        where id = '$the_bug'";

                            $result = db_query($query);
                            $row = db_result($result);
                           
                            echo fix_csv($row);
                            
                        }else if ($t_column == 'My column 2'){

                           $the_bug = $t_row->id;

                           $query = "select column_two from mantis_project_table
                                        where id = '$the_bug'";

                            $result = db_query($query);
                            $row = db_result($result);
                            
                            echo fix_csv($row);
                            
                        }
                        else
                            {
				$t_function = 'csv_format_' . $t_column;
				echo $t_function( $t_row->$t_column );

			}
		}echo $t_nl;		
	}
So there you go, I've successfully added new row to my CSV file.
Thanks alot for jkordani help. His method has given me to this idea. :D
jkordani
Posts: 8
Joined: 19 Oct 2009, 18:27

Re: 1.1.8 export description and additional information!WORK

Post by jkordani »

You're welcome! Glad you got it working.

Are you looking to track native mantis data in your csv reports, or are you integrating a foreign (or modified) database?
Mimie
Posts: 22
Joined: 21 Dec 2010, 08:54

Re: 1.1.8 export description and additional information!WORK

Post by Mimie »

For the CSV, I'm looking to track native mantis data as well as integrating to the modified database.
This is because I want to refer to where the issue link to such as some project details, notes, attachments..etc
ShawnPaul
Posts: 4
Joined: 17 Jan 2012, 14:59

Re: 1.1.8 export description and additional information!WORK

Post by ShawnPaul »

@Jkordani, could you please repost your custom functions files, and the patch diff ? The link above is dead. I am trying to add/export a column from the bugnote table. Thanks.
Post Reply