| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Models; |
| 4 |
|
| 5 |
use FluentCommunity\App\Models\XProfile; |
| 6 |
use FluentCommunity\App\Models\User; |
| 7 |
|
| 8 |
/** |
| 9 |
* Legacy notification preference rows in fcom_notification_users. |
| 10 |
* |
| 11 |
* @deprecated 2.8.2 Preferences moved to fcom_notification_prefs; use |
| 12 |
* NotificationPreference and the NotificationPref service instead. |
| 13 |
* Retained so the pre-2.8.2 rows stay readable and third-party code |
| 14 |
* referencing this model does not fatal. Nothing in the plugin |
| 15 |
* writes through it any more. |
| 16 |
* |
| 17 |
* @package FluentCommunity\App\Models |
| 18 |
* |
| 19 |
* @version 1.0.0 |
| 20 |
*/ |
| 21 |
class NotificationSubscription extends Model |
| 22 |
{ |
| 23 |
protected $table = 'fcom_notification_users'; |
| 24 |
|
| 25 |
protected $primaryKey = 'id'; |
| 26 |
|
| 27 |
protected $guarded = ['id']; |
| 28 |
|
| 29 |
protected $fillable = [ |
| 30 |
'object_id', |
| 31 |
'user_id', |
| 32 |
'is_read', |
| 33 |
'object_type', |
| 34 |
'notification_type' |
| 35 |
]; |
| 36 |
|
| 37 |
protected static function boot() |
| 38 |
{ |
| 39 |
parent::boot(); |
| 40 |
|
| 41 |
static::creating(function ($model) { |
| 42 |
$model->object_type = 'notification_pref'; |
| 43 |
}); |
| 44 |
|
| 45 |
static::updating(function ($model) { |
| 46 |
$model->object_type = 'notification_pref'; |
| 47 |
}); |
| 48 |
|
| 49 |
// Add global scope to get only notifications |
| 50 |
static::addGlobalScope('notification', function ($builder) { |
| 51 |
$builder->where('object_type', 'notification_pref'); |
| 52 |
}); |
| 53 |
} |
| 54 |
|
| 55 |
public function user() |
| 56 |
{ |
| 57 |
return $this->belongsTo(User::class, 'user_id'); |
| 58 |
} |
| 59 |
|
| 60 |
public function xprofile() |
| 61 |
{ |
| 62 |
return $this->belongsTo(XProfile::class, 'user_id', 'user_id'); |
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|