This repository was archived by the owner on May 29, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExtension.php
More file actions
97 lines (82 loc) · 3.03 KB
/
Copy pathExtension.php
File metadata and controls
97 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php namespace Thoughtco\KitchenDisplay;
use AdminAuth;
use Admin\Facades\AdminLocation;
use Admin\Widgets\Form;
use DB;
use Event;
use System\Classes\BaseExtension;
use Thoughtco\KitchenDisplay\Models\Views as KitchenViews;
/**
* Extension Information File
**/
class Extension extends BaseExtension
{
public function boot()
{
Event::listen('admin.list.extendColumns', function (&$widget) {
if ($widget->getController() instanceof \Thoughtco\KitchenDisplay\Controllers\Views){
if (!AdminAuth::user()->hasPermission('Thoughtco.KitchenDisplay.Manage')) {
$widget->removeColumn('edit');
}
}
});
Event::listen('admin.toolbar.extendButtons', function (&$widget) {
if ($widget->getController() instanceof \Thoughtco\KitchenDisplay\Controllers\Views){
if (!AdminAuth::user()->hasPermission('Thoughtco.KitchenDisplay.Manage')) {
$widget->getController()->widgets['toolbar']->removeButton('create');
$widget->getController()->widgets['toolbar']->removeButton('delete');
}
}
});
Event::listen('admin.list.extendQuery', function ($listWidget, $query) {
if (AdminAuth::isSuperUser())
return;
if ($listWidget->getController() instanceof \Thoughtco\KitchenDisplay\Controllers\Views) {
// build list of views the user is allowed to access by location
$viewList = KitchenViews::where(['is_enabled' => true])
->get()
->map(function($view) {
if (AdminLocation::getId() === NULL || in_array(AdminLocation::getId(), $view->locations)) {
$limitedUsers = array_get($view->display, 'users_limit', []);
// if users is blank or in array
if (!count($limitedUsers) OR in_array(AdminAuth::getId(), $limitedUsers))
return $view->id;
}
return;
})
->whereNotNull();
$query->whereIn('id', $viewList->toArray());
}
});
}
public function registerPermissions()
{
return [
'Thoughtco.KitchenDisplay.Manage' => [
'description' => 'Manage Kitchen Display views',
'group' => 'module',
],
'Thoughtco.KitchenDisplay.View' => [
'description' => 'View orders ready to process',
'group' => 'module',
],
];
}
public function registerNavigation()
{
return [
'sales' => [
'child' => [
'summary' => [
'priority' => 10,
'class' => 'pages',
'href' => admin_url('thoughtco/kitchendisplay/views'),
'title' => lang('lang:thoughtco.kitchendisplay::default.text_title'),
'permission' => 'Thoughtco.KitchenDisplay.View',
],
],
],
];
}
}
?>