PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Models / NotificationPreference.php

NotificationPreference.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.10.0, at app/Models/NotificationPreference.php

76 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Models;
4
5 /**
6 * NotificationPreference Model - DB Model for fcom_notification_prefs table
7 *
8 * Stores a user's explicit notification overrides as an (event x channel) matrix.
9 * A missing row means "inherit the site default" - see NotificationPref::isEnabled().
10 * Only explicit overrides are stored, so a member on all defaults costs zero rows.
11 *
12 * Unlike the legacy pref rows in fcom_notification_users, the channel is a real
13 * column here. Adding push (or any future channel) is new rows, not new key names.
14 *
15 * @package FluentCommunity\App\Models
16 *
17 * @property int $id
18 * @property int $user_id
19 * @property string $channel
20 * @property string $event_key
21 * @property int $object_id
22 * @property int $value
23 *
24 * @version 1.0.0
25 */
26 class NotificationPreference extends Model
27 {
28 protected $table = 'fcom_notification_prefs';
29
30 protected $primaryKey = 'id';
31
32 protected $guarded = ['id'];
33
34 protected $fillable = [
35 'user_id',
36 'channel',
37 'event_key',
38 'object_id',
39 'value'
40 ];
41
42 public function user()
43 {
44 return $this->belongsTo(User::class, 'user_id');
45 }
46
47 public function xprofile()
48 {
49 return $this->belongsTo(XProfile::class, 'user_id', 'user_id');
50 }
51
52 public function scopeForChannel($query, $channel)
53 {
54 return $query->where('channel', $channel);
55 }
56
57 public function scopeForEvent($query, $eventKey)
58 {
59 return $query->where('event_key', $eventKey);
60 }
61
62 /**
63 * Global prefs (not scoped to a space or other object) use object_id = 0
64 * rather than NULL so the unique key can enforce one row per cell.
65 */
66 public function scopeGlobalScoped($query)
67 {
68 return $query->where('object_id', 0);
69 }
70
71 public function scopeEnabled($query)
72 {
73 return $query->where('value', 1);
74 }
75 }
76