ProjectGanttExport.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Exports;
  3. use App\Models\Project;
  4. use App\Services\Project\ProjectGanttService;
  5. use Illuminate\Support\Collection;
  6. use Maatwebsite\Excel\Concerns\Exportable;
  7. use Maatwebsite\Excel\Concerns\FromCollection;
  8. use Maatwebsite\Excel\Concerns\ShouldAutoSize;
  9. use Maatwebsite\Excel\Concerns\WithHeadings;
  10. use Maatwebsite\Excel\Concerns\WithMapping;
  11. use Maatwebsite\Excel\Events\AfterSheet;
  12. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  13. class ProjectGanttExport implements FromCollection, WithMapping, ShouldAutoSize
  14. {
  15. use Exportable;
  16. private static $index = 1;
  17. public function collection()
  18. {
  19. $project = Project::allowed(request()->project_id)->findOrFail(request()->project_id);
  20. $group = in_array(
  21. request()->get("group"),
  22. ['requirement_id','assign','task_type']
  23. ) ? request()->get("group") : "task_type";
  24. $header = ['id'=>'ID','parent'=> 0,'text'=>'Folder','start_date'=>'Start_Date','end_date'=>'End_Date','progress'=>'Progress','assign_to'=>'Assign_To'];
  25. $gantt = (new ProjectGanttService())->gantt($project, $group);
  26. array_unshift($gantt,$header);
  27. return new Collection($gantt);
  28. }
  29. public function map($project): array
  30. {
  31. $folder = '';
  32. if ($project['parent'] == 0){
  33. $folder = $project['text'];
  34. $displayId = $project['id'] =='ID'?'ID':'';
  35. $project['text'] = $project['text']=='Folder'?'Name':'';
  36. }else{
  37. $displayId = self::$index++;
  38. }
  39. return [
  40. $folder,
  41. $displayId,
  42. $project['text'],
  43. $project['parent'] != 0 ? ($project['progress'] * 100) . '%' : ($project['progress'] == 'Progress' ? 'Progress' : ''),
  44. $project['start_date'],
  45. $project['end_date'],
  46. $project['assign_to'],
  47. ];
  48. }
  49. }