1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipboxfactory/craft-ember/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\ember\queries; |
10
|
|
|
|
11
|
|
|
use craft\db\Query; |
12
|
|
|
use craft\helpers\Db; |
13
|
|
|
use craft\models\UserGroup; |
14
|
|
|
use craft\records\UserGroup as UserGroupRecord; |
15
|
|
|
use flipbox\craft\ember\helpers\QueryHelper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 2.0.0 |
20
|
|
|
*/ |
21
|
|
|
trait UserGroupAttributeTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The user group(s) that the resulting organizations’ users must be in. |
25
|
|
|
* |
26
|
|
|
* @var string|string[]|int|int[]|UserGroup|UserGroup[]|null |
27
|
|
|
*/ |
28
|
|
|
public $userGroup; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value |
32
|
|
|
* @return static The query object |
33
|
|
|
*/ |
34
|
|
|
public function setUserGroup($value) |
35
|
|
|
{ |
36
|
|
|
$this->userGroup = $value; |
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value |
42
|
|
|
* @return static The query object |
43
|
|
|
*/ |
44
|
|
|
public function userGroup($value) |
45
|
|
|
{ |
46
|
|
|
return $this->setUserGroup($value); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value |
51
|
|
|
* @return static The query object |
52
|
|
|
*/ |
53
|
|
|
public function setUserGroupId($value) |
54
|
|
|
{ |
55
|
|
|
return $this->setUserGroup($value); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value |
60
|
|
|
* @return static The query object |
61
|
|
|
*/ |
62
|
|
|
public function userGroupId($value) |
63
|
|
|
{ |
64
|
|
|
return $this->setUserGroup($value); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $value |
69
|
|
|
* @return array|string |
70
|
|
|
*/ |
71
|
|
|
protected function parseUserGroupValue($value) |
72
|
|
|
{ |
73
|
|
|
return QueryHelper::prepareParam( |
74
|
|
|
$value, |
75
|
|
|
function(string $handle) { |
76
|
|
|
$value = (new Query()) |
77
|
|
|
->select(['id']) |
78
|
|
|
->from([UserGroupRecord::tableName()]) |
79
|
|
|
->where(Db::parseParam('handle', $handle)) |
|
|
|
|
80
|
|
|
->scalar(); |
81
|
|
|
return empty($value) ? false : $value; |
82
|
|
|
} |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.