Export Addressbook List - fix definition, export members and roles
authorPaul Mehrer <p.mehrer@metaways.de>
Wed, 26 Jul 2017 14:54:08 +0000 (16:54 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Thu, 27 Jul 2017 08:40:14 +0000 (10:40 +0200)
members and their roles in the list are written into one colon separated list
in the property memberroles

Change-Id: I019581fe2a6f7b846bf74f8b521bfe89b45e9467
Reviewed-on: http://gerrit.tine20.com/customers/5332
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tine20/Addressbook/Export/List/Doc.php
tine20/Addressbook/Export/List/Trait.php [new file with mode: 0644]
tine20/Addressbook/Export/List/Xls.php
tine20/Addressbook/Export/Xls.php
tine20/Addressbook/Export/definitions/adb_list_doc.xml
tine20/Addressbook/Export/definitions/adb_list_overview_xls.xml
tine20/Addressbook/Export/definitions/adb_list_xls.xml
tine20/Addressbook/Export/templates/addressbook_list_overview.xlsx
tine20/Tinebase/Export/Abstract.php

index 010507d..bb27519 100644 (file)
@@ -19,5 +19,7 @@
  */
 class Addressbook_Export_List_Doc extends Tinebase_Export_Doc
 {
+    use Addressbook_Export_List_Trait;
+
     protected $_defaultExportname = 'adb_list_doc';
 }
diff --git a/tine20/Addressbook/Export/List/Trait.php b/tine20/Addressbook/Export/List/Trait.php
new file mode 100644 (file)
index 0000000..b8c0c0e
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Addressbook List Export trait
+ *
+ * @package     Addressbook
+ * @subpackage  Export
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Paul Mehrer <p.mehrer@metaways.de>
+ * @copyright   Copyright (c) 2017-2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ */
+
+trait Addressbook_Export_List_Trait
+{
+    /**
+     * resolve records and prepare for export (set user timezone, ...)
+     *
+     * @param Tinebase_Record_RecordSet $_records
+     */
+    protected function _resolveRecords(Tinebase_Record_RecordSet $_records)
+    {
+        parent::_resolveRecords($_records);
+
+        /** @var Addressbook_Model_List $record */
+        foreach ($_records as $record) {
+            $memberRolesBackend = Addressbook_Controller_List::getInstance()->getMemberRolesBackend();
+            $filter = new Addressbook_Model_ListMemberRoleFilter(array(
+                array('field' => 'list_id',      'operator' => 'equals', 'value' => $record->getId())
+            ));
+
+            $members = array();
+            $listRoles = array();
+            /** @var Addressbook_Model_ListMemberRole $listMemberRole */
+            foreach($memberRolesBackend->search($filter) as $listMemberRole)
+            {
+                if (!isset($members[$listMemberRole->contact_id])) {
+                    $members[$listMemberRole->contact_id] = array();
+                }
+                $members[$listMemberRole->contact_id][] = $listMemberRole->list_role_id;
+                $listRoles[$listMemberRole->list_role_id] = true;
+            }
+
+            if (count($listRoles) > 0) {
+                $listRoles = Addressbook_Controller_ListRole::getInstance()->getMultiple(array_keys($listRoles));
+            }
+
+            $memberRecords = array();
+            if (is_array($record->members)) {
+                $memberRecords = Addressbook_Controller_Contact::getInstance()->getMultiple($record->members);
+            }
+
+            $str = '';
+            /** @var Addressbook_Model_Contact $contact */
+            foreach($memberRecords as $contact) {
+                $str .= ($str===''?'':', ') . $contact->n_fn;
+                if (isset($members[$contact->getId()])) {
+                    $str .= ' (';
+                    $first = true;
+                    foreach($members[$contact->getId()] as $listRole) {
+                        /** @var Addressbook_Model_ListRole $listRole */
+                        if (null !== ($listRole = $listRoles->getById($listRole))) {
+                            $str .= (true===$first?'':', ') . $listRole->name;
+                            $first = false;
+                        }
+                    }
+                    $str .= ')';
+                }
+            }
+
+            $record->memberroles = $str;
+        }
+    }
+}
\ No newline at end of file
index b351302..13ffb46 100644 (file)
  */
 class Addressbook_Export_List_Xls extends Tinebase_Export_Xls
 {
-    protected $_defaultExportname = 'adb_list_xls';
-
-    /**
-     * resolve records and prepare for export (set user timezone, ...)
-     *
-     * @param Tinebase_Record_RecordSet $_records
-     */
-    protected function _resolveRecords(Tinebase_Record_RecordSet $_records)
-    {
-        parent::_resolveRecords($_records);
-
-        /** @var Addressbook_Model_List $record */
-        foreach ($_records as $record) {
-            $memberRolesBackend = Addressbook_Controller_List::getInstance()->getMemberRolesBackend();
-            $filter = new Addressbook_Model_ListMemberRoleFilter(array(
-                array('field' => 'list_id',      'operator' => 'equals', 'value' => $record->getId())
-            ));
-
-            $members = array();
-            $listRoles = array();
-            /** @var Addressbook_Model_ListMemberRole $listMemberRole */
-            foreach($memberRolesBackend->search($filter) as $listMemberRole)
-            {
-                if (!isset($members[$listMemberRole->contact_id])) {
-                    $members[$listMemberRole->contact_id] = array();
-                }
-                $members[$listMemberRole->contact_id][] = $listMemberRole->list_role_id;
-                $listRoles[$listMemberRole->list_role_id] = true;
-            }
+    use Addressbook_Export_List_Trait;
 
-            if (count($listRoles) > 0) {
-                $listRoles = Addressbook_Controller_ListRole::getInstance()->getMultiple(array_keys($listRoles));
-            }
-
-            $memberRecords = array();
-            if (is_array($record->members)) {
-                $memberRecords = Addressbook_Controller_Contact::getInstance()->getMultiple($record->members);
-            }
-
-            $str = '';
-            /** @var Addressbook_Model_Contact $contact */
-            foreach($memberRecords as $contact) {
-                $str .= ($str===''?'':', ') . $contact->n_fn;
-                if (isset($members[$contact->getId()])) {
-                    $str .= ' (';
-                    $first = true;
-                    foreach($members[$contact->getId()] as $listRole) {
-                        /** @var Addressbook_Model_ListRole $listRole */
-                        if (null !== ($listRole = $listRoles->getById($listRole))) {
-                            $str .= (true===$first?'':', ') . $listRole->name;
-                            $first = false;
-                        }
-                    }
-                    $str .= ')';
-                }
-            }
-
-            $record->memberroles = $str;
-        }
-    }
+    protected $_defaultExportname = 'adb_list_xls';
 }
index c14185e..e79dc3e 100644 (file)
@@ -25,21 +25,24 @@ class Addressbook_Export_Xls extends Tinebase_Export_Xls
      * @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())
