PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.19
VikAppointments Services Booking Calendar v1.2.19
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controller.php
vikappointments / admin Last commit date
assets 1 month ago controllers 1 month ago export 1 month ago helpers 1 month ago layouts 1 month ago models 1 month ago tables 1 month ago views 1 month ago access.xml 1 month ago controller.php 1 month ago
controller.php
288 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * General back-end controller of VikAppointments component.
16 *
17 * @since 1.0
18 */
19 class VikAppointmentsController extends JControllerVAP
20 {
21 /**
22 * Display task.
23 *
24 * @return void
25 */
26 public function display($cachable = false, $urlparams = false)
27 {
28 $input = JFactory::getApplication()->input;
29
30 $view = $input->get('view');
31
32 if (empty($view))
33 {
34 // set default view if not specified
35 $input->set('view', $view = AppointmentsHelper::getDefaultView());
36 }
37
38 /**
39 * Fetch here whether to display the menu or not.
40 *
41 * @since 1.7
42 */
43 $is_menu = $this->shouldDisplayMenu($view);
44
45 if ($is_menu)
46 {
47 AppointmentsHelper::printMenu();
48 }
49
50 // call parent behavior
51 parent::display();
52
53 if ($is_menu)
54 {
55 AppointmentsHelper::printFooter();
56 }
57 }
58
59 /**
60 * FULL SCREEN VIEWS (no menu)
61 */
62
63 function store_dashboard_properties()
64 {
65 $input = JFactory::getApplication()->input;
66
67 $prop = array(
68 'appointments' => $input->getUint('a_page', 1),
69 'waiting' => $input->getUint('w_page', 1),
70 'customers' => $input->getUint('c_page', 1),
71 'packages' => $input->getUint('p_page', 1),
72 );
73
74 JFactory::getSession()->set('dashboard-properties', $prop, 'vap');
75 exit;
76 }
77
78 /**
79 * CANCEL TASKS
80 */
81
82 function dashboard()
83 {
84 JFactory::getApplication()->redirect('index.php?option=com_vikappointments');
85 }
86
87 /**
88 * Task used to allow the plugins to self-render their contents
89 * within a stand-alone page of VikAppointments.
90 *
91 * Any arguments to be passed to the plugins can be specified
92 * within the `args` property in query string, such as:
93 * &args[action]=xxx&args[id]=123
94 *
95 * @return void
96 *
97 * @since 1.7.3
98 */
99 public function plugin_action()
100 {
101 $input = JFactory::getApplication()->input;
102 $dispatcher = VAPFactory::getEventDispatcher();
103
104 // a configuration array to be passed to the plugins
105 $state = new VAPActionState($input->get('args', [], 'array'));
106
107 // extract action from request and also from args array
108 $action = $input->get('action', $state->get('action'));
109
110 if (!$action)
111 {
112 // action was not specified in request
113 throw new InvalidArgumentException('Missing action.', 400);
114 }
115
116 // create actions container
117 $container = new VAPActionContainerMap();
118
119 /**
120 * Trigger event to let the plugins be able to render their contents on a
121 * stand-alone page or to execute some tasks as a controller.
122 *
123 * @param VAPActionContainer $container A container used to attach the task.
124 *
125 * @return void
126 *
127 * @since 1.7.3
128 */
129 $dispatcher->trigger('onDispatchVikAppointmentsPluginAction', array($container));
130
131 // notify elements subscribed to the requested event/action
132 $result = new VAPActionResultHtml($container->notify($action, $state));
133
134 if ($result->has())
135 {
136 // display HTML
137 echo $result->display();
138 }
139 }
140
141 /**
142 * Task used to allow the plugins to self-render their contents
143 * within a stand-alone page of VikAppointments.
144 *
145 * Any arguments to be passed to the plugins can be specified
146 * within the `args` property in query string, such as:
147 * &args[action]=xxx&args[id]=123
148 *
149 * @return void
150 *
151 * @since 1.6.6
152 * @deprecated 1.8 Use plugin_action() instead.
153 */
154 public function plugin_view()
155 {
156 $input = JFactory::getApplication()->input;
157 $dispatcher = VAPFactory::getEventDispatcher();
158
159 // a configuration array to be passed to the plugins
160 $args = $input->get('args', array(), 'array');
161
162 // wrap arguments in a registry for a better ease of use
163 $args = new JRegistry($args);
164
165 /**
166 * Trigger event to let the plugins be able to
167 * render their contents on a stand-alone page.
168 *
169 * @param Registry $args A registry of arguments set in request.
170 *
171 * @return string The HTML to display.
172 *
173 * @since 1.6.6
174 */
175 $html = $dispatcher->trigger('onDisplayVikAppointmentsPluginView', array($args));
176
177 // strip empty values from resulting array
178 $html = array_filter($html);
179
180 // join HTML responses and echo string
181 echo implode("\n", $html);
182 }
183
184 /////////////////////
185 ////// HELPERS //////
186 /////////////////////
187
188 /**
189 * Checks whether the specified view should display the menu.
190 *
191 * @param string $view The view to check.
192 * @param array $list An additional list of supported views.
193 *
194 * @return boolean
195 *
196 * @since 1.7
197 */
198 protected function shouldDisplayMenu($view, array $list = array())
199 {
200 $tmpl = JFactory::getApplication()->input->get('tmpl');
201
202 // do not display in case of tmpl=component
203 if (!strcmp((string) $tmpl, 'component'))
204 {
205 return false;
206 }
207
208 // defines list of views that supports menu and footer
209 $views = array(
210 // Dashboard
211 'vikappointments',
212 // Groups
213 'groups',
214 // Employees
215 'employees',
216 'emppayments',
217 'emplocations',
218 // Services
219 'services',
220 'serworkdays',
221 'restrictions',
222 'rates',
223 // Options
224 'options',
225 'optiongroups',
226 // Locations
227 'locations',
228 // Packages
229 'packorders',
230 'packgroups',
231 'packages',
232 // Reservations
233 'reservations',
234 // Waiting List
235 'waitinglist',
236 // Customer
237 'customers',
238 'usernotes',
239 // Coupons
240 'coupons',
241 'coupongroups',
242 // Calendar
243 'calendar',
244 'caldays',
245 // Countries
246 'countries',
247 'states',
248 'cities',
249 // Reviews
250 'reviews',
251 // Subscriptions
252 'subscriptions',
253 'subscrorders',
254 // Analytics
255 'analytics',
256 // Custom Fields
257 'customf',
258 // Payments
259 'payments',
260 // Status Codes
261 'statuscodes',
262 // Taxes
263 'taxes',
264 // Invoices
265 'invoices',
266 // Media
267 'media',
268 // Configuration
269 'editconfig',
270 'editconfigemp',
271 'editconfigcldays',
272 'editconfigsmsapi',
273 'editconfigcron',
274 'editconfigapp',
275 // Misc
276 'import',
277 'export',
278 'tags',
279 );
280
281 // merge lookup with overrides
282 $views = array_merge($views, $list);
283
284 // check whether the view is in the list
285 return in_array($view, $views);
286 }
287 }
288