Merge pull request #1913 from SevanNerse/export-events
headings and data of exports converted to event-driven
This commit is contained in:
commit
c05274221e
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Events\Export\HeadingsPreparing;
|
||||
use App\Events\Export\RowsPreparing;
|
||||
use App\Utilities\Date;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
@ -15,9 +17,12 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
{
|
||||
public $ids;
|
||||
|
||||
public $fields;
|
||||
|
||||
public function __construct($ids = null)
|
||||
{
|
||||
$this->ids = $ids;
|
||||
$this->fields = $this->fields();
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
@ -38,7 +43,7 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
|
||||
$evil_chars = ['=', '+', '-', '@'];
|
||||
|
||||
foreach ($this->fields() as $field) {
|
||||
foreach ($this->fields as $field) {
|
||||
$value = $model->$field;
|
||||
|
||||
if (in_array($field, $date_fields)) {
|
||||
@ -58,6 +63,15 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return $this->fields();
|
||||
event(new HeadingsPreparing($this));
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
public function prepareRows($rows)
|
||||
{
|
||||
event(new RowsPreparing($this, $rows));
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
|
20
app/Events/Export/HeadingsPreparing.php
Normal file
20
app/Events/Export/HeadingsPreparing.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Export;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class HeadingsPreparing extends Event
|
||||
{
|
||||
public $class;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $class
|
||||
*/
|
||||
public function __construct($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
}
|
24
app/Events/Export/RowsPreparing.php
Normal file
24
app/Events/Export/RowsPreparing.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Export;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class RowsPreparing extends Event
|
||||
{
|
||||
public $class;
|
||||
|
||||
public $rows;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $class
|
||||
* @param $rows
|
||||
*/
|
||||
public function __construct($class, $rows)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->rows = $rows;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user