Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| InAppNotification | |
75.00% |
3 / 4 |
|
75.00% |
3 / 4 |
4.25 | |
0.00% |
0 / 1 |
| campaign | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStatusEnum | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| newFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models; |
| 4 | |
| 5 | use App\Enums\InAppNotificationStatus; |
| 6 | use App\Http\Models\Auth\User; |
| 7 | use Database\Factories\Http\Models\InAppNotificationFactory; |
| 8 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 9 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 10 | |
| 11 | /** |
| 12 | * InAppNotification model - per-user notification delivery record. |
| 13 | * |
| 14 | * Tracks delivery and interaction status for a notification assigned |
| 15 | * to a specific user from a campaign. |
| 16 | * |
| 17 | * @property string $_id |
| 18 | * @property string $campaign_id The campaign this notification belongs to |
| 19 | * @property string $user_id The user this notification is for |
| 20 | * @property string $status Current status (pending, sent, viewed, clicked, dismissed) |
| 21 | * @property \Carbon\Carbon|null $sent_at When the notification was delivered |
| 22 | * @property \Carbon\Carbon|null $viewed_at When the user viewed it |
| 23 | * @property \Carbon\Carbon|null $clicked_at When the user clicked the CTA |
| 24 | * @property \Carbon\Carbon|null $dismissed_at When the user dismissed it |
| 25 | * @property int $impression_count Number of times shown to the user |
| 26 | * @property \Carbon\Carbon|null $created_at |
| 27 | * @property \Carbon\Carbon|null $updated_at |
| 28 | */ |
| 29 | class InAppNotification extends Moloquent |
| 30 | { |
| 31 | use HasFactory; |
| 32 | |
| 33 | /** |
| 34 | * The collection name. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | protected $table = 'in_app_notifications'; |
| 39 | |
| 40 | /** |
| 41 | * The attributes that are mass assignable. |
| 42 | * |
| 43 | * @var array<int, string> |
| 44 | */ |
| 45 | protected $fillable = [ |
| 46 | 'campaign_id', |
| 47 | 'user_id', |
| 48 | 'status', |
| 49 | 'sent_at', |
| 50 | 'viewed_at', |
| 51 | 'clicked_at', |
| 52 | 'dismissed_at', |
| 53 | 'impression_count', |
| 54 | ]; |
| 55 | |
| 56 | /** |
| 57 | * The attributes that should be cast. |
| 58 | * |
| 59 | * @var array<string, string> |
| 60 | */ |
| 61 | protected $casts = [ |
| 62 | 'sent_at' => 'datetime', |
| 63 | 'viewed_at' => 'datetime', |
| 64 | 'clicked_at' => 'datetime', |
| 65 | 'dismissed_at' => 'datetime', |
| 66 | 'impression_count' => 'integer', |
| 67 | ]; |
| 68 | |
| 69 | /** |
| 70 | * Get the campaign this notification belongs to. |
| 71 | */ |
| 72 | public function campaign(): BelongsTo |
| 73 | { |
| 74 | return $this->belongsTo(InAppNotificationCampaign::class, 'campaign_id'); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the user this notification is for. |
| 79 | */ |
| 80 | public function user(): BelongsTo |
| 81 | { |
| 82 | return $this->belongsTo(User::class, 'user_id'); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get the status as an enum. |
| 87 | */ |
| 88 | public function getStatusEnum(): InAppNotificationStatus |
| 89 | { |
| 90 | return InAppNotificationStatus::from($this->status); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Create a new factory instance for the model. |
| 95 | */ |
| 96 | protected static function newFactory(): InAppNotificationFactory |
| 97 | { |
| 98 | return InAppNotificationFactory::new(); |
| 99 | } |
| 100 | } |