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
fluent-support / app / Models / Agent.php

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

97 lines 2.1 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\Models\Traits\AgentTrait;
6
7 class Agent extends Person
8 {
9 use AgentTrait;
10
11 protected static $type = 'agent';
12
13 protected $searchable = [
14 'id',
15 'first_name',
16 'last_name',
17 'email',
18 'address_line_1',
19 'address_line_2',
20 'country'
21 ];
22
23 /**
24 * @return array
25 */
26 public function getSearchableFields(){
27 return $this->searchable;
28 }
29
30 /**
31 * Agent ids, cached per request. Reporting filters on these ids because
32 * whereHas('person') hits fs_persons, which has no person_type index.
33 *
34 * @return array
35 */
36 public static function getAgentIds()
37 {
38 static $agentIds = null;
39
40 if (is_null($agentIds)) {
41 $agentIds = array_map('intval', static::query()->pluck('id')->all());
42 }
43
44 return $agentIds;
45 }
46
47 public static function boot()
48 {
49 parent::boot();
50
51 static::creating(function ($model) {
52 $model->person_type = static::$type;
53 $model->hash = md5(time().wp_generate_uuid4());
54 });
55
56 static::addGlobalScope(function ($builder) {
57 $builder->where('person_type', 'agent');
58 });
59 }
60
61
62 /**
63 * @return Model Collection
64 */
65 public function tickets()
66 {
67 $foreign_key = self::$type . '_id';
68
69 $class = __NAMESPACE__ . '\Ticket';
70
71 return $this->hasMany(
72 $class, $foreign_key, 'id'
73 );
74 }
75
76 public function groups()
77 {
78 return $this->belongsToMany(
79 AgentGroup::class, 'fs_tag_pivot', 'source_id', 'tag_id'
80 )->wherePivot('source_type', 'agent_group');
81 }
82
83 public function scopeMentionBy($query, $search)
84 {
85 if (!$search) {
86 return $query;
87 }
88
89 return $query->where(function ($q) use ($search) {
90 $q->where('first_name', 'LIKE', '%' . $search . '%')
91 ->orWhere('last_name', 'LIKE', '%' . $search . '%')
92 ->orWhere('email', 'LIKE', '%' . $search . '%');
93 });
94 }
95
96 }
97