1.1.8 export description and additional information!WORKING!

Post about your customizations to share with others.

Moderators: Developer, Contributor

1.1.8 export description and additional information!WORKING!

Postby jkordani » Jan 19, 2010 7:05 am

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
jkordani
 
Posts: 8
Joined: Oct 19, 2009 1:27 pm

Re: 1.1.8 export description and additional information!WORK

Postby Mimie » Feb 24, 2011 9:08 pm

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 :)
Mimie
 
Posts: 22
Joined: Dec 21, 2010 3:54 am

Re: 1.1.8 export description and additional information!WORK

Postby jkordani » Feb 25, 2011 7:52 am

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.
jkordani
 
Posts: 8
Joined: Oct 19, 2009 1:27 pm

Re: 1.1.8 export description and additional information!WORK

Postby Mimie » Mar 01, 2011 2:56 am

Ok, lots of thanks :)
Mimie
 
Posts: 22
Joined: Dec 21, 2010 3:54 am

Re: 1.1.8 export description and additional information!WORK

Postby jkordani » Mar 03, 2011 1:33 pm

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.
jkordani
 
Posts: 8
Joined: Oct 19, 2009 1:27 pm

Re: 1.1.8 export description and additional information!WORK

Postby Mimie » Mar 03, 2011 9:44 pm

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
Mimie
 
Posts: 22
Joined: Dec 21, 2010 3:54 am

Re: 1.1.8 export description and additional information!WORK

Postby jkordani » Mar 04, 2011 1:47 pm

If you outline the problem you are trying to solve I might be able to help you more specifically.
jkordani
 
Posts: 8
Joined: Oct 19, 2009 1:27 pm

Re: 1.1.8 export description and additional information!WORK

Postby Mimie » Mar 13, 2011 8:44 pm

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("&quot;","\"",$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
Mimie
 
Posts: 22
Joined: Dec 21, 2010 3:54 am

Re: 1.1.8 export description and additional information!WORK

Postby jkordani » Mar 13, 2011 9:51 pm

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?
jkordani
 
Posts: 8
Joined: Oct 19, 2009 1:27 pm

Re: 1.1.8 export description and additional information!WORK

Postby Mimie » Mar 15, 2011 1:50 am

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
Mimie
 
Posts: 22
Joined: Dec 21, 2010 3:54 am

Re: 1.1.8 export description and additional information!WORK

Postby ShawnPaul » Jan 25, 2012 4:21 am

@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.
ShawnPaul
 
Posts: 4
Joined: Jan 17, 2012 9:59 am


Return to Customizations

Who is online

Users browsing this forum: Google [Bot] and 5 guests