123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Exports;
- use App\Models\Project;
- use App\Services\Project\ProjectKanbanService;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\Exportable;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\ShouldAutoSize;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithMapping;
- class ProjectKanbanExport implements FromCollection, WithMapping, WithHeadings, ShouldAutoSize
- {
- use Exportable;
- private static $index = 1;
- public function collection()
- {
- $service = new ProjectKanbanService();
- $project = Project::allowed(request()->project_id)->findOrFail(request()->project_id);
- $kanban = $service->kanban($project, request()->get("group", "requirement_asc"));
- $data =json_encode($kanban['group_data']);
- $TaskType = $kanban['status_items'];
- $result=[];
- $item = json_decode($data);
- for ($i = 0; $i <count($item) ; $i++) {
- $result[$i]['title'] = $item[$i]->title??'';
- $result[$i]['priority'] = $item[$i]->priority??'';
- $result[$i]['status'] = $item[$i]->status??'';
- foreach ($TaskType as $type){ //遍历每一种任务状态,转为扁平数据行
- foreach ($item[$i]->{$type} as $value){
- $result[$i]['type'] = $type;
- $result[$i]['typeName'] = $value->name;
- $result[$i]['typeEnd'] = $value->end;
- $result[$i]['typeAssign'] = $value->assign->name??'';
- }
- }
- }
- return new Collection($result);
- }
- public function map($project): array
- {
- $displayId = self::$index++;
- return [
- $displayId,
- $project['title'],
- $project['priority'],
- $project['status'],
- $project['typeName'],
- $project['type'],
- $project['typeEnd'],
- $project['typeAssign'],
- ];
- }
- public function headings(): array
- {
- return [
- 'ID',
- 'Title',
- 'Priority',
- 'Status',
- 'TaskName',
- 'TaskStatus',
- 'TaskEnd',
- 'TaskAssign',
- ];
- }
- }
|