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\base\ElementInterface; |
12
|
|
|
use craft\db\Query; |
13
|
|
|
use flipbox\craft\ember\helpers\QueryHelper; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Flipbox Factory <[email protected]> |
17
|
|
|
* @since 2.0.0 |
18
|
|
|
*/ |
19
|
|
|
trait ElementAttributeTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The element(s) that the resulting organizations’ elements must have. |
23
|
|
|
* |
24
|
|
|
* @var string|string[]|int|int[]|ElementInterface|ElementInterface[]|null |
25
|
|
|
*/ |
26
|
|
|
public $element; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string|string[]|int|int[]|ElementInterface|ElementInterface[]|null $value |
30
|
|
|
* @return static The query object |
31
|
|
|
*/ |
32
|
|
|
public function setElement($value) |
33
|
|
|
{ |
34
|
|
|
$this->element = $value; |
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string|string[]|int|int[]|ElementInterface|ElementInterface[]|null $value |
40
|
|
|
* @return static The query object |
41
|
|
|
*/ |
42
|
|
|
public function element($value) |
43
|
|
|
{ |
44
|
|
|
return $this->setElement($value); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string|string[]|int|int[]|ElementInterface|ElementInterface[]|null $value |
49
|
|
|
* @return static The query object |
50
|
|
|
*/ |
51
|
|
|
public function setElementId($value) |
52
|
|
|
{ |
53
|
|
|
return $this->setElement($value); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string|string[]|int|int[]|ElementInterface|ElementInterface[]|null $value |
58
|
|
|
* @return static The query object |
59
|
|
|
*/ |
60
|
|
|
public function elementId($value) |
61
|
|
|
{ |
62
|
|
|
return $this->setElement($value); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $value |
67
|
|
|
* @return array|string |
68
|
|
|
*/ |
69
|
|
|
protected function parseElementValue($value) |
70
|
|
|
{ |
71
|
|
|
return QueryHelper::prepareParam( |
72
|
|
|
$value, |
73
|
|
|
function (string $uri) { |
74
|
|
|
$value = (new Query()) |
75
|
|
|
->select(['id']) |
76
|
|
|
->from(['{{%elements_sites}} elements_sites']) |
77
|
|
|
->where(['uri' => $uri]) |
78
|
|
|
->scalar(); |
79
|
|
|
return empty($value) ? false : $value; |
80
|
|
|
} |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|