mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
49 lines
1.9 KiB
PHP
49 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Models\QAAnswerOptions;
|
|
use App\Models\QAQuestions;
|
|
use Carbon\Carbon;
|
|
|
|
class QuestionsAnswersResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$question = QAQuestions::where('id', $this->question_id)->first();
|
|
$source = new UserSourceResource($this->userSource);
|
|
$user = $this->source_id === 0 ? new UserResource($this->user) : null;
|
|
$answerOption = QAAnswerOptions::where('id', $this->answer_option_id)->first();
|
|
$questionGroups = explode(',', $this->question->questionnaire->group);
|
|
$user_marking = '';
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'question_id' => $this->question_id,
|
|
'question_groups' => $questionGroups,
|
|
'questionnaire' => new QuestionnaireSetsResource($this->question->questionnaire),
|
|
'question_title' => $question ? $question->question_title : null,
|
|
'question_type' => $question ? $question->question_type : 0,
|
|
'question_metadata' => $this->question_metadata,
|
|
'answer' => $answerOption ? $answerOption->display_text : null,
|
|
'answer_value' => $this->answer,
|
|
'documents' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::ADMIN_WORK_FLOW)->first()),
|
|
'reference' => $this->reference,
|
|
'source_system' => null,
|
|
'source_marking' => $user ? $user_marking : $source->marking,
|
|
'source_email' => $user ? $user->email : $source->email,
|
|
'time' => $this->time_used_seconds,
|
|
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
|
|
];
|
|
}
|
|
}
|