CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Improve field separator option on Import/Export
Pages: [1]

Author Topic: Improve field separator option on Import/Export  (Read 887 times)

kimkennof

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
  • CiviCRM version: 4.1.3
  • CMS version: Drupal
  • MySQL version: 5
  • PHP version: 5.2
Improve field separator option on Import/Export
September 26, 2012, 03:31:07 am
Hi guys,

I'm new to CiviCRM but I am an experienced PHP / Drupal coder and have developed tons of modules / themes / stuff for clients.

One of these clients is now using CiviCRM in their Intranet and has asked me to correct / improve some functionality, such as Import / Export of Contacts and Contact searches. Currently you can set the field separator for Import / Export globally in the CiviCRM settings under "Localisation".

My client has asked to add a dropdown on the Contact Export form to permit the user to chose which field separator to use in the exported CSV file. I've did some research and came to the following conclusions:

1. Change the export task form to include a dropdown with separator characters.

File: /CRM/Export/Form/Select.php

  1. on line 259, add a dropdown with field separator options
  2. on line 375, change the way the exportComponents function is called, including the separator sign from our posted dropdown.


2. Change the export task class method "exportComponents" and add an extra parameter "fieldSeparator".

File: /CRM/Export/BAO/Export.php

  1. on line 67, add parameter "fieldSeparator=','"

  2. on line 1064, add parameter to function call "self::writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode);" to include "fieldSeparator".

  3. on line 1745, pass on parameter into function call "
CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode),
        $headerRows,
        $componentDetails,
        NULL,
        $writeHeader
      );"


3. Change the core export class and add an extra parameter "fieldSeparator"

File: /CRM/Core/Report/Excel.php

  1. on line 197, add a parameter to function writeCSVFile() to receive a "fieldSeparator". Set this parameter to a static class property for later usage.

  2. on line 57, check the static class property if if's properly filled in, otherwise fallback to $config->fieldSeparator;


Is this modification something the community can use, and if so, how would I have to proceed to contribute this change back to the community?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Improve field separator option on Import/Export
September 26, 2012, 04:40:50 am

yes. contributing this back would be great :)

since u've already changed the code, its quite easy:

1. Create an issue at http://issues.civicrm.org/

2. Attach your patch (ideally in unified format) to the issue.

3. Would really help if you can write a webtest with a couple of tests to ensure that your additions are working:

http://wiki.civicrm.org/confluence/display/CRM/Testing

The export set of tests are here:

http://svn.civicrm.org/civicrm/branches/v4.2/tests/phpunit/WebTest/Export/

Not sure what version you are using but using a more recent version would make it a lot easier to apply the patch

4. You can always ping us on #civicrm irc channel if you have any questions etc

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Improve field separator option on Import/Export

This forum was archived on 2017-11-26.