Export: allow keyfield translations in related records
authorsstamer <s.stamer@metaways.de>
Tue, 2 Feb 2016 12:44:11 +0000 (13:44 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 3 Feb 2016 14:11:16 +0000 (15:11 +0100)
Change-Id: Ie7aa143fd4d4079beb09dd377258058566aaa5a3
Reviewed-on: http://gerrit.tine20.com/customers/2654
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Crm/Export/XlsTest.php
tine20/Crm/Export/Helper.php
tine20/Tinebase/Export/Abstract.php
tine20/Tinebase/Export/Spreadsheet/Abstract.php

index 0671c05..4ff2244 100644 (file)
@@ -63,6 +63,7 @@ class Crm_Export_XlsTest extends Crm_Export_AbstractTest
      */
     public function testExportXls()
     {
+        $translate = Tinebase_Translation::getTranslation('Crm');
         $excelObj = $this->_instance->generate();
         
         // output as csv
@@ -79,7 +80,7 @@ class Crm_Export_XlsTest extends Crm_Export_AbstractTest
         $this->assertEquals(1, preg_match("/PHPUnit/",                          $export), 'no name');
         $this->assertEquals(1, preg_match("/Description/",                      $export), 'no description');
         $this->assertEquals(1, preg_match('/' . preg_quote(Tinebase_Core::getUser()->accountDisplayName) . '/',          $export), 'no creator');
-        $this->assertEquals(1, preg_match('/open/',                             $export), 'no leadstate');
+        $this->assertEquals(1, preg_match('/' . $translate->_('open') . '/',    $export), 'no leadstate');
         
         unlink($csvFilename);
     }
index 6abc2e2..c32e4ca 100644 (file)
@@ -60,25 +60,15 @@ class Crm_Export_Helper
         
         switch($_param['type']) {
             case 'status':
-                $value = $_record->getLeadStatus();
-                break;
             case 'source':
-                $settings = Crm_Controller::getInstance()->getConfigSettings();
-                $source = $settings->getOptionById($_record->leadsource_id, 'leadsources');
-                if (isset($source['leadsource'])) {
-                    $value = $source['leadsource'];
-                } else {
-                    Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Leadsource id not found:' . $_record->leadsource_id);
-                    $value = '';
-                }
-                break;
             case 'type':
+                $leadIdType = $_param['type'] == 'status' ? 'leadstate' : 'lead' . $_param['type'];
                 $settings = Crm_Controller::getInstance()->getConfigSettings();
-                $type = $settings->getOptionById($_record->leadtype_id, 'leadtypes');
-                if (isset($type['leadtype'])) {
-                    $value = $type['leadtype'];
+                $source = $settings->getOptionById($_record->{$leadIdType . '_id'}, $leadIdType . 's');
+                if (isset($source[$leadIdType])) {
+                    $value = $source[$leadIdType];
                 } else {
-                    Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Leadtype id not found:' . $_record->leadtype_id);
+                    Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . $leadIdType . ' id not found:' . $_record->{$leadIdType . '_id'});
                     $value = '';
                 }
                 break;
index 40d1f84..e0f4ee5 100644 (file)
@@ -494,7 +494,7 @@ abstract class Tinebase_Export_Abstract
      * @param boolean $onlyFirstRelation
      * @return string
      */
-    protected function _addRelations(Tinebase_Record_Abstract $record, $relationType, $recordField = NULL, $onlyFirstRelation = FALSE)
+    protected function _addRelations(Tinebase_Record_Abstract $record, $relationType, $recordField = NULL, $onlyFirstRelation = FALSE, $keyfield = NULL, $application = NULL)
     {
         $record->relations->addIndices(array('type'));
         $matchingRelations = $record->relations->filter('type', $relationType);
@@ -505,7 +505,13 @@ abstract class Tinebase_Export_Abstract
         $resultArray = array();
         foreach ($matchingRelations as $relation) {
             if ($recordField !== NULL) {
-                $resultArray[] = $relation->related_record->{$recordField};
+                if ($keyfield !== NULL && $application !== NULL) {
+                    // special case where we want to translate a keyfield
+                    $result = $this->_getResolvedKeyfield($relation->related_record->{$recordField}, $keyfield, $application);
+                } else {
+                    $result = $relation->related_record->{$recordField};
+                }
+                $resultArray[] = $result;
             } else {
                 $resultArray[] = $this->_getRelationSummary($relation->related_record);
             }
index 12fbaba..04725b1 100644 (file)
@@ -164,7 +164,9 @@ abstract class Tinebase_Export_Spreadsheet_Abstract extends Tinebase_Export_Abst
                     $_record,
                     /* $relationType = */       $_field->identifier,
                     /* $recordField = */        $_field->field,
-                    /* $onlyFirstRelation = */  isset($_field->onlyfirst) ? $_field->onlyfirst : false
+                    /* $onlyFirstRelation = */  isset($_field->onlyfirst) ? $_field->onlyfirst : false,
+                    /* $keyfield = */            isset($_field->keyfield) ? $_field->keyfield : NULL,
+                    /* $application = */        isset($_field->application) ? $_field->application : NULL
                 );
                 break;
             case 'notes':