1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sfneal\Users\Builders; |
4
|
|
|
|
5
|
|
|
use Sfneal\Builders\QueryBuilder; |
6
|
|
|
|
7
|
|
|
class RoleBuilder extends QueryBuilder |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Scope Role query to roles of a particular type. |
11
|
|
|
* |
12
|
|
|
* @param string $type |
13
|
|
|
* @param string $operator |
14
|
|
|
* @param string $boolean |
15
|
|
|
* |
16
|
|
|
* @return $this |
17
|
|
|
*/ |
18
|
|
|
public function whereType(string $type, string $operator = '=', string $boolean = 'and') |
19
|
|
|
{ |
20
|
|
|
$this->where('type', $operator, $type, $boolean); |
21
|
|
|
|
22
|
|
|
return $this; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Scope Role query to only 'user' type roles. |
27
|
|
|
* |
28
|
|
|
* @param string $operator |
29
|
|
|
* @param string $boolean |
30
|
|
|
* |
31
|
|
|
* @return $this |
32
|
|
|
*/ |
33
|
|
|
public function whereTypeUser(string $operator = '=', string $boolean = 'and') |
34
|
|
|
{ |
35
|
|
|
$this->whereType('user', $operator, $boolean); |
36
|
|
|
|
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Scope query results to Role's matching a role 'name'. |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* @param string $operator |
45
|
|
|
* @param string $boolean |
46
|
|
|
* @return $this |
47
|
|
|
*/ |
48
|
|
|
public function whereName(string $name, string $operator = '=', string $boolean = 'and'): self |
49
|
|
|
{ |
50
|
|
|
$this->where('name', $operator, ucwords($name), $boolean); |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Scope query results to Role's that do NOT have a particular role 'name'. |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* @param string $boolean |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function whereNameNot(string $name, string $boolean = 'and'): self |
63
|
|
|
{ |
64
|
|
|
$this->whereName($name, '!=', $boolean); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Scope query results to Role's with names that are in the array of $names. |
71
|
|
|
* |
72
|
|
|
* @param array $names |
73
|
|
|
* @param string $boolean |
74
|
|
|
* @param bool $not |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function whereNameIn(array $names, string $boolean = 'and', bool $not = false): self |
78
|
|
|
{ |
79
|
|
|
$this->whereIn('name', $names, $boolean, $not); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Scope query results to Role's with names that are NOT in the array of $names. |
86
|
|
|
* |
87
|
|
|
* @param array $names |
88
|
|
|
* @param string $boolean |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
|
|
public function whereNameNotIn(array $names, string $boolean = 'and'): self |
92
|
|
|
{ |
93
|
|
|
$this->whereIn('name', $names, $boolean, true); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|