|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Modules\Core\Traits\Criteria; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
trait ParserFieldsSearchTrait |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @throws \Exception |
|
13
|
|
|
*/ |
|
14
|
|
|
protected function parserFieldsSearch() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->parserSearchFields(); |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
$fields = $this->fieldsSearchable; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
if (!is_null($this->searchFields) && is_array($this->searchFields)) { |
|
21
|
|
|
|
|
22
|
|
|
$this->parserOriginalFields(); |
|
23
|
|
|
|
|
24
|
|
|
$fields = []; |
|
25
|
|
|
|
|
26
|
|
|
foreach ($this->originalFields as $field => $condition) { |
|
27
|
|
|
if (is_numeric($field)) { |
|
28
|
|
|
$field = $condition; |
|
29
|
|
|
$condition = "="; |
|
30
|
|
|
} |
|
31
|
|
|
if (in_array($field, (array) $this->searchFields)) { |
|
32
|
|
|
$fields[$field] = $condition; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$this->assertFieldsNotAccepted($fields); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$this->fields = $fields; |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function parserOriginalFields() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->acceptedConditions = config('repository.criteria.acceptedConditions', ['=', 'like']); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$this->originalFields = $this->fieldsSearchable; |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
foreach ($this->searchFields as $index => $field) { |
|
49
|
|
|
$field_parts = explode(':', $field); |
|
50
|
|
|
$temporaryIndex = array_search($field_parts[0], $this->originalFields); |
|
51
|
|
|
|
|
52
|
|
|
if (count($field_parts) == 2) { |
|
53
|
|
|
if (in_array($field_parts[1], $this->acceptedConditions)) { |
|
54
|
|
|
unset($this->originalFields[$temporaryIndex]); |
|
55
|
|
|
$field = $field_parts[0]; |
|
56
|
|
|
$condition = $field_parts[1]; |
|
57
|
|
|
$this->originalFields[$field] = $condition; |
|
58
|
|
|
$this->searchFields[$index] = $field; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array $fields |
|
66
|
|
|
* @throws \Exception |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function assertFieldsNotAccepted($fields) |
|
69
|
|
|
{ |
|
70
|
|
|
if (count($fields) == 0) { |
|
71
|
|
|
throw new Exception((string) trans('repository::criteria.fields_not_accepted', ['field' => implode(',', (array) $this->searchFields)])); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.