| @@ 75-119 (lines=45) @@ | ||
| 72 | * |
|
| 73 | * @return JsonResponse |
|
| 74 | */ |
|
| 75 | public function multiselectSearch(Request $request, ModelConfigurationInterface $model, $field, $id = null) |
|
| 76 | { |
|
| 77 | if (! is_null($id)) { |
|
| 78 | $item = $model->getRepository()->find($id); |
|
| 79 | if (is_null($item) || ! $model->isEditable($item)) { |
|
| 80 | return new JsonResponse([ |
|
| 81 | 'message' => trans('lang.message.access_denied'), |
|
| 82 | ], 403); |
|
| 83 | } |
|
| 84 | ||
| 85 | $form = $model->fireEdit($id); |
|
| 86 | } else { |
|
| 87 | if (! $model->isCreatable()) { |
|
| 88 | return new JsonResponse([ |
|
| 89 | 'message' => trans('lang.message.access_denied'), |
|
| 90 | ], 403); |
|
| 91 | } |
|
| 92 | ||
| 93 | $form = $model->fireCreate(); |
|
| 94 | } |
|
| 95 | ||
| 96 | /** @var DependentSelect $element */ |
|
| 97 | if (is_null($element = $form->getElement($field))) { |
|
| 98 | return new JsonResponse([ |
|
| 99 | 'message' => 'Element not found', |
|
| 100 | ], 404); |
|
| 101 | } |
|
| 102 | ||
| 103 | $field = $request->field; |
|
| 104 | $model = new $request->model; |
|
| 105 | ||
| 106 | if ($request->q && is_object($model)) { |
|
| 107 | return new JsonResponse( |
|
| 108 | $model::where($request->field, 'like', "%{$request->q}%") |
|
| 109 | ->get() |
|
| 110 | ->map(function ($item) use ($field) { |
|
| 111 | return [ |
|
| 112 | 'tag_name' => $item->{$field}, |
|
| 113 | 'id' => $item->id, |
|
| 114 | 'custom_name' => $item->custom_name, |
|
| 115 | ]; |
|
| 116 | }) |
|
| 117 | ); |
|
| 118 | } |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * @param Request $request |
|
| @@ 129-173 (lines=45) @@ | ||
| 126 | * |
|
| 127 | * @return JsonResponse |
|
| 128 | */ |
|
| 129 | public function selectSearch(Request $request, ModelConfigurationInterface $model, $field, $id = null) |
|
| 130 | { |
|
| 131 | if (! is_null($id)) { |
|
| 132 | $item = $model->getRepository()->find($id); |
|
| 133 | if (is_null($item) || ! $model->isEditable($item)) { |
|
| 134 | return new JsonResponse([ |
|
| 135 | 'message' => trans('lang.message.access_denied'), |
|
| 136 | ], 403); |
|
| 137 | } |
|
| 138 | ||
| 139 | $form = $model->fireEdit($id); |
|
| 140 | } else { |
|
| 141 | if (! $model->isCreatable()) { |
|
| 142 | return new JsonResponse([ |
|
| 143 | 'message' => trans('lang.message.access_denied'), |
|
| 144 | ], 403); |
|
| 145 | } |
|
| 146 | ||
| 147 | $form = $model->fireCreate(); |
|
| 148 | } |
|
| 149 | ||
| 150 | /** @var DependentSelect $element */ |
|
| 151 | if (is_null($element = $form->getElement($field))) { |
|
| 152 | return new JsonResponse([ |
|
| 153 | 'message' => 'Element not found', |
|
| 154 | ], 404); |
|
| 155 | } |
|
| 156 | ||
| 157 | $field = $request->field; |
|
| 158 | $model = new $request->model; |
|
| 159 | ||
| 160 | if ($request->q && is_object($model)) { |
|
| 161 | return new JsonResponse( |
|
| 162 | $model::where($request->field, 'like', "%{$request->q}%") |
|
| 163 | ->get() |
|
| 164 | ->map(function ($item) use ($field) { |
|
| 165 | return [ |
|
| 166 | 'tag_name' => $item->{$field}, |
|
| 167 | 'id' => $item->id, |
|
| 168 | 'custom_name' => $item->custom_name, |
|
| 169 | ]; |
|
| 170 | }) |
|
| 171 | ); |
|
| 172 | } |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||