|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Active form controller |
|
5
|
|
|
* |
|
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
|
7
|
|
|
* @link http://inji.ru/ |
|
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
|
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
class ActiveFormController extends Controller { |
|
12
|
|
|
|
|
13
|
|
|
public function searchAction() { |
|
14
|
|
|
$result = new Server\Result(); |
|
15
|
|
|
$searchString = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING); |
|
16
|
|
|
$searchString = trim(preg_replace('![^A-zА-я0-9@-_\. ]!iSu', ' ', urldecode($searchString))); |
|
17
|
|
|
if (!$searchString) { |
|
18
|
|
|
$result->content = []; |
|
19
|
|
|
$result->send(); |
|
20
|
|
|
} |
|
21
|
|
|
try { |
|
22
|
|
|
$modelName = trim(filter_input(INPUT_GET, 'modelName', FILTER_SANITIZE_STRING)); |
|
23
|
|
|
if (!$modelName) { |
|
24
|
|
|
throw new Exception('Не указана модель'); |
|
25
|
|
|
} |
|
26
|
|
|
$model = new $modelName; |
|
27
|
|
|
if (!$model || !is_subclass_of($model, 'Model')) { |
|
28
|
|
|
throw new Exception('Модель не найдена'); |
|
29
|
|
|
} |
|
30
|
|
|
$formName = trim(filter_input(INPUT_GET, 'formName', FILTER_SANITIZE_STRING)); |
|
31
|
|
|
if (!$formName) { |
|
32
|
|
|
throw new Exception('Не указано название формы'); |
|
33
|
|
|
} |
|
34
|
|
|
if (empty($modelName::$forms[$formName])) { |
|
35
|
|
|
throw new Exception('Не существует указанной формы'); |
|
36
|
|
|
} |
|
37
|
|
|
$activeForm = new Ui\ActiveForm($model, $formName); |
|
38
|
|
|
$inputs = $activeForm->getInputs(); |
|
39
|
|
|
$inputName = trim(filter_input(INPUT_GET, 'inputName', FILTER_SANITIZE_STRING)); |
|
40
|
|
|
if (empty($inputs[$inputName])) { |
|
41
|
|
|
throw new Exception('У формы нет такого поля'); |
|
42
|
|
|
} |
|
43
|
|
|
} catch (Exception $exc) { |
|
44
|
|
|
$result->success = false; |
|
45
|
|
|
$result->content = $exc->getMessage(); |
|
46
|
|
|
return $result->send(); |
|
47
|
|
|
} |
|
48
|
|
|
$options = [ |
|
49
|
|
|
'where' => [ |
|
50
|
|
|
] |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
$searchArr = []; |
|
54
|
|
|
foreach (explode(' ', $searchString) as $part) { |
|
55
|
|
|
$colWhere = []; |
|
56
|
|
|
$first = true; |
|
57
|
|
|
foreach ($inputs[$inputName]['cols'] as $col) { |
|
58
|
|
|
$part = trim($part); |
|
59
|
|
|
if ($part && strlen($part) > 2) { |
|
60
|
|
|
$colWhere[] = [$col, '%' . $part . '%', 'LIKE', $first ? 'AND' : 'OR']; |
|
61
|
|
|
$first = false; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
if ($colWhere) { |
|
65
|
|
|
$searchArr[] = $colWhere; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
if ($searchArr) { |
|
69
|
|
|
$options['where'][] = $searchArr; |
|
70
|
|
|
} else { |
|
71
|
|
|
$result->content = []; |
|
72
|
|
|
$result->send(); |
|
73
|
|
|
} |
|
74
|
|
|
$list = $activeForm->getOptionsList($inputs[$inputName], ['noEmptyValue' => true], $modelName, 'aditional', $options,$model); |
|
|
|
|
|
|
75
|
|
|
$result->content = $list; |
|
76
|
|
|
$result->send(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: