|
1
|
|
|
<?php namespace Arcanesoft\Auth\ViewComposers; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Models\Permission; |
|
4
|
|
|
use Arcanesoft\Auth\Models\PermissionsGroup; |
|
5
|
|
|
use Illuminate\Contracts\View\View; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class PermissionGroupsFilterComposer |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanesoft\Auth\ViewComposers |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class PermissionGroupsFilterComposer extends ViewComposer |
|
15
|
|
|
{ |
|
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
| Constant |
|
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
19
|
|
|
*/ |
|
20
|
|
|
const VIEW = 'auth::admin._composers.permission-groups-filter'; |
|
21
|
|
|
|
|
22
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
23
|
|
|
| Main Functions |
|
24
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
25
|
|
|
*/ |
|
26
|
|
|
/** |
|
27
|
|
|
* Compose the view. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Illuminate\Contracts\View\View $view |
|
30
|
|
|
*/ |
|
31
|
|
|
public function compose(View $view) |
|
32
|
|
|
{ |
|
33
|
|
|
$view->with('permissionGroupsFilters', $this->getFilters()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
37
|
|
|
| Other Functions |
|
38
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
39
|
|
|
*/ |
|
40
|
|
|
/** |
|
41
|
|
|
* Get the groups filters data. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Illuminate\Support\Collection |
|
44
|
|
|
*/ |
|
45
|
|
|
private function getFilters() |
|
46
|
|
|
{ |
|
47
|
|
|
$filters = new Collection; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($this->getCachedPermissionGroups() as $group) { |
|
50
|
|
|
/** @var \Arcanesoft\Auth\Models\PermissionsGroup $group */ |
|
51
|
|
|
$filters->push([ |
|
52
|
|
|
'name' => $group->name, |
|
53
|
|
|
'params' => [$group->hashed_id], |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Custom Permission group |
|
58
|
|
|
//---------------------------------- |
|
59
|
|
|
if (Permission::where('group_id', 0)->count()) { |
|
60
|
|
|
$filters->push([ |
|
61
|
|
|
'name' => 'Custom', |
|
62
|
|
|
'params' => [hasher()->encode(0)], |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $filters; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the cached permission groups. |
|
71
|
|
|
* |
|
72
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
|
73
|
|
|
*/ |
|
74
|
|
|
private function getCachedPermissionGroups() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->cacheResults('permissions-groups.filters', function () { |
|
77
|
|
|
return PermissionsGroup::has('permissions')->get(); |
|
78
|
|
|
}); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|