-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathPublicFormBlockResource.php
More file actions
42 lines (35 loc) · 1.39 KB
/
PublicFormBlockResource.php
File metadata and controls
42 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\PublicFormBlockLogicResource;
class PublicFormBlockResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$logics = $this->formBlockLogics;
$interactions = $this->activeInteractions;
if ($this->options && $this->options['randomize_responses'] === true) {
$interactions = $this->activeInteractions->filter(fn ($value) => $value->name !== 'alt_response')->shuffle();
$customResponse = $this->activeInteractions->filter(fn ($value) => $value->name === 'alt_response')->first();
if ($customResponse) {
$interactions[] = $customResponse;
}
}
return [
'id' => $this->uuid,
'type' => $this->type->value,
'title' => $this->title,
'message' => $this->message,
'is_required' => $this->is_required,
'parent_block' => $this->parent_block,
'interactions' => PublicFormBlockInteractionResource::collection($interactions),
'logics' => PublicFormBlockLogicResource::collection($logics),
];
}
}