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