0011282: Translate salutation in xml export
authorsstamer <s.stamer@metaways.de>
Tue, 9 Jun 2015 10:26:18 +0000 (12:26 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 31 Aug 2015 14:09:07 +0000 (16:09 +0200)
https://forge.tine20.org/view.php?id=11282

Change-Id: I6964e41cc457d79b5c7584e62f64c1edea7a0aa3
Reviewed-on: http://gerrit.tine20.com/customers/2107
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/Export/definitions/adb_translation_xls_test.xml [new file with mode: 0644]
tests/tine20/Addressbook/JsonTest.php
tine20/Addressbook/Export/definitions/adb_default_xls.xml
tine20/Tinebase/Export/Abstract.php
tine20/Tinebase/Export/Spreadsheet/Abstract.php

diff --git a/tests/tine20/Addressbook/Export/definitions/adb_translation_xls_test.xml b/tests/tine20/Addressbook/Export/definitions/adb_translation_xls_test.xml
new file mode 100644 (file)
index 0000000..ff98b06
--- /dev/null
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+    <model>Addressbook_Model_Contact</model>
+    <name>adb_translation_xls_test</name>
+    <type>export</type>
+    <plugin>Addressbook_Export_Xls</plugin>
+    <label>Default Excel Export</label>
+    <description>default xls contact export definition</description>
+    <header>1</header>
+    <columns>
+        <column>
+            <identifier>adr_one_countryname</identifier>
+        </column>
+        <column>
+            <identifier>adr_one_locality</identifier>
+        </column>
+            <column>
+            <identifier>adr_one_postalcode</identifier>
+        </column>
+        <column>
+            <identifier>adr_one_region</identifier>
+        </column>
+        <column>
+            <identifier>adr_one_street</identifier>
+        </column>
+        <column>
+            <identifier>adr_one_street2</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_countryname</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_locality</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_postalcode</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_region</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_street</identifier>
+        </column>
+        <column>
+            <identifier>adr_two_street2</identifier>
+        </column>
+        <column>
+            <identifier>assistent</identifier>
+        </column>
+        <column>
+            <identifier>bday</identifier>
+        </column>
+        <column>
+            <identifier>calendar_uri</identifier>
+        </column>
+        <column>
+            <identifier>email</identifier>
+        </column>
+        <column>
+            <identifier>email_home</identifier>
+        </column>
+        <column>
+            <identifier>freebusy_uri</identifier>
+        </column>
+        <column>
+            <identifier>note</identifier>
+        </column>
+        <column>
+            <identifier>container_id</identifier>
+        </column>
+        <column>
+            <identifier>pubkey</identifier>
+        </column>
+        <column>
+            <identifier>role</identifier>
+        </column>
+        <column>
+            <identifier>room</identifier>
+        </column>
+        <column>
+            <identifier>salutation</identifier>
+            <type>keyfield</type>
+            <keyfield>contactSalutation</keyfield>
+            <application>Addressbook</application>
+        </column>
+        <column>
+            <identifier>title</identifier>
+        </column>
+        <column>
+            <identifier>tz</identifier>
+        </column>
+        <column>
+            <identifier>url</identifier>
+        </column>
+        <column>
+            <identifier>url_home</identifier>
+        </column>
+        <column>
+            <identifier>n_family</identifier>
+        </column>
+        <column>
+            <identifier>n_fileas</identifier>
+        </column>
+        <column>
+            <identifier>n_fn</identifier>
+        </column>
+        <column>
+            <identifier>n_given</identifier>
+        </column>
+        <column>
+            <identifier>n_middle</identifier>
+        </column>
+        <column>
+            <identifier>n_prefix</identifier>
+        </column>
+        <column>
+            <identifier>n_suffix</identifier>
+        </column>
+        <column>
+            <identifier>org_name</identifier>
+        </column>
+        <column>
+            <identifier>org_unit</identifier>
+        </column>
+        <column>
+            <identifier>tel_assistent</identifier>
+        </column>
+        <column>
+            <identifier>tel_car</identifier>
+        </column>
+        <column>
+            <identifier>tel_cell</identifier>
+        </column>
+        <column>
+            <identifier>tel_cell_private</identifier>
+        </column>
+        <column>
+            <identifier>tel_fax</identifier>
+        </column>
+        <column>
+            <identifier>tel_fax_home</identifier>
+        </column>
+        <column>
+            <identifier>tel_home</identifier>
+        </column>
+        <column>
+            <identifier>tel_pager</identifier>
+        </column>
+        <column>
+            <identifier>tel_work</identifier>
+        </column>
+        <column>
+            <identifier>lon</identifier>
+        </column>
+        <column>
+            <identifier>lat</identifier>
+        </column>
+        <column>
+            <identifier>created_by</identifier>
+        </column>
+        <column>
+            <identifier>creation_time</identifier>
+        </column>
+        <column>
+            <identifier>last_modified_by</identifier>
+        </column>
+        <column>
+            <identifier>last_modified_time</identifier>
+        </column>
+        <column>
+            <identifier>tags</identifier>
+            <type>tags</type>
+        </column>
+    </columns>
+</config>
index 0d28d9f..aaf4cb1 100644 (file)
@@ -704,6 +704,38 @@ class Addressbook_JsonTest extends TestCase
     }
     
     /**
+     * testExportXlsWithTranslation
+     *
+     */
+    public function testExportXlsWithTranslation()
+    {
+        $instance = new Tinebase_Frontend_Json();
+        $instance->setLocale('de', FALSE, FALSE);
+        
+        $filter = new Addressbook_Model_ContactFilter(array(array(
+                'field'    => 'n_fileas',
+                'operator' => 'equals',
+                'value'    =>  Tinebase_Core::getUser()->accountDisplayName
+        )));
+        
+        $ownContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId());
+        $ownContact->salutation = 'MR';
+        Addressbook_Controller_Contact::getInstance()->update($ownContact);
+        
+        $definition = dirname(__FILE__) . '/Export/definitions/adb_translation_xls_test.xml';
+        $exporter = new Addressbook_Export_Xls($filter, Addressbook_Controller_Contact::getInstance(), array('definitionFilename' => $definition));
+        $doc = $exporter->generate();
+        
+        $xlswriter = PHPExcel_IOFactory::createWriter($doc, 'CSV');
+        ob_start();
+        $xlswriter->save('php://output');
+        $out = ob_get_clean();
+        
+        $this->assertContains(Tinebase_Core::getUser()->accountDisplayName, $out, 'display name not found.');
+        $this->assertContains('Herr', $out, 'no translated salutation found.');
+    }
+    
+    /**
      * each tag should have an own column
      */
     public function testExportOdsWithTagMatrix()
