PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.4
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.4
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.5.4, at app/Models/Conversation.php

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