Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ClientManagementUsersExportResource | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
600 | |
0.00% |
0 / 1 |
toArray | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
600 |
1 | <?php |
2 | |
3 | namespace App\Http\Resources; |
4 | |
5 | use Illuminate\Http\Request; |
6 | use Illuminate\Support\Carbon; |
7 | use App\Traits\SubscriptionTrait; |
8 | use App\Http\Models\HubspotProperties; |
9 | use App\Http\Models\Admin\AdminUserInvitation; |
10 | use Illuminate\Http\Resources\Json\JsonResource; |
11 | |
12 | class ClientManagementUsersExportResource extends JsonResource |
13 | { |
14 | use SubscriptionTrait; |
15 | |
16 | /** |
17 | * Transform the resource into an array. |
18 | * |
19 | * @return array<string, mixed> |
20 | */ |
21 | public function toArray(Request $request): array |
22 | { |
23 | $group_name = $this->company_group ? $this->company_group->name : "Not Assigned"; |
24 | $subgroup_name = $this->company_group ? $this->company_group->name : "Not Assigned"; |
25 | |
26 | if ($this->company_group && $this->company_group->parent_id) { |
27 | $group_name = $this->company_group->parent ? $this->company_group->parent->name : "Not Assigned"; |
28 | } |
29 | |
30 | if ($this->company_group && !$this->company_group->parent_id) { |
31 | $subgroup_name = "Not Assigned"; |
32 | } |
33 | |
34 | $statusDate = null; |
35 | |
36 | if ($this->created_at) { |
37 | $statusDate = $this->created_at->toFormattedDateString(); |
38 | } |
39 | |
40 | if ($this->activation_date) { |
41 | $statusDate = Carbon::parse($this->activation_date)->toFormattedDateString(); |
42 | } |
43 | |
44 | $status = filled($this->deleted_at) ? "Deactivated" : "Active"; |
45 | |
46 | if ($this->status && $this->status != "Deactivated" && empty($this->deleted_at) ){ |
47 | $status = $this->status; |
48 | } |
49 | |
50 | if ($status == "Deactivated") { |
51 | $deactivatedAt = $model->deactivated_at ?? $this->deleted_at; |
52 | $statusDate = $deactivatedAt ? Carbon::parse($deactivatedAt)->toFormattedDateString() : null; |
53 | } |
54 | |
55 | $plan_name = "Freemium"; |
56 | $role = role($this->role); |
57 | $extension = "No"; |
58 | |
59 | if ($status == "Invited") { |
60 | $invitation = AdminUserInvitation::firstWhere('email', $this->email); |
61 | |
62 | if ($invitation) { |
63 | $statusDate = $invitation?->updated_at?->toFormattedDateString(); |
64 | |
65 | if(filled($invitation->role_name)){ |
66 | $role = $invitation->role_name; |
67 | } |
68 | |
69 | if($this->subscription("invitation")){ |
70 | $plan_name = $this->subscription("invitation")->title; |
71 | } |
72 | } |
73 | } |
74 | |
75 | if ($status == "Active") { |
76 | $plan_name = $this->getCurrentPlan($this)->title; |
77 | $hubspot = HubspotProperties::firstWhere("flymsg_id", $this->id); |
78 | $extension = ($hubspot?->flymsg_chrome_extension_installed == "Yes" || $hubspot?->flymsg_edge_extension_installed == "Yes") ? "Yes" : "No"; |
79 | } |
80 | |
81 | return [ |
82 | 'first_name' => $this->first_name, |
83 | 'last_name' => $this->last_name, |
84 | 'email' => $this->email, |
85 | 'company' => $this->company ? $this->company->name : "Not Assigned", |
86 | 'extension' => $extension, |
87 | 'role' => $role, |
88 | 'group' => $group_name, |
89 | 'subgroup' => $subgroup_name, |
90 | 'licenseType' => $plan_name, |
91 | 'status' => $status, |
92 | 'created_at' => $this->created_at ?? $this->updated_at, |
93 | 'statusDate' => $statusDate, |
94 | ]; |
95 | } |
96 | } |