Skip to content

Commit 7e822ee

Browse files
committed
Patch: Delete of redundant usage of \PanicHDMember within Member model
1 parent 01da94d commit 7e822ee

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

src/Models/Member.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,12 @@ public function isTicketOwner($id)
147147
*/
148148
public function maxLevel()
149149
{
150-
$member = \PanicHDMember::find(auth()->user()->id);
151-
if ($member->isAdmin()) {
150+
if ($this->isAdmin()) {
152151
return 3;
153-
} elseif ($member->isAgent()) {
152+
153+
} elseif ($this->isAgent()) {
154154
return 2;
155+
155156
} else {
156157
return 1;
157158
}
@@ -166,15 +167,16 @@ public function maxLevel()
166167
*/
167168
public function currentLevel()
168169
{
169-
$member = \PanicHDMember::find(auth()->user()->id);
170-
if ($member->isAdmin()) {
170+
if ($this->isAdmin()) {
171171
return 3;
172-
} elseif ($member->isAgent()) {
172+
173+
} elseif ($this->isAgent()) {
173174
if (session()->exists('panichd_filter_currentLevel') and session('panichd_filter_currentLevel') == 1) {
174175
return 1;
175176
} else {
176177
return 2;
177178
}
179+
178180
} else {
179181
return 1;
180182
}
@@ -215,20 +217,18 @@ public function levelInCategory($id = false)
215217
*/
216218
public function canCloseTicket($id)
217219
{
218-
$member = \PanicHDMember::find(auth()->user()->id);
219-
220220
$a_perm = Setting::grab('close_ticket_perm');
221221

222-
if ($member->isAdmin() && $a_perm['admin'] == 'yes') {
222+
if ($this->isAdmin() && $a_perm['admin'] == 'yes') {
223223
return true;
224224
}
225225
if ($ticket = Ticket::find($id)) {
226-
if ($member->id == $ticket->agent_id or (Setting::grab('agent_restrict') == 0 and $member->categories()->where('id', $ticket->category_id)->count() == 1)) {
226+
if ($this->id == $ticket->agent_id or (Setting::grab('agent_restrict') == 0 and $this->categories()->where('id', $ticket->category_id)->count() == 1)) {
227227
return true;
228228
}
229229
}
230230

231-
if ($member->isTicketOwner($id) && $a_perm['owner'] == 'yes') {
231+
if ($this->isTicketOwner($id) && $a_perm['owner'] == 'yes') {
232232
return true;
233233
}
234234

@@ -262,13 +262,11 @@ public function canCommentTicket($ticket)
262262
*/
263263
public function canManageTicket($id)
264264
{
265-
$member = \PanicHDMember::find(auth()->user()->id);
266-
267-
if ($member->isAdmin()) {
265+
if ($this->isAdmin()) {
268266
return true;
269267

270268
} elseif ($ticket = Ticket::find($id)) {
271-
if ($member->id == $ticket->agent_id or (Setting::grab('agent_restrict') == 0 and $member->categories()->where('id', $ticket->category_id)->count() == 1)) {
269+
if ($this->id == $ticket->agent_id or (Setting::grab('agent_restrict') == 0 and $this->categories()->where('id', $ticket->category_id)->count() == 1)) {
272270
return true;
273271
}
274272
}
@@ -285,13 +283,12 @@ public function canManageTicket($id)
285283
*/
286284
public function canViewNewTickets()
287285
{
288-
$member = \PanicHDMember::find(auth()->user()->id);
289-
290-
if ($member->isAdmin()) {
286+
if ($this->isAdmin()) {
291287
return true;
292-
} elseif ($member->isAgent() and $member->currentLevel() == 2) {
288+
289+
} elseif ($this->isAgent() and $this->currentLevel() == 2) {
293290
if (Setting::grab('agent_restrict') == 1) {
294-
return $member->categories()->wherePivot('autoassign', '1')->count() == 0 ? false : true;
291+
return $this->categories()->wherePivot('autoassign', '1')->count() == 0 ? false : true;
295292
} else {
296293
return true;
297294
}
@@ -485,9 +482,7 @@ public function scopeVisible($query)
485482
*/
486483
public function scopeVisibleForAgent($query, $id)
487484
{
488-
$member = \PanicHDMember::findOrFail($id);
489-
490-
if ($member->currentLevel() == 2) {
485+
if ($this->currentLevel() == 2) {
491486
// Depends on agent_restrict
492487
if (Setting::grab('agent_restrict') == 0) {
493488
return $query->whereHas('categories', function ($q1) use ($id) {

0 commit comments

Comments
 (0)