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
|
<?php
/**
* UserFrosting (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
*/
namespace UserFrosting\Sprinkle\Admin\Sprunje;
use Illuminate\Database\Capsule\Manager as Capsule;
use UserFrosting\Sprinkle\Core\Facades\Debug;
use UserFrosting\Sprinkle\Core\Sprunje\Sprunje;
/**
* PermissionSprunje
*
* Implements Sprunje for the permissions API.
*
* @author Alex Weissman (https://alexanderweissman.com)
*/
class PermissionSprunje extends Sprunje
{
protected $name = 'permissions';
protected $sortable = [
'name',
'properties'
];
protected $filterable = [
'name',
'properties',
'info'
];
protected $excludeForAll = [
'info'
];
/**
* {@inheritDoc}
*/
protected function baseQuery()
{
return $this->classMapper->createInstance('permission')->newQuery();
}
/**
* Filter LIKE the slug, conditions, or description.
*
* @param Builder $query
* @param mixed $value
* @return $this
*/
protected function filterInfo($query, $value)
{
return $this->filterProperties($query, $value);
}
/**
* Filter LIKE the slug, conditions, or description.
*
* @param Builder $query
* @param mixed $value
* @return $this
*/
protected function filterProperties($query, $value)
{
// Split value on separator for OR queries
$values = explode($this->orSeparator, $value);
$query->where(function ($query) use ($values) {
foreach ($values as $value) {
$query->orLike('slug', $value)
->orLike('conditions', $value)
->orLike('description', $value);
}
});
return $this;
}
/**
* Sort based on slug.
*
* @param Builder $query
* @param string $direction
* @return $this
*/
protected function sortProperties($query, $direction)
{
$query->orderBy('slug', $direction);
return $this;
}
}
|