PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.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 All 69 releases
← All changes | app/Models/Conversation.php +99 -8 1.5.0 → 2.4.5 View file →
@@ -1,8 +1,11 @@
1 1 <?php
2 2
3 3 namespace FluentSupport\App\Models;
4 4
5 +use FluentSupport\App\Services\Helper;
6 +use FluentSupport\Framework\Support\Arr;
7 +
5 8 class Conversation extends Model
6 9 {
7 10 protected $table = 'fs_conversations';
8 11
@@ -22,17 +25,30 @@
22 25 ];
23 26
24 27 public static function boot()
25 28 {
29 + parent::boot();
30 +
26 31 static::creating(function ($model) {
27 32 if(empty($model->content_hash)) {
28 33 $model->content_hash = md5($model->content);
29 34 }
35 + $model->created_at = current_time('mysql');
36 + $model->updated_at = current_time('mysql');
30 37 });
38 +
39 + static::deleting(function ($model) {
40 + //Delete cc info
41 + Meta::where('object_type', 'response')->where('object_id', $model->id)->delete();
42 + // Attachment files first, then their rows
43 + $class = __NAMESPACE__ . '\Attachment';
44 + $attachments = $class::where('conversation_id', $model->id)->get();
45 + $class::purgeAttachments($attachments);
46 + $class::where('conversation_id', $model->id)->delete();
47 + });
31 48 }
32 49
33 50 /**
34 - * $searchable Columns in table to search
35 51 * @var array
36 52 */
37 53 protected $searchable = [
38 54 'content'
@@ -38,9 +54,8 @@
38 54 'content'
39 55 ];
40 56
41 57 /**
42 - * Local scope to filter subscribers by search/query string
43 58 * @param ModelQueryBuilder $query
44 59 * @param string $search
45 60 * @return ModelQueryBuilder
46 61 */
@@ -60,22 +75,20 @@
60 75 return $query;
61 76 }
62 77
63 78 /**
64 - * Local scope to filter subscribers by search/query string
65 79 * @param ModelQueryBuilder $query
66 - * @param string $type
80 + * @param array $type
67 81 * @return ModelQueryBuilder
68 82 */
69 83 public function scopeFilterByType($query, $type)
70 84 {
71 - $query->where('conversation_type', $type);
85 + $query->whereIn('conversation_type', $type);
72 86
73 87 return $query;
74 88 }
75 89
76 90 /**
77 - * One2Many: Customer has to many Click Tickets
78 91 * @return Model Collection
79 92 */
80 93 public function ticket()
81 94 {
@@ -86,9 +99,8 @@
86 99 );
87 100 }
88 101
89 102 /**
90 - * One2Many: Customer has to many Click Tickets
91 103 * @return Model Collection
92 104 */
93 105 public function person()
94 106 {
@@ -99,9 +111,9 @@
99 111 );
100 112 }
101 113
102 114 /**
103 - * A Conversation belongs to a Customer.
115 + * Alias of person(). The author may be an agent, not only a customer.
104 116 *
105 117 * @return \FluentSupport\App\Models\Model
106 118 */
107 119 public function customer()
@@ -112,7 +124,86 @@
112 124 public function attachments()
113 125 {
114 126 $class = __NAMESPACE__ . '\Attachment';
115 127 return $this->hasMany($class, 'conversation_id', 'id');
128 + }
129 +
130 + /**
131 + * CC info stored in fs_meta.
132 + *
133 + * @return Model Collection
134 + */
135 + public function ccinfo()
136 + {
137 + $class = __NAMESPACE__ . '\Meta';
138 +
139 + return $this->hasOne(
140 + $class, 'object_id', 'id'
141 + )->where('object_type', 'response')->where('key', 'settings');
142 + }
143 +
144 +
145 + public function getSettingsValue($valueKey = false, $default = false)
146 + {
147 + $exist = Meta::where('object_type', 'response')
148 + ->where('key', 'settings')
149 + ->where('object_id', $this->id)
150 + ->first();
151 +
152 + if ($exist) {
153 + $value = Helper::safeUnserialize($exist->value);
154 + if ($valueKey) {
155 + if (!is_array($value)) {
156 + return $default;
157 + }
158 + return Arr::get($value, $valueKey, $default);
159 + }
160 + return $value;
161 + }
162 +
163 + return $default;
164 + }
165 +
166 + public function updateSettingsValue($valueKey, $value)
167 + {
168 + $exist = Meta::where('object_type', 'response')
169 + ->where('key', 'settings')
170 + ->where('object_id', $this->id)
171 + ->first();
172 +
173 + if ($exist) {
174 + $existingValue = Helper::safeUnserialize($exist->value);
175 +
176 + if (!is_array($existingValue)) {
177 + $existingValue = [];
178 + }
179 +
180 + $existingValue[$valueKey] = $value;
181 +
182 + $exist->value = maybe_serialize($existingValue);
183 + $exist->save();
184 + return $this;
185 + }
186 +
187 + $settings = [
188 + 'object_type' => 'response',
189 + 'key' => 'settings',
190 + 'object_id' => $this->id,
191 + 'value' => maybe_serialize([
192 + $valueKey => $value
193 + ])
194 + ];
195 +
196 + Meta::create($settings);
197 +
198 + return $this;
199 +
200 + }
201 +
202 + public static function deleteAll($ticketId){
203 + $conversations = Conversation::where('ticket_id', $ticketId)->get();
204 + foreach ($conversations as $conversation) {
205 + $conversation->delete();
206 + }
116 207 }
117 208
118 209 }