1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under `AGPL-3.0-only, proprietary` license[s]. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/manganel |
7
|
|
|
* @license AGPL-3.0-only, proprietary |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) Peter Maselkowski <[email protected]> |
10
|
|
|
* @link https://maslosoft.com/manganel/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Maslosoft\Manganel\Decorators\QueryBuilder; |
14
|
|
|
|
15
|
|
|
use Maslosoft\Gazebo\PluginFactory; |
16
|
|
|
use Maslosoft\Manganel\Interfaces\ManganelAwareInterface; |
17
|
|
|
use Maslosoft\Manganel\Interfaces\QueryBuilder\ConditionDecoratorInterface; |
18
|
|
|
use Maslosoft\Manganel\Interfaces\QueryBuilder\OperatorDecoratorInterface; |
19
|
|
|
use Maslosoft\Manganel\SearchCriteria; |
20
|
|
|
use Maslosoft\Manganel\Traits\ManganelAwareTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ConditionDecorator |
24
|
|
|
* |
25
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
26
|
|
|
*/ |
27
|
|
|
class ConditionDecorator implements ConditionDecoratorInterface, ManganelAwareInterface |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
use ManganelAwareTrait; |
31
|
|
|
|
32
|
32 |
|
public function decorate(&$conditions, SearchCriteria $criteria) |
33
|
|
|
{ |
34
|
32 |
|
foreach ($criteria->getConditions() as $name => $value) |
35
|
|
|
{ |
36
|
3 |
|
$decorators = (new PluginFactory())->instance($this->manganel->decorators, $criteria, [ |
37
|
3 |
|
OperatorDecoratorInterface::class |
38
|
|
|
]); |
39
|
3 |
|
$condition = []; |
40
|
3 |
|
foreach ($decorators as $decorator) |
41
|
|
|
{ |
42
|
|
|
/* @var $decorator OperatorDecoratorInterface */ |
43
|
3 |
|
if ($decorator->useWith($name, $value)) |
44
|
|
|
{ |
45
|
3 |
|
$decorator->decorate($condition, $name, $value); |
46
|
|
|
} |
47
|
|
|
} |
48
|
3 |
|
if (empty($condition)) |
49
|
|
|
{ |
50
|
|
|
continue; |
51
|
|
|
} |
52
|
3 |
|
$conditions[] = $condition; |
53
|
|
|
} |
54
|
32 |
|
} |
55
|
|
|
|
56
|
3 |
|
public function getKind() |
57
|
|
|
{ |
58
|
3 |
|
return self::KindFilter; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|