LaravelRUS /
SleepingOwlAdmin
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SleepingOwl\Admin\Http\Controllers; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Contracts\Foundation\Application; |
||||||
| 6 | use Illuminate\Http\JsonResponse; |
||||||
| 7 | use Illuminate\Http\Request; |
||||||
| 8 | use Illuminate\Routing\Controller; |
||||||
| 9 | use SleepingOwl\Admin\Contracts\ModelConfigurationInterface; |
||||||
| 10 | use SleepingOwl\Admin\Display\DisplayDatatablesAsyncAlterPaginate; |
||||||
| 11 | use SleepingOwl\Admin\Display\DisplayTabbed; |
||||||
| 12 | use SleepingOwl\Admin\Form\Columns\Column; |
||||||
| 13 | use SleepingOwl\Admin\Form\FormElements; |
||||||
| 14 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||||||
| 15 | |||||||
| 16 | class AlterPaginateDisplayController extends Controller |
||||||
| 17 | { |
||||||
| 18 | /** |
||||||
| 19 | * @param ModelConfigurationInterface $model |
||||||
| 20 | * @param Request $request |
||||||
| 21 | * @param Application $application |
||||||
| 22 | * @param null $name |
||||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||||
| 23 | * @return JsonResponse |
||||||
| 24 | * @throws NotFoundHttpException |
||||||
| 25 | */ |
||||||
| 26 | public function async(ModelConfigurationInterface $model, Request $request, Application $application, $name = null) |
||||||
| 27 | { |
||||||
| 28 | $payload = $request->payload ?: []; |
||||||
| 29 | |||||||
| 30 | $display = $model->fireDisplay($payload); |
||||||
|
0 ignored issues
–
show
The call to
SleepingOwl\Admin\Contra...nterface::fireDisplay() has too many arguments starting with $payload.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. Loading history...
|
|||||||
| 31 | |||||||
| 32 | if ($display instanceof DisplayTabbed) { |
||||||
| 33 | $tabs = $display->getTabs(); |
||||||
| 34 | |||||||
| 35 | foreach ($tabs as $tab) { |
||||||
| 36 | $content = $tab->getContent(); |
||||||
| 37 | |||||||
| 38 | if ($content instanceof FormElements) { |
||||||
| 39 | foreach ($content->getElements() as $element) { |
||||||
| 40 | |||||||
| 41 | //Return data-table if inside FormElements |
||||||
| 42 | if ($element instanceof DisplayDatatablesAsyncAlterPaginate) { |
||||||
| 43 | if ($element->getName() == $name) { |
||||||
| 44 | return $this->renderFindedTable($element, $application, $request); |
||||||
| 45 | } |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | //Try to find data table in columns |
||||||
| 49 | if ($element instanceof Column) { |
||||||
| 50 | foreach ($element->getElements() as $columnElement) { |
||||||
| 51 | if ($columnElement instanceof DisplayDatatablesAsyncAlterPaginate) { |
||||||
| 52 | if ($columnElement->getName() == $name) { |
||||||
| 53 | return $this->renderFindedTable($columnElement, $application, $request); |
||||||
| 54 | } |
||||||
| 55 | } |
||||||
| 56 | } |
||||||
| 57 | } |
||||||
| 58 | } |
||||||
| 59 | } |
||||||
| 60 | |||||||
| 61 | //Finded trully in content-tab |
||||||
| 62 | if ($content instanceof DisplayDatatablesAsyncAlterPaginate) { |
||||||
| 63 | if ($content->getName() == $name) { |
||||||
| 64 | return $this->renderFindedTable($content, $application, $request); |
||||||
| 65 | } |
||||||
| 66 | } |
||||||
| 67 | } |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | if ($display instanceof DisplayDatatablesAsyncAlterPaginate) { |
||||||
| 71 | return $this->renderFindedTable($display, $application, $request); |
||||||
| 72 | } |
||||||
| 73 | |||||||
| 74 | abort(404); |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | /** |
||||||
| 78 | * @param ModelConfigurationInterface $model |
||||||
| 79 | * @param Request $request |
||||||
| 80 | */ |
||||||
| 81 | public function treeReorder(ModelConfigurationInterface $model, Request $request) |
||||||
| 82 | { |
||||||
| 83 | $display = $model->fireDisplay(); |
||||||
| 84 | |||||||
| 85 | if ($display instanceof DisplayTabbed) { |
||||||
| 86 | $display->getTabs()->each(function (DisplayTab $tab) use ($request) { |
||||||
|
0 ignored issues
–
show
The type
SleepingOwl\Admin\Http\Controllers\DisplayTab was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 87 | $content = $tab->getContent(); |
||||||
| 88 | if ($content instanceof DisplayTree) { |
||||||
|
0 ignored issues
–
show
The type
SleepingOwl\Admin\Http\Controllers\DisplayTree was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 89 | $content->getRepository()->reorder( |
||||||
| 90 | $request->input('data') |
||||||
| 91 | ); |
||||||
| 92 | } |
||||||
| 93 | }); |
||||||
| 94 | } else { |
||||||
| 95 | $display->getRepository()->reorder( |
||||||
|
0 ignored issues
–
show
The method
getRepository() does not exist on SleepingOwl\Admin\Contra...isplay\DisplayInterface. It seems like you code against a sub-type of SleepingOwl\Admin\Contra...isplay\DisplayInterface such as SleepingOwl\Admin\Form\FormDefault or SleepingOwl\Admin\Display\Display.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 96 | $request->input('data') |
||||||
| 97 | ); |
||||||
| 98 | } |
||||||
| 99 | } |
||||||
| 100 | |||||||
| 101 | /** |
||||||
| 102 | * @param DisplayDatatablesAsyncAlterPaginate $datatable |
||||||
| 103 | * @param Application $application |
||||||
| 104 | * @param Request $request |
||||||
| 105 | * @return array|JsonResponse |
||||||
| 106 | */ |
||||||
| 107 | protected function renderFindedTable(DisplayDatatablesAsyncAlterPaginate $datatable, Application $application, Request $request) |
||||||
| 108 | { |
||||||
| 109 | try { |
||||||
| 110 | return $datatable->renderAsync($request); |
||||||
| 111 | } catch (\Exception $exception) { |
||||||
| 112 | \Log::error('unable to render finded table!', [ |
||||||
| 113 | 'exception' => $exception, |
||||||
| 114 | ]); |
||||||
| 115 | |||||||
| 116 | return new JsonResponse([ |
||||||
| 117 | 'message' => $application->isLocal() |
||||||
| 118 | ? $exception->getMessage() |
||||||
| 119 | : trans('sleeping_owl::lang.table.error'), |
||||||
| 120 | ], 403); |
||||||
| 121 | } |
||||||
| 122 | } |
||||||
| 123 | } |
||||||
| 124 |