TaskTransformer.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Repositories\Transformers\Dianli;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Exam\PaperResult;
  5. use Carbon\Carbon;
  6. use League\Fractal\TransformerAbstract;
  7. use App\Repositories\Models\Dianli\Task;
  8. /**
  9. * Class TaskTransformer.
  10. *
  11. * @package namespace App\Repositories\Transformers\Dianli;
  12. */
  13. class TaskTransformer extends TransformerAbstract
  14. {
  15. /**
  16. * Transform the Task entity.
  17. *
  18. * @param \App\Repositories\Models\Dianli\Task $model
  19. *
  20. * @return array
  21. */
  22. public function transform(Task $model)
  23. {
  24. return [
  25. 'id' => (int)$model->id,
  26. 'name' => $model->name,
  27. 'type' => $model->type,
  28. 'start_date' => $model->start_date,
  29. 'end_date' => $model->end_date,
  30. 'weeks' => $model->weeks,
  31. 'assign_admin_ids' => $model->assign_admin_ids,
  32. 'assign_admin' => $model->assign_admin,
  33. 'admin' => $model->admin,
  34. 'paper_id' => $model->paper_id,
  35. 'allot_nums' => PaperResult::query()->where('paper_id', $model->paper_id)->where('status', ModelStatusEnum::OK)->count(),
  36. 'paper' => $model->paper,
  37. 'status' => $model->status,
  38. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  39. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  40. ];
  41. }
  42. }