ソースを参照

update exporter

jqh 5 年 前
コミット
2abb51291a
1 ファイル変更13 行追加26 行削除
  1. 13 26
      src/Grid/Exporters/AbstractExporter.php

+ 13 - 26
src/Grid/Exporters/AbstractExporter.php

@@ -32,11 +32,6 @@ abstract class AbstractExporter implements ExporterInterface
      */
     protected $titles = [];
 
-    /**
-     * @var array
-     */
-    protected $data;
-
     /**
      * @var string
      */
@@ -92,20 +87,6 @@ abstract class AbstractExporter implements ExporterInterface
         return $this;
     }
 
-    /**
-     * Set export data.
-     *
-     * @param array $data
-     *
-     * @return $this
-     */
-    public function data($data)
-    {
-        $this->data = $data;
-
-        return $this;
-    }
-
     /**
      * Set export data callback function.
      *
@@ -189,10 +170,6 @@ abstract class AbstractExporter implements ExporterInterface
      */
     public function buildData(?int $page = null, ?int $perPage = null)
     {
-        if (! is_null($this->data)) {
-            return $this->data;
-        }
-
         $model = $this->grid->model();
 
         // current page
@@ -214,11 +191,21 @@ abstract class AbstractExporter implements ExporterInterface
         $model->reset();
         $model->rejectQueries('forPage');
 
-        if ($this->builder) {
-            return ($this->builder)($array);
+        return $this->callBuilder($array);
+    }
+
+    /**
+     * @param array $data
+     *
+     * @return array
+     */
+    protected function callBuilder(array &$data)
+    {
+        if ($data && $this->builder) {
+            return ($this->builder)($data);
         }
 
-        return $array;
+        return $data;
     }
 
     /**