Skip to content

Commit 60669dd

Browse files
committed
Allow of loading notices widget without logged user
1 parent a3abc58 commit 60669dd

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/Models/Ticket.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ public function isNew()
9797
public function scopeActive($query)
9898
{
9999
$query = $query->whereNull('completed_at');
100-
101-
$member = \PanicHDMember::findOrFail(auth()->user()->id);
102-
if ($member->currentLevel() >= 2){
103-
return $query->where('status_id', '!=', Setting::grab('default_status_id'));
104-
}else{
105-
return $query;
106-
}
100+
101+
if (is_null(auth()->user()) or \PanicHDMember::find(auth()->user()->id)->currentLevel() < 2){
102+
return $query;
103+
}else{
104+
return $query->where('status_id', '!=', Setting::grab('default_status_id'));
105+
}
107106
}
108107

109108
/**

src/PanicHDServiceProvider.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,20 @@ public function boot()
204204
// Notices widget
205205
view()->composer(['panichd::notices.widget', 'panichd::notices.index'], function ($view) {
206206
if (Setting::grab('departments_notices_feature')){
207-
// Get notices from related users
208-
$a_notices = Ticket::active()->notHidden()->whereIn('user_id', \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers())
207+
// Get available notice users list
208+
if(is_null(auth()->user())){
209+
$all_dept_users = \PanicHDMember::where('ticketit_department','0');
210+
if (version_compare(app()->version(), '5.3.0', '>=')) {
211+
$a_notice_users = $all_dept_users->pluck('id')->toArray();
212+
}else{
213+
$a_notice_users = $all_dept_users->lists('id')->toArray();
214+
}
215+
}else{
216+
$a_notice_users = \PanicHDMember::find(auth()->user()->id)->getMyNoticesUsers();
217+
}
218+
219+
// Get notices
220+
$a_notices = Ticket::active()->notHidden()->whereIn('user_id', $a_notice_users)
209221
->join('panichd_priorities', 'priority_id', '=', 'panichd_priorities.id')
210222
->select('panichd_tickets.*')
211223
->with('owner.department')

0 commit comments

Comments
 (0)