|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Modules\Core\Traits\Criteria; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Trait ParserSearchableTrait |
|
8
|
|
|
* |
|
9
|
|
|
* @property \Illuminate\Http\Request $request |
|
10
|
|
|
* @property \Prettus\Repository\Contracts\RepositoryInterface $repository |
|
11
|
|
|
* @property $search |
|
12
|
|
|
* @property $searchData |
|
13
|
|
|
* @property $searchFields |
|
14
|
|
|
* @property $isFirstField = true |
|
15
|
|
|
* @property $modelForceAndWhere |
|
16
|
|
|
* @property $fieldsSearchable |
|
17
|
|
|
* @property $fields |
|
18
|
|
|
* @property $filter |
|
19
|
|
|
* @property $orderBy |
|
20
|
|
|
* @property $sortedBy |
|
21
|
|
|
* @property $with |
|
22
|
|
|
* @property $searchJoin |
|
23
|
|
|
* @property $acceptedConditions |
|
24
|
|
|
* @property $originalFields |
|
25
|
|
|
* @package Modules\Core\Traits\Criteria |
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
trait ParserSearchableTrait |
|
28
|
|
|
{ |
|
29
|
|
|
use ParserFieldsSearchTrait; |
|
30
|
|
|
use ParserSearchWhereTrait; |
|
31
|
|
|
use ParserSearchDataTrait; |
|
32
|
|
|
use ParserSearchTrait; |
|
33
|
|
|
use ParserForceAndWhereTrait; |
|
34
|
|
|
use ParserValueTrait; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws \Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function parserSearchable() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->fieldsSearchable = $this->repository->getFieldsSearchable(); |
|
|
|
|
|
|
42
|
|
|
$this->search = $this->request->get(config('repository.criteria.params.search', 'search'), null); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if ($this->search && is_array($this->fieldsSearchable) && count($this->fieldsSearchable)) { |
|
45
|
|
|
|
|
46
|
|
|
$this->parserFieldsSearch(); |
|
47
|
|
|
$this->parserSearchData(); |
|
48
|
|
|
$this->parserSearch(); |
|
49
|
|
|
$this->parserForceAndWhere(); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($this->fields as $field => $condition) { |
|
52
|
|
|
|
|
53
|
|
|
$this->getConditionField($field, $condition); |
|
54
|
|
|
$value = $this->parserValue($condition, $field); |
|
55
|
|
|
$relation = null; |
|
56
|
|
|
$this->getRelationField($field, $relation); |
|
57
|
|
|
$this->parserSearchWhere($value, $relation, $field, $condition); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function getConditionField(&$field, &$condition) |
|
63
|
|
|
{ |
|
64
|
|
|
if (is_numeric($field)) { |
|
65
|
|
|
$field = $condition; |
|
66
|
|
|
$condition = "="; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function getRelationField(&$field, &$relation) |
|
71
|
|
|
{ |
|
72
|
|
|
if (stripos($field, '.')) { |
|
73
|
|
|
$explode = explode('.', $field); |
|
74
|
|
|
$field = array_pop($explode); |
|
75
|
|
|
$relation = implode('.', $explode); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |