Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 77 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UsersReportExport | |
0.00% |
0 / 77 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
array | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
56 | |||
headings | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | namespace App\Exports; |
3 | |
4 | use Carbon\Carbon; |
5 | use MongoDB\BSON\UTCDateTime; |
6 | use App\Http\Models\Auth\Role; |
7 | use App\Http\Models\Auth\User; |
8 | use App\Http\Models\HubspotProperties; |
9 | use Vitorccs\LaravelCsv\Concerns\FromArray; |
10 | use Vitorccs\LaravelCsv\Concerns\Exportable; |
11 | use Vitorccs\LaravelCsv\Concerns\WithMapping; |
12 | use Vitorccs\LaravelCsv\Concerns\WithHeadings; |
13 | use App\Http\Resources\UserDetailsReportResource; |
14 | |
15 | |
16 | class UsersReportExport implements FromArray, WithHeadings |
17 | // class UsersReportExport implements FromArray, WithHeadings, WithMapping |
18 | { |
19 | use Exportable; |
20 | |
21 | public $filters; |
22 | public $only_selected_user_ids; |
23 | |
24 | public function __construct($filters, $only_selected_user_ids = []) |
25 | { |
26 | $this->filters = $filters; |
27 | $this->only_selected_user_ids = $only_selected_user_ids; |
28 | } |
29 | |
30 | public function array(): array |
31 | { |
32 | $admin = auth()->user(); |
33 | $role = role($admin->role); |
34 | |
35 | $users = User::select([ |
36 | "id", |
37 | "first_name", |
38 | "last_name", |
39 | "company_group_id", |
40 | "company_id", |
41 | "deleted_at", |
42 | "avatar" |
43 | ]); |
44 | |
45 | $user_ids = array_filter($this->only_selected_user_ids, function ($value) { |
46 | return $value !== ""; |
47 | }); |
48 | if (count($user_ids) > 0) { |
49 | $users = $users->whereIn("_id", $user_ids); |
50 | } |
51 | |
52 | if ($role == Role::GLOBAL_ADMIN) { |
53 | $users = $users->where("company_id", "=", $admin->company_id); |
54 | } else { |
55 | $user_group = $admin->company_group; |
56 | $users = $users->where("company_group_id", "=", $user_group->id); |
57 | } |
58 | |
59 | $users = $users->get(); |
60 | $ids = $users->pluck("id")->toArray(); |
61 | |
62 | $start_date = $this->filters->fromDate; |
63 | $end_date = $this->filters->toDate; |
64 | |
65 | if ($start_date && $end_date) { |
66 | $start_date = Carbon::parse($start_date)->startOfDay(); |
67 | $end_date = Carbon::parse($end_date)->endOfDay(); |
68 | } |
69 | |
70 | // TODO MA select only the user saved columns. |
71 | $properties = HubspotProperties::whereIn("flymsg_id", $ids); |
72 | |
73 | if ($start_date && $end_date) { |
74 | $properties = $properties->whereBetween("created_at", [ |
75 | new UTCDateTime(strtotime(Carbon::now()->subMonths(12)->startOfDay()->toDateString()) * 1000), |
76 | new UTCDateTime(strtotime(Carbon::now()->endOfDay()->toDateString()) * 1000), |
77 | ]); |
78 | } |
79 | |
80 | $properties = $properties->get(); |
81 | |
82 | $properties = UserDetailsReportResource::collection($properties); |
83 | |
84 | // Create an instance of the current request |
85 | $request = request(); |
86 | |
87 | return $properties->toArray($request); // Pass the request instance |
88 | } |
89 | |
90 | public function headings(): array |
91 | { |
92 | return [ |
93 | 'First Name', |
94 | 'Last Name', |
95 | 'Email', |
96 | 'License Type', |
97 | 'FlyMSG Account Creation Date', |
98 | 'Extension Installed on Any Browser', |
99 | 'Last Login to FlyMSG', |
100 | 'Total # of Characters Typed by FlyMSG by User', |
101 | 'Total # of Characters Typed Summarized Monthly by FlyMSG by User', |
102 | 'Is the User Signed into FlyMSG Extension?', |
103 | 'Last Login to FlyLearning', |
104 | 'Total Time Saved by FlyMSG by User', |
105 | 'Total Cost Savings by FlyMSG by User', |
106 | 'Last Date User Used a FlyCut', |
107 | '# of FlyCuts Created (Count)', |
108 | '# of FlyCuts Created (Last Date)', |
109 | '# of FlyPlates Added to FlyCuts (Count)', |
110 | '# of FlyPlates Added to FlyCuts (Last Date)', |
111 | 'Total # of Times FlyEngage AI Used (Count)', |
112 | 'Total # of Characters Typed by FlyEngage', |
113 | 'Total # of Times FlyPosts Used (Count)', |
114 | 'Total # of Characters Typed by FlyPosts', |
115 | 'Which Browser has an extension been installed on', |
116 | 'FlyMSG Chrome Extension Installed', |
117 | 'FlyMSG Chrome Extension Installed (Date)', |
118 | 'FlyMSG Chrome Extension UNInstalled', |
119 | 'FlyMSG Chrome Extension UNInstalled (Date)', |
120 | 'FlyMSG Edge Extension Installed', |
121 | 'FlyMSG Edge Extension Installed (Date)', |
122 | 'FlyMSG Edge Extension UNInstalled', |
123 | 'FlyMSG Edge Extension UNInstalled (Date)', |
124 | '"Other" Reason to sign out (Free form field)', |
125 | 'FlyMSG Extension Version for Edge', |
126 | 'FlyMSG Extension Version for Chrome', |
127 | 'Clicked Help/request Help From Menu (Count)', |
128 | 'Typed Words Per Minute', |
129 | ]; |
130 | } |
131 | } |