controller.php
4 days ago
fieldcontrol.php
4 days ago
index.html
4 days ago
manager.php
4 days ago
toolbar.php
4 days ago
toolbar.php
376 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 | * Class used to manage the employees area toolbar. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | class VAPEmployeeAreaToolbar |
| 20 | { |
| 21 | /** |
| 22 | * The singleton instance. |
| 23 | * |
| 24 | * @var self |
| 25 | */ |
| 26 | protected static $instance = null; |
| 27 | |
| 28 | /** |
| 29 | * The employee authentication handler. |
| 30 | * |
| 31 | * @var VAPEmployeeAuth |
| 32 | */ |
| 33 | protected $auth; |
| 34 | |
| 35 | /** |
| 36 | * An associative array holding the main menu. |
| 37 | * |
| 38 | * @var array |
| 39 | */ |
| 40 | protected $mainMenu = array(); |
| 41 | |
| 42 | /** |
| 43 | * An associative array holding the secondary menu. |
| 44 | * |
| 45 | * @var array |
| 46 | */ |
| 47 | protected $sideMenu = array(); |
| 48 | |
| 49 | /** |
| 50 | * Returns the employees area toolbar instance. |
| 51 | * |
| 52 | * @return self |
| 53 | */ |
| 54 | public static function getInstance() |
| 55 | { |
| 56 | if (static::$instance === null) |
| 57 | { |
| 58 | static::$instance = new static(); |
| 59 | } |
| 60 | |
| 61 | return static::$instance; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Class constructor. |
| 66 | * The visibility is protected to prevent the instantiation |
| 67 | * of this class from the outside. |
| 68 | */ |
| 69 | protected function __construct() |
| 70 | { |
| 71 | $this->auth = VAPEmployeeAuth::getInstance(); |
| 72 | |
| 73 | // set up employees area menus |
| 74 | $this->setupMainMenu(); |
| 75 | $this->setupSidebarMenu(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Cannot clone this object. |
| 80 | */ |
| 81 | private function __clone() |
| 82 | { |
| 83 | |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Helper method used to set up the main menu. |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | protected function setupMainMenu() |
| 92 | { |
| 93 | /** |
| 94 | * Do not display the "profile" menu item in case |
| 95 | * the profile management is turned off from the |
| 96 | * employees configuration. |
| 97 | * |
| 98 | * @since 1.7.2 |
| 99 | */ |
| 100 | if ($this->auth->manage()) |
| 101 | { |
| 102 | // add profile item to main menu |
| 103 | $this->mainMenu['profile'] = [ |
| 104 | 'active' => true, |
| 105 | 'title' => JText::translate('VAPEMPPROFILETITLE'), |
| 106 | 'icon' => 'fas fa-user', |
| 107 | 'query' => [ |
| 108 | 'task' => 'empeditprofile.edit', |
| 109 | ], |
| 110 | 'selQuery' => [ |
| 111 | 'view' => 'empeditprofile', |
| 112 | ] |
| 113 | ]; |
| 114 | } |
| 115 | |
| 116 | // add working days item to main menu |
| 117 | $this->mainMenu['workdays'] = [ |
| 118 | 'active' => true, |
| 119 | 'title' => JText::translate('VAPEMPWORKDAYSTITLE'), |
| 120 | 'icon' => 'fas fa-calendar', |
| 121 | 'query' => [ |
| 122 | 'view' => 'empwdays', |
| 123 | ], |
| 124 | ]; |
| 125 | |
| 126 | // add services item to main menu |
| 127 | $this->mainMenu['services'] = [ |
| 128 | 'active' => true, |
| 129 | 'title' => JText::translate('VAPEMPSERVICESTITLE'), |
| 130 | 'icon' => 'fas fa-list', |
| 131 | 'query' => [ |
| 132 | 'view' => 'empserviceslist', |
| 133 | ], |
| 134 | ]; |
| 135 | |
| 136 | if ($this->auth->managePayments()) |
| 137 | { |
| 138 | // add payments item to main menu |
| 139 | $this->mainMenu['payments'] = [ |
| 140 | 'active' => true, |
| 141 | 'title' => JText::translate('VAPEMPPAYMENTSTITLE'), |
| 142 | 'icon' => 'fas fa-credit-card', |
| 143 | 'query' => [ |
| 144 | 'view' => 'emppaylist', |
| 145 | ], |
| 146 | ]; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Trigger hook to allow the plugins to alter the items of the main menu |
| 151 | * displayed within the Employees Area. |
| 152 | * |
| 153 | * @param array &$menu The main menu. |
| 154 | * |
| 155 | * @return void |
| 156 | * |
| 157 | * @since 1.7 |
| 158 | */ |
| 159 | VAPFactory::getEventDispatcher()->trigger('onSetupEmployeesAreaMainMenu', array(&$this->mainMenu)); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Helper method used to set up the sidebar menu. |
| 164 | * |
| 165 | * @return void |
| 166 | */ |
| 167 | protected function setupSidebarMenu() |
| 168 | { |
| 169 | // add account status item to sidebar menu |
| 170 | $this->sideMenu['status'] = [ |
| 171 | 'separator' => true, |
| 172 | 'title' => JText::translate('VAPEMPACCOUNTSTATUSTITLE'), |
| 173 | 'icon' => null, |
| 174 | 'query' => [ |
| 175 | 'view' => 'empaccountstat', |
| 176 | ], |
| 177 | ]; |
| 178 | |
| 179 | /** |
| 180 | * Do not display the "coupons" menu item in case |
| 181 | * the coupons management is turned off from the |
| 182 | * employees configuration. |
| 183 | * |
| 184 | * @since 1.6.5 |
| 185 | */ |
| 186 | if ($this->auth->manageCoupons()) |
| 187 | { |
| 188 | // add coupons item to sidebar menu |
| 189 | $this->sideMenu['coupons'] = [ |
| 190 | 'separator' => false, |
| 191 | 'title' => JText::translate('VAPEMPCOUPONSTITLE'), |
| 192 | 'icon' => null, |
| 193 | 'query' => [ |
| 194 | 'view' => 'empcoupons', |
| 195 | ], |
| 196 | ]; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Do not display the "locations" menu item in case |
| 201 | * the locations management is turned off from the |
| 202 | * employees configuration. |
| 203 | * |
| 204 | * @since 1.7.2 |
| 205 | */ |
| 206 | if ($this->auth->manageLocations()) |
| 207 | { |
| 208 | // add locations item to sidebar menu |
| 209 | $this->sideMenu['locations'] = [ |
| 210 | 'separator' => $this->auth->manageWorkDays() ? false : true, |
| 211 | 'title' => JText::translate('VAPEMPLOCATIONSTITLE'), |
| 212 | 'icon' => null, |
| 213 | 'query' => [ |
| 214 | 'view' => 'emplocations', |
| 215 | ], |
| 216 | ]; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Do not display the "assignments" menu item in case |
| 221 | * the working days management is turned off from the |
| 222 | * employees configuration. |
| 223 | * |
| 224 | * @since 1.7.2 |
| 225 | */ |
| 226 | if ($this->auth->manageWorkDays()) |
| 227 | { |
| 228 | // add locations-working days item to sidebar menu |
| 229 | $this->sideMenu['locwdays'] = [ |
| 230 | 'separator' => true, |
| 231 | 'title' => JText::translate('VAPEMPLOCWDTITLE'), |
| 232 | 'icon' => null, |
| 233 | 'query' => [ |
| 234 | 'view' => 'emplocwdays', |
| 235 | ], |
| 236 | ]; |
| 237 | } |
| 238 | |
| 239 | if (VikAppointments::isSubscriptions()) |
| 240 | { |
| 241 | // add subscriptions orders item to sidebar menu |
| 242 | $this->sideMenu['subscrorders'] = [ |
| 243 | 'separator' => false, |
| 244 | 'title' => JText::translate('VAPEMPSUBSCRPURCHTITLE'), |
| 245 | 'icon' => null, |
| 246 | 'query' => [ |
| 247 | 'view' => 'empsubscrorder', |
| 248 | ], |
| 249 | ]; |
| 250 | |
| 251 | // add subscriptions item to sidebar menu |
| 252 | $this->sideMenu['subscriptions'] = [ |
| 253 | 'separator' => true, |
| 254 | 'title' => JText::translate('VAPEMPSUBSCRTITLE'), |
| 255 | 'icon' => null, |
| 256 | 'query' => [ |
| 257 | 'view' => 'empsubscr', |
| 258 | ], |
| 259 | ]; |
| 260 | } |
| 261 | |
| 262 | if ($this->auth->manageCustomFields()) |
| 263 | { |
| 264 | // add custom fields item to sidebar menu |
| 265 | $this->sideMenu['fields'] = [ |
| 266 | 'separator' => false, |
| 267 | 'title' => JText::translate('VAPEMPCUSTOMFTITLE'), |
| 268 | 'icon' => null, |
| 269 | 'query' => [ |
| 270 | 'view' => 'empcustfields', |
| 271 | ], |
| 272 | ]; |
| 273 | } |
| 274 | |
| 275 | // add settings item to sidebar menu |
| 276 | $this->sideMenu['settings'] = [ |
| 277 | 'separator' => true, |
| 278 | 'title' => JText::translate('VAPEMPSETTINGSTITLE'), |
| 279 | 'icon' => null, |
| 280 | 'query' => [ |
| 281 | 'view' => 'empsettings', |
| 282 | ], |
| 283 | ]; |
| 284 | |
| 285 | // add log out item to sidebar menu |
| 286 | $this->sideMenu['logout'] = [ |
| 287 | 'separator' => false, |
| 288 | 'title' => JText::translate('VAPLOGOUTTITLE'), |
| 289 | 'icon' => null, |
| 290 | 'query' => [ |
| 291 | 'task' => 'emplogin.logout', |
| 292 | ], |
| 293 | ]; |
| 294 | |
| 295 | /** |
| 296 | * Trigger hook to allow the plugins to alter the items of the sidebar menu |
| 297 | * displayed within the Employees Area. |
| 298 | * |
| 299 | * @param array &$menu The sidebar menu. |
| 300 | * |
| 301 | * @return void |
| 302 | * |
| 303 | * @since 1.7 |
| 304 | */ |
| 305 | VAPFactory::getEventDispatcher()->trigger('onSetupEmployeesAreaSidebarMenu', array(&$this->sideMenu)); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Renders the employees area menus. |
| 310 | * |
| 311 | * @param array $options An associative array of options. |
| 312 | * |
| 313 | * @return string |
| 314 | */ |
| 315 | public function render(array $options = array()) |
| 316 | { |
| 317 | $input = JFactory::getApplication()->input; |
| 318 | |
| 319 | foreach ($this->mainMenu as $key => &$mainItem) |
| 320 | { |
| 321 | if (empty($options['selected'])) |
| 322 | { |
| 323 | // extract query to fetch |
| 324 | $query = isset($mainItem['selQuery']) ? $mainItem['selQuery'] : @$mainItem['query']; |
| 325 | |
| 326 | // make sure all the query arguments are set in request |
| 327 | $mainItem['selected'] = !array_diff_assoc((array) $query, $input->getArray()); |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | // check whether the key of this item matches the specified one |
| 332 | $mainItem['selected'] = $key === $options['selected']; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | foreach ($this->sideMenu as &$sideItem) |
| 337 | { |
| 338 | if (empty($options['selected'])) |
| 339 | { |
| 340 | // extract query to fetch |
| 341 | $query = isset($sideItem['selQuery']) ? $sideItem['selQuery'] : @$sideItem['query']; |
| 342 | |
| 343 | // make sure all the query arguments are set in request |
| 344 | $sideItem['selected'] = !array_diff_assoc((array) $query, $input->getArray()); |
| 345 | } |
| 346 | else |
| 347 | { |
| 348 | // check whether the key of this item matches the specified one |
| 349 | $mainItem['selected'] = $key === $options['selected']; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // prepare display data options |
| 354 | $options['auth'] = $this->auth; |
| 355 | $options['mainmenu'] = $this->mainMenu; |
| 356 | $options['sidemenu'] = $this->sideMenu; |
| 357 | |
| 358 | /** |
| 359 | * The employees area toolbar is displayed from the layout below: |
| 360 | * /components/com_vikappointments/layouts/emparea/toolbar.php |
| 361 | * |
| 362 | * If you need to change something from this layout, just create |
| 363 | * an override of this layout by following the instructions below: |
| 364 | * - open the back-end of your Joomla |
| 365 | * - visit the Extensions > Templates > Templates page |
| 366 | * - edit the active template |
| 367 | * - access the "Create Overrides" tab |
| 368 | * - select Layouts > com_vikappointments > emparea |
| 369 | * - start editing the toolbar.php file on your template to create your own layout |
| 370 | * |
| 371 | * @since 1.6 |
| 372 | */ |
| 373 | return JLayoutHelper::render('emparea.toolbar', $options); |
| 374 | } |
| 375 | } |
| 376 |