12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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"));
- $TaskType = $kanban['status_items'];
- $item = $kanban['group_data'];
- $result=[];
- $j = 0;
- for ($i = 0; $i < count($item) ; $i++) {
- foreach ($TaskType as $type){ //遍历每一种任务状态,转为扁平数据行
- $arrItem = (array)$item[$i];
- if ($arrItem[$type]) {
- foreach ($arrItem[$type] as $value){
- $result[$j]['title'] = $arrItem['title']??'';
- $result[$j]['priority'] = $arrItem['priority']??'';
- $result[$j]['status'] = $arrItem['status']??'';
- $result[$j]['type'] = $type;
- $result[$j]['typeName'] = $value->name;
- $result[$j]['typeEnd'] = $value->end;
- $result[$j]['typeAssign'] = $value->assignTo->username??'';
- $j++;
- }
- }
- }
- }
- 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',
- ];
- }
- }
|