123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Exports;
- use App\Models\Task;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- class TaskExport implements FromCollection, WithHeadings
- {
- private static $index = 1;
- public function collection()
- {
- $tasks = collect([]);
- Task::query()
- ->where("parent_id", 0)
- ->with(['children', 'assignTo', 'createdBy', 'parent', 'requirement', 'project'])
- ->filter(request()->all())
- ->allowed()
- ->orderBy("id")
- ->chunkById(200, function ($items) use (&$tasks) {
- foreach ($items as $item) {
- $tasks->push($this->formatRow($item));
- if ($item->children) {
- foreach ($item->children as $child) {
- $tasks->push($this->formatRow($child));
- }
- }
- }
- });
- return $tasks;
- }
- protected function formatRow(Task $task)
- {
- $displayId = self::$index++;
- return [
- $displayId,
- // $task->id,
- $task->name,
- $task->begin,
- $task->end,
- $task->parent?->name,
- $task->project?->name,
- $task->asset?->name,
- $task->requirement?->name,
- $task->status,
- $task->task_type,
- $task->doc_type,
- $task->suitability,
- $task->state,
- $task->approval_status,
- $task->description,
- $task->createdBy?->name,
- $task->created_at,
- ];
- }
- public function headings(): array
- {
- return [
- 'ID',
- 'Name',
- 'Begin',
- 'End',
- 'Parent',
- 'Project Name',
- 'Asset',
- 'Requirement',
- 'Status',
- 'Task Type',
- 'Doc Type',
- 'Suitability',
- 'State',
- 'Approval Status',
- 'Description',
- 'Created By',
- 'Created Date',
- ];
- }
- }
|