Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ClientManagementUserV2Resource | |
0.00% |
0 / 38 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| toArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| buildUser | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
20 | |||
| getInvitationLinkForAdminPortal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 Illuminate\Http\Resources\Json\JsonResource; |
| 9 | |
| 10 | class ClientManagementUserV2Resource extends JsonResource |
| 11 | { |
| 12 | use SubscriptionTrait; |
| 13 | |
| 14 | /** |
| 15 | * Transform the resource into an array. |
| 16 | * |
| 17 | * @return array<string, mixed> |
| 18 | */ |
| 19 | public function toArray(Request $request): array |
| 20 | { |
| 21 | return $this->buildUser($this); |
| 22 | } |
| 23 | |
| 24 | private function buildUser($model) |
| 25 | { |
| 26 | $group_name = $model['group_name'] ?? "Not Assigned"; |
| 27 | $subgroup_name = $model['subgroup_name'] ?? "Not Assigned"; |
| 28 | $createdAt = Carbon::createFromTimestamp(($model['user_created_at'] ?? $model['created_at'])->toDateTime()->getTimestamp()); |
| 29 | $statusDate = $createdAt->toFormattedDateString(); |
| 30 | if (!empty($model['status_date'])) { |
| 31 | $carbonDate = Carbon::createFromTimestamp($model['status_date']->toDateTime()->getTimestamp()); |
| 32 | $statusDate = $carbonDate->toFormattedDateString(); |
| 33 | } |
| 34 | $status = $model['status'] ?? "Active"; |
| 35 | $plan_name = $model['plan_name'] ?? "Freemium"; |
| 36 | $role = role($model['role_names'] ?? null); |
| 37 | $extension = "No"; |
| 38 | |
| 39 | if ($status == "Active") { |
| 40 | // $chromeInstalled = $model['is_chrome_extension_installed'] ? 'Yes' : 'No'; |
| 41 | // $edgeInstalled = $model['is_edge_extension_installed'] ? 'Yes' : 'No'; |
| 42 | $extension = $model['is_any_extension_installed'] ? "Yes" : "No"; |
| 43 | } |
| 44 | |
| 45 | return [ |
| 46 | 'id' => $model['user_id'], |
| 47 | 'first_name' => $model['first_name'], |
| 48 | 'last_name' => $model['last_name'], |
| 49 | 'name' => $model['full_name'], |
| 50 | 'email' => $model['email'], |
| 51 | 'company' => $model['company_name'] ?? "Individuals", |
| 52 | 'company_id' => $model['company_id'] ?? null, |
| 53 | 'company_group_id' => $model['subgroup_id'] ?? $model['group_id'] ?? null, |
| 54 | 'company_slug' => $model['company_name'] ?? null, |
| 55 | 'company_has_groups' => false, // ($model['company_info'] ?? null)?->groups > 0, |
| 56 | 'groups_admin' => $model['sales_pro_team_manager']?->company_group_ids ?? null, |
| 57 | 'extension' => $extension, |
| 58 | 'role' => $role, |
| 59 | 'group' => $group_name, |
| 60 | 'subgroup' => $subgroup_name, |
| 61 | 'licenseType' => $plan_name, |
| 62 | 'status' => $status, |
| 63 | 'is_invite' => $model['is_invite'] ?? false, |
| 64 | 'invitation_link' => $this->getInvitationLinkForAdminPortal($model), |
| 65 | 'created_at' => $model['user_created_at'] ?? $model['created_at'], |
| 66 | 'statusDate' => $statusDate, |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | private function getInvitationLinkForAdminPortal($model) |
| 71 | { |
| 72 | return config('romeo.frontend-base-url') . "/session/signup?email=" . $model['email']; |
| 73 | } |
| 74 | } |