index e195102..58cd031 100644 (file)
@@ -79,6 +79,9 @@
         </column>
         <column>
             <identifier>salutation</identifier>
+            <type>keyfield</type>
+            <keyfield>contactSalutation</keyfield>
+            <application>Addressbook</application>
         </column>
         <column>
             <identifier>title</identifier>
index 06d6808..aea5ee4 100644 (file)
@@ -447,6 +447,22 @@ abstract class Tinebase_Export_Abstract
     }
     
     /**
+     * return translated Keyfield string
+     *
+     * @param String $_property
+     * @param String $_keyfield
+     * @param String $_application
+     * @return string
+     */
+    protected function _getResolvedKeyfield($_property, $_keyfield, $_application)
+    {
+         $i18nApplication = Tinebase_Translation::getTranslation($_application);
+         $config = Tinebase_Config::getAppConfig($_application);
+         $result = $config::getInstance()->get($_keyfield)->records->getById($_property);
+         return isset($result->value) ? $i18nApplication->translate($result->value) : $_property;
+    }
+    
+    /**
      * 
      * return container name (or other field)
      * 
index 3077d5d..770ab12 100644 (file)
@@ -140,6 +140,9 @@ abstract class Tinebase_Export_Spreadsheet_Abstract extends Tinebase_Export_Abst
             case 'tags':
                 $result = $this->_getTags($_record);
                 break;
+            case 'keyfield':
+                $result = $this->_getResolvedKeyfield($_record->{$_field->identifier}, $_field->keyfield, $_field->application);
+                break;
             case 'currency':
                 $currency = ($_field->currency) ? $_field->currency : 'EUR';
                 $result =  ($_record->{$_field->identifier}) ? $_record->{$_field->identifier} : '0';