|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the eav package. |
|
4
|
|
|
* @author Aleksandr Drobotik <[email protected]> |
|
5
|
|
|
* @copyright 2023 Aleksandr Drobotik |
|
6
|
|
|
* @license https://opensource.org/license/mit The MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Drobotik\Eav\QueryBuilder; |
|
11
|
|
|
|
|
12
|
|
|
use Drobotik\Eav\Enum\_ATTR; |
|
13
|
|
|
|
|
14
|
|
|
class QueryBuilderAttributes |
|
15
|
|
|
{ |
|
16
|
|
|
private array $attributes = []; |
|
17
|
|
|
private array $joins = []; |
|
18
|
|
|
private array $selected = []; |
|
19
|
|
|
|
|
20
|
|
|
public function setAttributes(array $attributes) : void |
|
21
|
|
|
{ |
|
22
|
|
|
foreach ($attributes as $attribute) |
|
23
|
|
|
$this->appendAttribute($attribute); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getAttributes(): array |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->attributes; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
public function appendAttribute(array $attribute): void |
|
32
|
|
|
{ |
|
33
|
1 |
|
$this->attributes[$attribute[_ATTR::NAME->column()]] = $attribute; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public function getAttribute(string $name) : array |
|
37
|
|
|
{ |
|
38
|
1 |
|
return $this->attributes[$name]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
public function isAttribute(string $name) : bool |
|
42
|
|
|
{ |
|
43
|
1 |
|
return key_exists($name, $this->attributes); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setAttributeJoined(string $name): void |
|
47
|
|
|
{ |
|
48
|
|
|
if(!$this->isAttribute($name)) return; |
|
49
|
|
|
if(!$this->isAttributeJoined($name)) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->joins[] = $name; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function isAttributeJoined(string $name) : bool |
|
56
|
|
|
{ |
|
57
|
|
|
return in_array($name, $this->joins); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function setAttributeSelected(string $name): void |
|
61
|
|
|
{ |
|
62
|
|
|
if(!$this->isAttribute($name)) return; |
|
63
|
|
|
if(!$this->isAttributeJoined($name)) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->selected[] = $name; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function isAttributeSelected(string $name) : bool |
|
70
|
|
|
{ |
|
71
|
|
|
return in_array($name, $this->selected); |
|
72
|
|
|
} |
|
73
|
|
|
} |