PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.0
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.0
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 1.5.5 All 68 releases
fluent-support / app / Models / Conversation.php

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

117 lines 2.5 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 class Conversation extends Model
6 {
7 protected $table = 'fs_conversations';
8
9 /**
10 * The attributes that are mass assignable.
11 *
12 * @var array
13 */
14 protected $fillable = [
15 'ticket_id',
16 'person_id',
17 'message_id',
18 'conversation_type',
19 'content',
20 'source',
21 'is_important'
22 ];
23
24 public static function boot()
25 {
26 static::creating(function ($model) {
27 $model->content_hash = md5($model->content);
28 });
29 }
30
31 /**
32 * $searchable Columns in table to search
33 * @var array
34 */
35 protected $searchable = [
36 'content'
37 ];
38
39 /**
40 * Local scope to filter subscribers by search/query string
41 * @param ModelQueryBuilder $query
42 * @param string $search
43 * @return ModelQueryBuilder
44 */
45 public function scopeSearchBy($query, $search)
46 {
47 if ($search) {
48 $fields = $this->searchable;
49 $query->where(function ($query) use ($fields, $search) {
50 $query->where(array_shift($fields), 'LIKE', "%$search%");
51
52 foreach ($fields as $field) {
53 $query->orWhere($field, 'LIKE', "$search%");
54 }
55 });
56 }
57
58 return $query;
59 }
60
61 /**
62 * Local scope to filter subscribers by search/query string
63 * @param ModelQueryBuilder $query
64 * @param string $type
65 * @return ModelQueryBuilder
66 */
67 public function scopeFilterByType($query, $type)
68 {
69 $query->where('conversation_type', $type);
70
71 return $query;
72 }
73
74 /**
75 * One2Many: Customer has to many Click Tickets
76 * @return Model Collection
77 */
78 public function ticket()
79 {
80 $class = __NAMESPACE__ . '\Ticket';
81
82 return $this->belongsTo(
83 $class, 'ticket_id', 'id'
84 );
85 }
86
87 /**
88 * One2Many: Customer has to many Click Tickets
89 * @return Model Collection
90 */
91 public function person()
92 {
93 $class = __NAMESPACE__ . '\Person';
94
95 return $this->belongsTo(
96 $class, 'person_id', 'id'
97 );
98 }
99
100 /**
101 * A Conversation belongs to a Customer.
102 *
103 * @return \FluentSupport\App\Models\Model
104 */
105 public function customer()
106 {
107 return $this->person();
108 }
109
110 public function attachments()
111 {
112 $class = __NAMESPACE__ . '\Attachment';
113 return $this->hasMany($class, 'conversation_id', 'id');
114 }
115
116 }
117