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