PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.2.0
Fluent Support – Helpdesk & Customer Support Ticket System v2.2.0
2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 All 67 releases
fluent-support / app / Models / Notification.php

Notification.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.2.0, at app/Models/Notification.php

114 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Models;
4
5 use FluentSupport\App\Services\Notifications\NotificationSettings;
6 use FluentSupport\App\Services\Helper;
7
8 class Notification extends Model
9 {
10 protected $table = 'fs_notifications';
11
12 protected $fillable = [
13 'actor_id',
14 'ticket_id',
15 'conversation_id',
16 'event_type',
17 'category',
18 'payload'
19 ];
20
21 public static function boot()
22 {
23 parent::boot();
24
25 static::creating(function ($model) {
26 $model->created_at = current_time('mysql');
27 $model->updated_at = current_time('mysql');
28 });
29
30 static::updating(function ($model) {
31 $model->updated_at = current_time('mysql');
32 });
33
34 static::deleting(function ($model) {
35 NotificationUser::where('notification_id', $model->id)->delete();
36 });
37 }
38
39 public function setPayloadAttribute($payload)
40 {
41 $this->attributes['payload'] = maybe_serialize($payload);
42 }
43
44 public function getPayloadAttribute($payload)
45 {
46 return Helper::safeUnserialize($payload);
47 }
48
49 public function recipients()
50 {
51 $class = __NAMESPACE__ . '\NotificationUser';
52
53 return $this->hasMany($class, 'notification_id', 'id');
54 }
55
56 public function ticket()
57 {
58 $class = __NAMESPACE__ . '\Ticket';
59
60 return $this->belongsTo($class, 'ticket_id', 'id');
61 }
62
63 public function conversation()
64 {
65 $class = __NAMESPACE__ . '\Conversation';
66
67 return $this->belongsTo($class, 'conversation_id', 'id');
68 }
69
70 public function actor()
71 {
72 $class = __NAMESPACE__ . '\Person';
73
74 return $this->belongsTo($class, 'actor_id', 'id');
75 }
76
77 public static function deleteByTicketId($ticketId)
78 {
79 if (!(new NotificationSettings())->notificationTablesExist()) {
80 return;
81 }
82
83 $ticketId = (int) $ticketId;
84
85 if (!$ticketId) {
86 return;
87 }
88
89 (new static())->getConnection()->transaction(function () use ($ticketId) {
90 do {
91 $notificationIds = static::where('ticket_id', $ticketId)
92 ->orderBy('id', 'ASC')
93 ->limit(100)
94 ->pluck('id')
95 ->toArray();
96
97 if ($notificationIds) {
98 NotificationUser::whereIn('notification_id', $notificationIds)->delete();
99 static::whereIn('id', $notificationIds)->delete();
100 }
101 } while ($notificationIds);
102 });
103 }
104
105 public function scopeByCategory($query, $category)
106 {
107 if ($category && $category !== 'all') {
108 $query->where('category', $category);
109 }
110
111 return $query;
112 }
113 }
114