Completed
Push — master ( f26102...541e16 )
by Peter
08:58
created

SearchCriteria::setModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel;
14
15
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
16
use Maslosoft\Mangan\Criteria;
17
use Maslosoft\Mangan\Interfaces\Decorators\ConditionDecoratorTypeAwareInterface;
18
use Maslosoft\Mangan\Interfaces\Decorators\ConditionDecoratorTypeInterface;
19
use Maslosoft\Mangan\Transformers\CriteriaArray;
20
use Maslosoft\Manganel\Traits\UniqueModelsAwareTrait;
21
22
/**
23
 * SearchCriteria
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class SearchCriteria extends Criteria implements ConditionDecoratorTypeAwareInterface
28
{
29
30
	use UniqueModelsAwareTrait;
31
32
	private $query = '';
33
34 64
	public function __construct($criteria = null, AnnotatedInterface $model = null)
35
	{
36 64
		parent::__construct($criteria, $model);
37 64
		if (!empty($model))
38
		{
39 37
			$this->add($model);
40
		}
41 64
	}
42
43 64
	public function getDecoratorType()
44
	{
45 64
		return SearchCriteriaArray::class;
46
	}
47
48 41
	public function setModel(AnnotatedInterface $model)
49
	{
50 41
		$this->add($model);
51 41
		parent::setModel($model);
52 41
	}
53
54 41
	public function add($model)
55
	{
56 41
		$this->addModel($model);
57 41
		return $this;
58
	}
59
60 39
	public function search($query)
61
	{
62 39
		$this->query = $query;
63 39
	}
64
65 64
	public function getSearch()
66
	{
67 64
		return $this->query;
68
	}
69
70
}
71