-    {
+    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';
-    
+
     /**
      * default export definition name
-     * 
+     *
      * @var string
      */
     protected $_defaultExportname = 'adb_default_xls';
-}
+}
\ No newline at end of file
index 54e8e03..18c476c 100644 (file)
     <template>tine20:///Tinebase/folders/shared/export/templates/Addressbook/addressbook_list_export.docx</template>
     <favorite>true</favorite>
     <order>100</order>
+    <keyFields>
+        <keyField>
+            <name>listType</name>
+            <propertyName>list_type</propertyName>
+        </keyField>
+    </keyFields>
 </config>
index 05254ca..a108e39 100644 (file)
     <scope>multi</scope>
     <favorite>true</favorite>
     <order>200</order>
+    <keyFields>
+        <keyField>
+            <name>listType</name>
+            <propertyName>list_type</propertyName>
+        </keyField>
+    </keyFields>
 </config>
index 55b0f9c..8e91c13 100644 (file)
     <scope>multi</scope>
     <favorite>true</favorite>
     <order>300</order>
+    <keyFields>
+        <keyField>
+            <name>listType</name>
+            <propertyName>list_type</propertyName>
+        </keyField>
+    </keyFields>
 </config>
index e6a13a0..2feed91 100644 (file)
Binary files a/tine20/Addressbook/Export/templates/addressbook_list_overview.xlsx and b/tine20/Addressbook/Export/templates/addressbook_list_overview.xlsx differ
index 4d65573..a867147 100644 (file)
@@ -997,6 +997,8 @@ abstract class Tinebase_Export_Abstract implements Tinebase_Record_IteratableInt
             'export'            => array(
                 'timestamp'         => $this->_exportTimeStamp,
                 'account'           => Tinebase_Core::getUser(),
+                'contact'           => Addressbook_Controller_Contact::getInstance()->get(Tinebase_Core::getUser()
+                                        ->contact_id),
                 'groupdata'         => $this->_lastGroupValue,
             ),
             'additionalRecords' => $this->_additionalRecords,