|
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\Helpers; |
|
14
|
|
|
|
|
15
|
|
|
use Maslosoft\Manganel\Decorators\QueryBuilder\MultiModelDecorator; |
|
16
|
|
|
use Maslosoft\Manganel\Decorators\QueryBuilder\SingleModelDecorator; |
|
17
|
|
|
use Maslosoft\Manganel\Interfaces\ModelsAwareInterface; |
|
18
|
|
|
use Maslosoft\Manganel\Manganel; |
|
19
|
|
|
use Maslosoft\Manganel\SearchCriteria; |
|
20
|
|
|
use Maslosoft\Manganel\Traits\UniqueModelsAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* QueryBuilderDecorator |
|
24
|
|
|
* |
|
25
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
26
|
|
|
*/ |
|
27
|
|
|
class QueryBuilderDecorator implements ModelsAwareInterface |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
use UniqueModelsAwareTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Manganel instance |
|
34
|
|
|
* @var Manganel |
|
35
|
|
|
*/ |
|
36
|
|
|
private $manganel = null; |
|
37
|
|
|
|
|
38
|
32 |
|
public function __construct(Manganel $manganel) |
|
39
|
|
|
{ |
|
40
|
32 |
|
$this->manganel = $manganel; |
|
41
|
32 |
|
} |
|
42
|
|
|
|
|
43
|
32 |
|
public function decorate(&$body, SearchCriteria $criteria) |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
32 |
|
$models = $this->getModels(); |
|
47
|
32 |
|
$numModels = count($models); |
|
48
|
|
|
|
|
49
|
32 |
|
if ($numModels === 1) |
|
50
|
|
|
{ |
|
51
|
26 |
|
(new SingleModelDecorator()) |
|
52
|
26 |
|
->setManganel($this->manganel) |
|
53
|
26 |
|
->decorate($body, $criteria); |
|
54
|
|
|
} |
|
55
|
|
|
else |
|
56
|
|
|
{ |
|
57
|
6 |
|
(new MultiModelDecorator($models)) |
|
58
|
6 |
|
->setManganel($this->manganel) |
|
59
|
6 |
|
->decorate($body, $criteria); |
|
60
|
|
|
} |
|
61
|
32 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|