1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Helper; |
4
|
|
|
|
5
|
|
|
use App\Model\helpdesk\Agent\Department; |
6
|
|
|
use App\Model\helpdesk\Agent\Groups; |
7
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Status; |
8
|
|
|
use App\Model\helpdesk\Ticket\TicketStatusType; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
*------------------------------------------------------------------ |
12
|
|
|
* Class Finder |
13
|
|
|
*------------------------------------------------------------------ |
14
|
|
|
* Description: This class is used for defining some common functions |
15
|
|
|
* used in the project. |
16
|
|
|
* |
17
|
|
|
* @author <Ladybird Web Solution> |
18
|
|
|
*/ |
19
|
|
|
class Finder |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* DEPARTMENT |
23
|
|
|
* This function is used for returning department name with respect to id. |
24
|
|
|
* |
25
|
|
|
* @param $id type int |
26
|
|
|
* @param $custom type array/null |
27
|
|
|
* |
28
|
|
|
* @return type string |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public static function department($id, $custom = null) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
if ($custom == null) { |
33
|
|
|
$department = Department::whereId($id)->select(['name']); |
34
|
|
|
} elseif (isset($custom)) { |
35
|
|
|
$department = Department::whereId($id)->select($custom); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $department->first()->name; |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* GROUP |
43
|
|
|
* This function is used for returning group name with respect to id. |
44
|
|
|
* |
45
|
|
|
* @param $id type int |
46
|
|
|
* @param $custom type array/null |
47
|
|
|
* |
48
|
|
|
* @return type string |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public static function group($id, $custom = null) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
if ($custom == null) { |
53
|
|
|
$group = Groups::whereId($id)->select(['name']); |
54
|
|
|
} elseif (isset($custom)) { |
55
|
|
|
$group = Groups::whereId($id)->select($custom); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $group->first()->name; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* STATUS TYPE |
63
|
|
|
* This function is used for returning status type name with respect to id. |
64
|
|
|
* |
65
|
|
|
* @param $id type int |
66
|
|
|
* @param $custom type array/null |
67
|
|
|
* |
68
|
|
|
* @return type string |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public static function statusType($id, $custom = null) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
if ($custom == null) { |
73
|
|
|
$status_type = TicketStatusType::whereId($id)->select(['name']); |
74
|
|
|
} elseif (isset($custom)) { |
75
|
|
|
$status_type = TicketStatusType::whereId($id)->select($custom); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $status_type->first()->name; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* STATUS |
83
|
|
|
* This function is used for returning status name with respect to id. |
84
|
|
|
* |
85
|
|
|
* @param $id type int |
86
|
|
|
* @param $custom type array/null |
87
|
|
|
* |
88
|
|
|
* @return type string |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
public static function status($id, $custom = null) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
if ($custom == null) { |
93
|
|
|
$status = Ticket_Status::whereId($id)->first(); |
94
|
|
|
} elseif (isset($custom)) { |
95
|
|
|
$status = Ticket_Status::whereId($id)->select($custom); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $status; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* USER ROLES IN A GROUP FOR STATUS LIST |
103
|
|
|
* This function is used to return roles of users from a given value. |
104
|
|
|
* If the value is 1 the response is client |
105
|
|
|
* If the value is 2 the response is agent |
106
|
|
|
* If the value is 4 the response is admin |
107
|
|
|
* If the value is 1+2 = 3 the response is client, agent |
108
|
|
|
* If the value is 1+4 = 5 the response is client, admin |
109
|
|
|
* If the value is 2+4 = 6 the response is agent, admin |
110
|
|
|
* If the value is 1+2+4 = 7 the response is client, agent, admin. |
111
|
|
|
* |
112
|
|
|
* @param $id type int |
113
|
|
|
* |
114
|
|
|
* @return type string |
115
|
|
|
*/ |
116
|
|
|
public static function rolesGroup($id) |
117
|
|
|
{ |
118
|
|
|
switch ($id) { |
119
|
|
|
case null: |
120
|
|
|
return \Lang::get('lang.none'); |
121
|
|
|
case 1: |
122
|
|
|
return 'Client'; |
|
|
|
|
123
|
|
|
case 2: |
124
|
|
|
return 'Agent'; |
|
|
|
|
125
|
|
|
case 4: |
126
|
|
|
return 'Admin'; |
|
|
|
|
127
|
|
|
case 3: |
128
|
|
|
return 'Client,Agent'; |
|
|
|
|
129
|
|
|
case 5: |
130
|
|
|
return 'Client,Admin'; |
|
|
|
|
131
|
|
|
case 6: |
132
|
|
|
return 'Agent,Admin'; |
|
|
|
|
133
|
|
|
case 7: |
134
|
|
|
return 'Client,Agent,Admin'; |
|
|
|
|
135
|
|
|
default: |
136
|
|
|
return 'Undefined!'; |
|
|
|
|
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* ANY TYPE STATUS |
142
|
|
|
* This function is used to return the set of status which are of any type passed in the param. |
143
|
|
|
* |
144
|
|
|
* @param type $id |
145
|
|
|
* |
146
|
|
|
* @return type array |
147
|
|
|
*/ |
148
|
|
|
public static function anyTypeStatus($id) |
149
|
|
|
{ |
150
|
|
|
$status_group = Ticket_Status::where('purpose_of_status', '=', $id)->select(['id'])->get(); |
151
|
|
|
foreach ($status_group as $status) { |
152
|
|
|
$status_group2[] = $status->id; |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $status_group2; |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* RETURNS ALL STATUS |
160
|
|
|
* This function is used to return all the status given in the system. |
161
|
|
|
* |
162
|
|
|
* @return type array |
163
|
|
|
*/ |
164
|
|
|
public static function getAllStatus() |
165
|
|
|
{ |
166
|
|
|
$status = Ticket_Status::where('purpose_of_status', '!=', 3)->orwhere('purpose_of_status', '!=', 4)->get(); |
167
|
|
|
|
168
|
|
|
return $status; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* VARIABLE REPLACEMENT |
173
|
|
|
* This function is used to replace the replaceable variables form a given content for templates. |
174
|
|
|
*/ |
175
|
|
|
public static function replaceTemplateVariables($variables, $data, $contents) |
176
|
|
|
{ |
177
|
|
View Code Duplication |
foreach ($variables as $key => $variable) { |
|
|
|
|
178
|
|
|
$messagebody = str_replace($variables[$key], $data[$key], $contents); |
179
|
|
|
$contents = $messagebody; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $contents; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.