Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| FlyMsgUserDailyUsage | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| GenerateNewRecord | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models; |
| 4 | |
| 5 | use App\Http\Models\Admin\CompanyGroup; |
| 6 | use App\Http\Models\Auth\User; |
| 7 | use App\Observers\FlyMsgUserDailyUsageObserver; |
| 8 | use Carbon\Carbon; |
| 9 | use Illuminate\Database\Eloquent\Attributes\ObservedBy; |
| 10 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 11 | use Illuminate\Notifications\Notifiable; |
| 12 | |
| 13 | #[ObservedBy([FlyMsgUserDailyUsageObserver::class])] |
| 14 | class FlyMsgUserDailyUsage extends Moloquent |
| 15 | { |
| 16 | use Notifiable; |
| 17 | protected $table = 'fly_msg_user_daily_usage'; |
| 18 | |
| 19 | protected $fillable = [ |
| 20 | 'user_id', |
| 21 | 'hubspot_id', |
| 22 | 'year', |
| 23 | 'month', |
| 24 | 'day', |
| 25 | 'date', |
| 26 | 'company_id', |
| 27 | 'email_domain', |
| 28 | 'user_status', |
| 29 | 'group_id', |
| 30 | 'subgroup_id', |
| 31 | 'category', |
| 32 | 'time_saved', |
| 33 | 'cost_savings', |
| 34 | 'characters_typed', |
| 35 | 'flycuts_created', |
| 36 | 'flyplates_added', |
| 37 | 'flyengage_count', |
| 38 | 'sentence_rewrite_count', |
| 39 | 'paragraph_rewrite_count', |
| 40 | 'flypost_count', |
| 41 | 'flycut_count', |
| 42 | 'fly_grammar_actions', |
| 43 | 'fly_grammar_accepted', |
| 44 | 'fly_grammar_autocorrect', |
| 45 | 'fly_grammar_autocomplete', |
| 46 | 'updated_at', |
| 47 | 'created_at', |
| 48 | ]; |
| 49 | |
| 50 | public static function GenerateNewRecord( |
| 51 | int $year, |
| 52 | int $month, |
| 53 | int $day, |
| 54 | string $user_id, |
| 55 | float $time_saved, |
| 56 | float $cost_savings, |
| 57 | int $characters_typed, |
| 58 | int $flycuts_created, |
| 59 | int $flyplates_added, |
| 60 | int $flyengage_count, |
| 61 | int $sentence_rewrite_count, |
| 62 | int $paragraph_rewrite_count, |
| 63 | int $flypost_count, |
| 64 | int $flycut_count, |
| 65 | int $fly_grammar_actions, |
| 66 | int $fly_grammar_accepted, |
| 67 | int $fly_grammar_autocorrect, |
| 68 | int $fly_grammar_autocomplete, |
| 69 | ) { |
| 70 | $user = User::find($user_id); |
| 71 | $findByDate = new FlyMsgUserDailyUsage(); |
| 72 | $findByDate->user_id = $user_id; |
| 73 | $findByDate->hubspot_id = $user->hubspot_id; |
| 74 | $findByDate->year = $year; |
| 75 | $findByDate->month = $month; |
| 76 | $findByDate->day = $day; |
| 77 | $findByDate->date = new \MongoDB\BSON\UTCDateTime(Carbon::create($year, $month, $day)->timestamp * 1000); |
| 78 | $findByDate->email_domain = strrchr($user->email, "@"); |
| 79 | $findByDate->user_status = $user->status ?? 'Active'; |
| 80 | $findByDate->company_id = $user->company_id; |
| 81 | |
| 82 | $group = CompanyGroup::find($user->company_group_id); |
| 83 | if (!empty($group?->parent_id)) { |
| 84 | $findByDate->subgroup_id = $user->company_group_id; |
| 85 | $findByDate->group_id = $group->parent_id; |
| 86 | } else { |
| 87 | $findByDate->group_id = $user->company_group_id; |
| 88 | } |
| 89 | |
| 90 | $findByDate->category = $user->company_id ? 'corporate' : 'individual'; |
| 91 | $findByDate->time_saved = $time_saved; |
| 92 | $findByDate->cost_savings = $cost_savings; |
| 93 | $findByDate->characters_typed = $characters_typed; |
| 94 | $findByDate->flycuts_created = $flycuts_created; |
| 95 | $findByDate->flyplates_added = $flyplates_added; |
| 96 | $findByDate->flyengage_count = $flyengage_count; |
| 97 | $findByDate->sentence_rewrite_count = $sentence_rewrite_count; |
| 98 | $findByDate->paragraph_rewrite_count = $paragraph_rewrite_count; |
| 99 | $findByDate->flypost_count = $flypost_count; |
| 100 | $findByDate->flycut_count = $flycut_count; |
| 101 | $findByDate->fly_grammar_actions = $fly_grammar_actions; |
| 102 | $findByDate->fly_grammar_accepted = $fly_grammar_accepted; |
| 103 | $findByDate->fly_grammar_autocorrect = $fly_grammar_autocorrect; |
| 104 | $findByDate->fly_grammar_autocomplete = $fly_grammar_autocomplete; |
| 105 | $findByDate->save(); |
| 106 | } |
| 107 | } |