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\DisplayDatatablesAsync; |
||||||
11 | use SleepingOwl\Admin\Display\DisplayTab; |
||||||
12 | use SleepingOwl\Admin\Display\DisplayTabbed; |
||||||
13 | use SleepingOwl\Admin\Display\DisplayTree; |
||||||
14 | use SleepingOwl\Admin\Form\Columns\Column; |
||||||
15 | use SleepingOwl\Admin\Form\FormElements; |
||||||
16 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||||||
17 | |||||||
18 | class DisplayController extends Controller |
||||||
19 | { |
||||||
20 | /** |
||||||
21 | * @param ModelConfigurationInterface $model |
||||||
22 | * @param Request $request |
||||||
23 | * @param Application $application |
||||||
24 | * @param null $name |
||||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||||
25 | * @return JsonResponse |
||||||
26 | * @throws NotFoundHttpException |
||||||
27 | */ |
||||||
28 | public function async(ModelConfigurationInterface $model, Request $request, Application $application, $name = null) |
||||||
29 | { |
||||||
30 | $payload = $request->payload ?: []; |
||||||
31 | |||||||
32 | $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. ![]() |
|||||||
33 | |||||||
34 | if ($display instanceof DisplayTabbed) { |
||||||
35 | $tabs = $display->getTabs(); |
||||||
36 | |||||||
37 | foreach ($tabs as $tab) { |
||||||
38 | $content = $tab->getContent(); |
||||||
39 | |||||||
40 | if ($content instanceof FormElements) { |
||||||
41 | foreach ($content->getElements() as $element) { |
||||||
42 | |||||||
43 | //Return data-table if inside FormElements |
||||||
44 | if ($element instanceof DisplayDatatablesAsync) { |
||||||
45 | if ($element->getName() == $name) { |
||||||
46 | return $this->renderFindedTable($element, $application, $request); |
||||||
47 | } |
||||||
48 | } |
||||||
49 | |||||||
50 | //Try to find data table in columns |
||||||
51 | if ($element instanceof Column) { |
||||||
52 | foreach ($element->getElements() as $columnElement) { |
||||||
53 | if ($columnElement instanceof DisplayDatatablesAsync) { |
||||||
54 | if ($columnElement->getName() == $name) { |
||||||
55 | return $this->renderFindedTable($columnElement, $application, $request); |
||||||
56 | } |
||||||
57 | } |
||||||
58 | } |
||||||
59 | } |
||||||
60 | } |
||||||
61 | } |
||||||
62 | |||||||
63 | //Finded trully in content-tab |
||||||
64 | if ($content instanceof DisplayDatatablesAsync) { |
||||||
65 | if ($content->getName() == $name) { |
||||||
66 | return $this->renderFindedTable($content, $application, $request); |
||||||
67 | } |
||||||
68 | } |
||||||
69 | } |
||||||
70 | } |
||||||
71 | |||||||
72 | if ($display instanceof DisplayDatatablesAsync) { |
||||||
73 | return $this->renderFindedTable($display, $application, $request); |
||||||
74 | } |
||||||
75 | |||||||
76 | abort(404); |
||||||
77 | } |
||||||
78 | |||||||
79 | /** |
||||||
80 | * @param ModelConfigurationInterface $model |
||||||
81 | * @param Request $request |
||||||
82 | */ |
||||||
83 | public function treeReorder(ModelConfigurationInterface $model, Request $request) |
||||||
84 | { |
||||||
85 | $display = $model->fireDisplay(); |
||||||
86 | |||||||
87 | if ($display instanceof DisplayTabbed) { |
||||||
88 | $display->getTabs()->each(function (DisplayTab $tab) use ($request) { |
||||||
89 | $content = $tab->getContent(); |
||||||
90 | if ($content instanceof DisplayTree) { |
||||||
91 | $content->getRepository()->reorder( |
||||||
92 | $request->input('data') |
||||||
93 | ); |
||||||
94 | } |
||||||
95 | }); |
||||||
96 | } else { |
||||||
97 | $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
![]() |
|||||||
98 | $request->input('data') |
||||||
99 | ); |
||||||
100 | } |
||||||
101 | } |
||||||
102 | |||||||
103 | /** |
||||||
104 | * @param DisplayDatatablesAsync $datatable |
||||||
105 | * @param Application $application |
||||||
106 | * @param Request $request |
||||||
107 | * @return array|JsonResponse |
||||||
108 | */ |
||||||
109 | protected function renderFindedTable(DisplayDatatablesAsync $datatable, Application $application, Request $request) |
||||||
110 | { |
||||||
111 | try { |
||||||
112 | return $datatable->renderAsync($request); |
||||||
113 | } catch (\Exception $exception) { |
||||||
114 | \Log::error('unable to render finded table!', [ |
||||||
115 | 'exception' => $exception, |
||||||
116 | ]); |
||||||
117 | |||||||
118 | return new JsonResponse([ |
||||||
119 | 'message' => $application->isLocal() |
||||||
120 | ? $exception->getMessage() |
||||||
121 | : trans('sleeping_owl::lang.table.error'), |
||||||
122 | ], 403); |
||||||
123 | } |
||||||
124 | } |
||||||
125 | } |
||||||
126 |