0010020: Allow to define the default export definition
authorAlexander Stintzing <a.stintzing@metaways.de>
Wed, 2 Jul 2014 10:37:41 +0000 (12:37 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 9 Jul 2014 17:00:18 +0000 (19:00 +0200)
the default export definition should be configurable in preferences

https://forge.tine20.org/mantisbt/view.php?id=10020

Change-Id: I729c4e5dbc0cacef7090922c102439f4dc5acbe7
Reviewed-on: http://gerrit.tine20.com/customers/815
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Export/Ods.php
tine20/Addressbook/Export/Xls.php
tine20/Addressbook/Preference.php

index 6688ee6..49577f4 100644 (file)
 class Addressbook_Export_Ods extends Tinebase_Export_Spreadsheet_Ods
 {
     /**
+     * the constructor
+     *
+     * @param Tinebase_Model_Filter_FilterGroup $_filter
+     * @param Tinebase_Controller_Record_Interface $_controller (optional)
+     * @param array $_additionalOptions (optional) additional options
+     */
+    public function __construct(Tinebase_Model_Filter_FilterGroup $_filter, Tinebase_Controller_Record_Interface $_controller = NULL, $_additionalOptions = array())
+    {
+        $this->_prefKey = Addressbook_Preference::DEFAULT_CONTACT_ODS_EXPORTCONFIG;
+    
+        parent::__construct($_filter, $_controller, $_additionalOptions);
+    }
+    
+    /**
      * @var string application of this export class
      */
     protected $_applicationName = 'Addressbook';
index e21d00b..a6d8661 100644 (file)
 class Addressbook_Export_Xls extends Tinebase_Export_Spreadsheet_Xls
 {
     /**
+     * the constructor
+     *
+     * @param Tinebase_Model_Filter_FilterGroup $_filter
+     * @param Tinebase_Controller_Record_Interface $_controller (optional)
+     * @param array $_additionalOptions (optional) additional options
+     */
+    public function __construct(Tinebase_Model_Filter_FilterGroup $_filter, Tinebase_Controller_Record_Interface $_controller = NULL, $_additionalOptions = array())
+    {
+        $this->_prefKey = Addressbook_Preference::DEFAULT_CONTACT_XLS_EXPORTCONFIG;
+        parent::__construct($_filter, $_controller, $_additionalOptions);
+    }
+    
+    /**
      * @var string $_applicationName
      */
     protected $_applicationName = 'Addressbook';
index df89c59..3d75201 100644 (file)
@@ -30,6 +30,20 @@ class Addressbook_Preference extends Tinebase_Preference_Abstract
     const DEFAULTPERSISTENTFILTER_NAME = "All contacts";
     
     /**
+     * the default ods export configuration
+     * 
+     * @var string
+     */
+    const DEFAULT_CONTACT_ODS_EXPORTCONFIG = 'defaultContactODSExportconfig';
+    
+    /**
+     * the default xls export configuration
+     *
+     * @var string
+     */
+    const DEFAULT_CONTACT_XLS_EXPORTCONFIG = 'defaultContactXLSExportconfig';
+    
+    /**
      * @var string application
      */
     protected $_application = 'Addressbook';
@@ -46,6 +60,8 @@ class Addressbook_Preference extends Tinebase_Preference_Abstract
         $allPrefs = array(
             self::DEFAULTADDRESSBOOK,
             self::DEFAULTPERSISTENTFILTER,
+            self::DEFAULT_CONTACT_ODS_EXPORTCONFIG,
+            self::DEFAULT_CONTACT_XLS_EXPORTCONFIG
         );
         
         return $allPrefs;
@@ -69,6 +85,14 @@ class Addressbook_Preference extends Tinebase_Preference_Abstract
                 'label'         => $translate->_('Default Favorite'),
                 'description'   => $translate->_('The default favorite which is loaded on addressbook startup'),
             ),
+            self::DEFAULT_CONTACT_ODS_EXPORTCONFIG  => array(
+                'label'         => $translate->_('Contacts ODS export configuration'),
+                'description'   => $translate->_('Use this configuration for the contact ODS export.'),
+            ),
+            self::DEFAULT_CONTACT_XLS_EXPORTCONFIG  => array(
+                'label'         => $translate->_('Contacts XLS export configuration'),
+                'description'   => $translate->_('Use this configuration for the contact XLS export.'),
+            ),
         );
         
         return $prefDescriptions;
@@ -93,10 +117,55 @@ class Addressbook_Preference extends Tinebase_Preference_Abstract
             case self::DEFAULTPERSISTENTFILTER:
                 $preference->value          = Tinebase_PersistentFilter::getPreferenceValues('Addressbook', $_accountId, self::DEFAULTPERSISTENTFILTER_NAME);
                 break;
+            case self::DEFAULT_CONTACT_ODS_EXPORTCONFIG:
+                $preference->value      = 'adb_default_ods';
+                break;
+            case self::DEFAULT_CONTACT_XLS_EXPORTCONFIG:
+                $preference->value      = 'adb_default_xls';
+                break;
             default:
                 throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');
         }
         
         return $preference;
     }
+    
+    /**
+     * get special options
+     *
+     * @param string $_value
+     * @return array
+     */
+    protected function _getSpecialOptions($_value)
+    {
+        $translate = Tinebase_Translation::getTranslation($this->_application);
+    
+        $result = array();
+        switch($_value) {
+            case self::DEFAULT_CONTACT_ODS_EXPORTCONFIG:
+            case self::DEFAULT_CONTACT_XLS_EXPORTCONFIG:
+                if ($value == self::DEFAULT_CONTACT_XLS_EXPORTCONFIG) {
+                    $plugin = 'Addressbook_Export_Xls';
+                } else {
+                    $plugin = 'Addressbook_Export_Ods';
+                }
+                // get names from import export definitions
+                $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(
+                array('field' => 'plugin', 'operator' => 'equals', 'value' => $plugin),
+                ));
+                $configs = Tinebase_ImportExportDefinition::getInstance()->search($filter);
+                if (! empty($configs)) {
+                    foreach($configs as $tsConfig) {
+                        $result[] = array($tsConfig->name, $tsConfig->name);
+                    }
+                } else {
+                    $result[] = array('default', $translate->_('default'));
+                }
+                break;
+            default:
+                $result = parent::_getSpecialOptions($_value);
+        }
+    
+        return $result;
+    }
 }