PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.3
Responsive Menu – Create Mobile-Friendly Menu v3.1.3
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / app / Controllers / AdminController.php

AdminController.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.3, at app/Controllers/AdminController.php

134 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Controllers;
4 use ResponsiveMenu\View\View;
5 use ResponsiveMenu\Management\OptionManager;
6 use ResponsiveMenu\Validation\Validator;
7 use ResponsiveMenu\Tasks\UpdateOptionsTask;
8 use ResponsiveMenu\Collections\OptionsCollection;
9
10 class AdminController {
11
12 public function __construct(OptionManager $manager, View $view) {
13 $this->manager = $manager;
14 $this->view = $view;
15 }
16
17 public function index($nav_menus, $location_menus) {
18 return $this->view->render(
19 'admin/main.html.twig',
20 [
21 'options' => $this->manager->all(),
22 'nav_menus' => $nav_menus,
23 'location_menus' => $location_menus
24 ]
25 );
26 }
27
28 public function rebuild($nav_menus, $location_menus) {
29 return $this->view->render(
30 'admin/main.html.twig',
31 [
32 'options' => $this->manager->all(),
33 'nav_menus' => $nav_menus,
34 'location_menus' => $location_menus,
35 'alert' => ['success' => 'Responsive Menu Database Rebuilt Successfully.']
36 ]
37 );
38 }
39
40 public function update($new_options, $nav_menus, $location_menus) {
41 $validator = new Validator();
42 $errors = [];
43 if($validator->validate($new_options)):
44 try {
45 $options = $this->manager->updateOptions($new_options);
46 $task = new UpdateOptionsTask;
47 $task->run($options, $this->view);
48 $alert = ['success' => 'Responsive Menu Options Updated Successfully.'];
49 } catch (\Exception $e) {
50 $alert = ['danger' => $e->getMessage()];
51 }
52 else:
53 $options = new OptionsCollection($new_options);
54 $errors = $validator->getErrors();
55 $alert = ['danger' => $errors];
56 endif;
57
58 return $this->view->render(
59 'admin/main.html.twig',
60 [
61 'options' => $options,
62 'alert' => $alert,
63 'nav_menus' => $nav_menus,
64 'location_menus' => $location_menus,
65 'errors' => $errors
66 ]
67 );
68 }
69
70 public function reset($default_options, $nav_menus, $location_menus) {
71 try {
72 $options = $this->manager->updateOptions($default_options);
73 $task = new UpdateOptionsTask;
74 $task->run($options, $this->view);
75 $alert = ['success' => 'Responsive Menu Options Reset Successfully'];
76 } catch(\Exception $e) {
77 $alert = ['danger' => $e->getMessage()];
78 }
79 return $this->view->render(
80 'admin/main.html.twig',
81 [
82 'options' => $options,
83 'alert' => $alert,
84 'nav_menus' => $nav_menus,
85 'location_menus' => $location_menus
86 ]
87 );
88 }
89
90 public function import($imported_options, $nav_menus, $location_menus) {
91 if(!empty($imported_options)):
92 $validator = new Validator();
93 $errors = [];
94 if($validator->validate($imported_options)):
95 try {
96 unset($imported_options['button_click_trigger']);
97 $options = $this->manager->updateOptions($imported_options);
98 $task = new UpdateOptionsTask;
99 $task->run($options, $this->view);
100 $alert = ['success' => 'Responsive Menu Options Imported Successfully.'];
101 } catch(\Exception $e) {
102 $options = $this->manager->all();
103 $alert = ['danger' => $e->getMessage()];
104 }
105 else:
106 $options = new OptionsCollection($imported_options);
107 $errors = $validator->getErrors();
108 $alert = ['danger' => $errors];
109 endif;
110 else:
111 $options = $this->manager->all();
112 $alert = ['danger' => 'No import file selected'];
113 endif;
114
115 return $this->view->render(
116 'admin/main.html.twig',
117 [
118 'options' => $options,
119 'alert' => $alert,
120 'nav_menus' => $nav_menus,
121 'location_menus' => $location_menus,
122 'errors' => $errors
123 ]
124 );
125 }
126
127 public function export() {
128 return json_encode(
129 $this->manager->all()->toArray()
130 );
131 }
132
133 }
134