1 | <?php |
||||
2 | |||||
3 | namespace HexMakina\kadro\Auth; |
||||
4 | |||||
5 | use HexMakina\BlackBox\Auth\OperatorInterface; |
||||
6 | use HexMakina\BlackBox\ORM\ModelInterface; |
||||
7 | use HexMakina\Crudites\Queries\AutoJoin; |
||||
8 | |||||
9 | trait HasOperator |
||||
10 | { |
||||
11 | use \HexMakina\TightORM\HasOne; |
||||
12 | |||||
13 | private $operator = null; |
||||
14 | |||||
15 | abstract public function get($prop_name); |
||||
16 | |||||
17 | public function operator(OperatorInterface $setter = null) |
||||
18 | { |
||||
19 | if (!is_null($setter)) { |
||||
20 | $this->operator = $setter; |
||||
21 | } |
||||
22 | |||||
23 | if (is_null($this->operator)) { |
||||
24 | $extract_attempt = self::extract(new Operator(), $this, true); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
25 | if (!is_null($extract_attempt)) { |
||||
26 | foreach (['permission_names', 'permission_ids'] as $permission_marker) { |
||||
27 | if (property_exists($this, $permission_marker)) { |
||||
28 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
||||
29 | } |
||||
30 | } |
||||
31 | |||||
32 | $this->operator = $extract_attempt; |
||||
33 | } |
||||
34 | } |
||||
35 | |||||
36 | if (is_null($this->operator) && !empty($this->get('operator_id'))) { |
||||
37 | $this->operator = Operator::exists($this->get('operator_id')); |
||||
38 | } |
||||
39 | |||||
40 | return $this->operator; |
||||
41 | } |
||||
42 | |||||
43 | |||||
44 | public static function enhance_query_retrieve($Query, $filters, $options) |
||||
0 ignored issues
–
show
The parameter
$options is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
45 | { |
||||
46 | AutoJoin::join($Query,[ACL::table(),'ACL'], null, 'LEFT OUTER'); |
||||
47 | $permission_alias = AutoJoin::join($Query,[Permission::table(), 'permission'], null, 'LEFT OUTER'); |
||||
48 | |||||
49 | $permission_ids_and_names = []; |
||||
50 | $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $permission_alias, 'id', $permission_alias . '_ids'); |
||||
51 | $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $permission_alias, 'name', $permission_alias . '_names'); |
||||
52 | $Query->selectAlso($permission_ids_and_names); |
||||
53 | |||||
54 | $Query->selectAlso(['operator.name as operator_name', 'operator.active as operator_active']); |
||||
55 | |||||
56 | if (isset($filters['username'])) { |
||||
57 | $Query->whereEQ('username', $filters['username'], 'operator'); |
||||
58 | } |
||||
59 | |||||
60 | if (isset($filters['email'])) { |
||||
61 | $Query->whereEQ('email', $filters['email'], 'operator'); |
||||
62 | } |
||||
63 | |||||
64 | if (isset($filters['active'])) { |
||||
65 | $Query->whereEQ('active', $filters['active'], 'operator'); |
||||
66 | } |
||||
67 | |||||
68 | return $Query; |
||||
69 | } |
||||
70 | } |
||||
71 |