Tinebase Export - allow front end to send data to be exported
authorPaul Mehrer <p.mehrer@metaways.de>
Tue, 23 May 2017 10:31:48 +0000 (12:31 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Tue, 23 May 2017 12:36:44 +0000 (14:36 +0200)
Change-Id: I9c81292aaa43e9ba6f7ce8d58cfe7f763c02e216
Reviewed-on: http://gerrit.tine20.com/customers/4737
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tine20/Tinebase/Export/Abstract.php
tine20/Tinebase/Export/Doc.php

index d062885..7cf7121 100644 (file)
@@ -181,6 +181,11 @@ abstract class Tinebase_Export_Abstract implements Tinebase_Record_IteratableInt
     protected $_logoPath = null;
 
     /**
+     * @var Tinebase_Record_RecordSet|null
+     */
+    protected $_records = null;
+
+    /**
      * the constructor
      *
      * @param Tinebase_Model_Filter_FilterGroup $_filter
@@ -214,6 +219,11 @@ abstract class Tinebase_Export_Abstract implements Tinebase_Record_IteratableInt
                 $this->_sortInfo =  $_additionalOptions['sortInfo'];
             }
         }
+
+        if (isset($_additionalOptions['recordData'])) {
+            $this->_records = new Tinebase_Record_RecordSet($this->_modelName,
+                array(new $this->_modelName($_additionalOptions['recordData'])));
+        }
     }
 
     /**
@@ -355,19 +365,29 @@ abstract class Tinebase_Export_Abstract implements Tinebase_Record_IteratableInt
 
         $this->_onBeforeExportRecords();
 
-        $iterator = new Tinebase_Record_Iterator(array(
-            'iteratable' => $this,
-            'controller' => $this->_controller,
-            'filter'     => $this->_filter,
-            'options'     => array(
-                'searchAction' => 'export',
-                'sortInfo'     => $this->_sortInfo,
-                'getRelations' => $this->_getRelations,
-            ),
-        ));
-
         $this->_firstIteration = true;
-        $result = $iterator->iterate();
+
+        if (null === $this->_records) {
+            $iterator = new Tinebase_Record_Iterator(array(
+                'iteratable' => $this,
+                'controller' => $this->_controller,
+                'filter' => $this->_filter,
+                'options' => array(
+                    'searchAction' => 'export',
+                    'sortInfo' => $this->_sortInfo,
+                    'getRelations' => $this->_getRelations,
+                ),
+            ));
+
+            $result = $iterator->iterate();
+        } else {
+
+            $result = array(
+                'totalcount' => $this->_records->count(),
+                'results'    => array(),
+            );
+            $result['results'][] = $this->processIteration($this->_records);
+        }
 
         $this->_onAfterExportRecords($result);
 
index 55a589f..1e0bf8b 100644 (file)
@@ -45,10 +45,9 @@ class Tinebase_Export_Doc extends Tinebase_Export_Abstract implements Tinebase_R
     protected $_block = null;
     protected $_separator = null;
 
-    /**
-     * @var Tinebase_Record_RecordSet|null
-     */
-    protected $_records = null;
+    protected $delayIteration = true;
+
+
 
     /**
      * get download content type
@@ -78,6 +77,9 @@ class Tinebase_Export_Doc extends Tinebase_Export_Abstract implements Tinebase_R
      */
     public function generate()
     {
+        if (null !== $this->_records) {
+            $this->delayIteration = false;
+        }
         $this->_rowCount = 0;
         $this->_createDocument();
         $this->_exportRecords();
@@ -202,6 +204,9 @@ class Tinebase_Export_Doc extends Tinebase_Export_Abstract implements Tinebase_R
      */
     public function processIteration($_records)
     {
+        if (false === $this->delayIteration) {
+            return;
+        }
         if (null === $this->_records) {
             $this->_records = $_records;
         } else {