Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| UserDetailsReportResource | |
0.00% |
0 / 75 |
|
0.00% |
0 / 3 |
210 | |
0.00% |
0 / 1 |
| toArray | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
156 | |||
| getVisibleColumns | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| checkFrontendKeysAgainstBackendKeys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resources; |
| 4 | |
| 5 | use App\Exceptions\ExpectedException; |
| 6 | use App\Helpers\FlyMSGLogger; |
| 7 | use App\Http\Models\Admin\UserDetailsColumnSetting; |
| 8 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Resources\Json\JsonResource; |
| 10 | |
| 11 | class UserDetailsReportResource extends JsonResource |
| 12 | { |
| 13 | /** |
| 14 | * Transform the resource into an array. |
| 15 | * |
| 16 | * @param Request $request |
| 17 | * @return array<string, mixed> |
| 18 | */ |
| 19 | public function toArray($request): array |
| 20 | { |
| 21 | // Fetch visible columns for the user |
| 22 | $visibleColumns = $this->getVisibleColumns(); |
| 23 | |
| 24 | $user = $this->user; |
| 25 | if (! $user) { |
| 26 | FlyMSGLogger::logError('UserDetailsReportResource', new ExpectedException("User not found for HS property with ID $this->id")); |
| 27 | $user = $this; |
| 28 | } |
| 29 | $status = $user->status; |
| 30 | |
| 31 | if ($user->deleted_at) { |
| 32 | $status = 'Deactivated'; |
| 33 | } |
| 34 | |
| 35 | if ($user->status == 'Invited') { |
| 36 | $status = 'Not Active'; |
| 37 | } |
| 38 | |
| 39 | if ($user->status == 'Active') { |
| 40 | $status = 'Active'; |
| 41 | } |
| 42 | |
| 43 | $group_subgroup_id = null; |
| 44 | $group_id = $user->company_group->id ?? null; |
| 45 | |
| 46 | if ($user->company_group && $user->company_group->parent_id) { |
| 47 | $group_id = $user->company_group->parent->id; |
| 48 | $group_subgroup_id = $user->company_group->id; |
| 49 | } |
| 50 | |
| 51 | // Define all available columns |
| 52 | $allColumns = [ |
| 53 | 'first_name' => $this->firstname, |
| 54 | 'last_name' => $this->lastname, |
| 55 | 'email' => $this->email, |
| 56 | 'license_type' => $this->subscription_type, |
| 57 | 'flymsg_account_creation_date' => $this->account_creation_date, |
| 58 | 'extension_installed_on_any_browser' => ($this->flymsg_chrome_extension_installed == 'Yes' || $this->flymsg_edge_extension_installed == 'Yes') ? 'Yes' : 'No', |
| 59 | 'last_login_to_flymsg' => $this->last_login, |
| 60 | 'total_no_of_characters_typed_by_flymsg_by_user' => $this->total___of_characters_typed_by_flymsg_by_user, |
| 61 | 'total_no_of_characters_typed_summarized_monthly_by_flymsg_by_user' => $this->total___of_characters_typed_monthly_by_flymsg_by_user, |
| 62 | 'is_the_user_signed_into_flymsg_extension' => $this->signed_into_flymsg_extension, |
| 63 | 'last_login_to_flylearning' => $this->last_login_to_flylearning, |
| 64 | 'total_time_saved_by_flymsg_by_user' => $this->total_time_saved_by_flymsg_by_user, |
| 65 | 'total_cost_savings_by_flymsg_by_user' => $this->total_cost_savings_by_flymsg_by_user, |
| 66 | 'last_date_user_used_a_flycut' => $this->last_date_user_used_a_flycut, |
| 67 | 'flycuts_created_count' => $this->number_of_flycuts_created_count, |
| 68 | 'flycuts_created_last_date' => $this->number_of_flycuts_created_last_date, |
| 69 | 'flyplates_added_to_flycuts_count' => $this->number_of_flyplates_in_flycuts_count, |
| 70 | 'flyplates_added_to_flycuts_last_date' => $this->number_of_flyplates_in_flycuts_last_date, |
| 71 | 'total_no_of_times_flyengage_ai_used_count' => $this->total___of_times_flyengage_used__count_, |
| 72 | 'total_no_of_characters_typed_by_flyengage' => $this->total_no_of_characters_typed_by_flyengage, |
| 73 | 'total_no_of_times_sentence_rewrite_ai_used_count' => $this->total___of_times_sentence_rewrite_used__count_, |
| 74 | 'total_no_of_characters_typed_by_sentence_rewrite' => $this->total_no_of_characters_typed_by_sentence_rewrite, |
| 75 | 'total_no_of_times_paragraph_rewrite_ai_used_count' => $this->total___of_times_paragraph_rewrite_used__count_, |
| 76 | 'total_no_of_characters_typed_by_paragraph_rewrite' => $this->total_no_of_characters_typed_by_paragraph_rewrite, |
| 77 | 'total_no_of_times_flyposts_used_count' => $this->total___of_times_flyposts_used__count_, |
| 78 | 'total_no_of_characters_typed_by_flyposts' => $this->total_no_of_characters_typed_by_flyposts, |
| 79 | 'which_browser_has_an_extension_been_installed_on' => $this->which_browser_has_an_extension_been_installed_on, |
| 80 | 'flymsg_chrome_extension_installed' => $this->flymsg_chrome_extension_installed, |
| 81 | 'flymsg_chrome_extension_installed_date' => $this->flymsg_chrome_extension_installed__date_, |
| 82 | 'flymsg_chrome_extension_uninstalled' => $this->flymsg_chrome_extension_uninstalled, |
| 83 | 'flymsg_chrome_extension_uninstalled_date' => $this->flymsg_chrome_extension_uninstalled__date_, |
| 84 | 'flymsg_edge_extension_installed_date' => $this->flymsg_edge_extension_installed__date_, |
| 85 | 'flymsg_edge_extension_installed' => $this->flymsg_edge_extension_installed, |
| 86 | 'flymsg_edge_extension_uninstalled' => $this->flymsg_edge_extension_uninstalled, |
| 87 | 'flymsg_edge_extension_uninstalled__date_' => $this->flymsg_edge_extension_uninstalled__date_, |
| 88 | 'other_reason_to_sign_out_free_form_field' => $this->other_reason_to_sign_out_free_form_field, |
| 89 | 'flymsg_extension_version_for_edge' => $this->flymsg_extension_version_for_edge, |
| 90 | 'flymsg_extension_version_for_chrome' => $this->flymsg_extension_version_for_chrome, |
| 91 | 'clicked_help_request_help_from_menu_count' => $this->clicked_settings_count, |
| 92 | 'typed_words_per_minute' => $this->typed_words_per_minute, |
| 93 | 'user_id' => $user->id, |
| 94 | 'group_id' => $group_id, |
| 95 | 'subgroup_id' => $group_subgroup_id, |
| 96 | 'status' => $status ?? 'Active', |
| 97 | ]; |
| 98 | |
| 99 | if (empty($visibleColumns)) { |
| 100 | return $allColumns; |
| 101 | } |
| 102 | |
| 103 | // Initialize an empty array for filtered columns |
| 104 | $filteredColumns = []; |
| 105 | |
| 106 | // Loop through visible columns and add them to filteredColumns array |
| 107 | foreach ($visibleColumns as $column) { |
| 108 | if (array_key_exists($column, $allColumns)) { |
| 109 | $filteredColumns[$column] = $allColumns[$column]; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return $filteredColumns; |
| 114 | } |
| 115 | |
| 116 | private function getVisibleColumns() |
| 117 | { |
| 118 | return UserDetailsColumnSetting::where('user_id', auth()->user()->id) |
| 119 | ->where('visible', true) |
| 120 | ->pluck('column') |
| 121 | ->toArray(); |
| 122 | } |
| 123 | |
| 124 | private function checkFrontendKeysAgainstBackendKeys($key) |
| 125 | { |
| 126 | return array_key_exists($key, $this->getVisibleColumns()); |
| 127 | } |
| 128 | } |