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