| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2025 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 |
* VikBooking Task Manager view. |
| 16 |
* |
| 17 |
* @since 1.18.0 (J) - 1.8.0 (WP) |
| 18 |
*/ |
| 19 |
class VikBookingViewTaskmanager extends JViewVikBooking |
| 20 |
{ |
| 21 |
/** |
| 22 |
* VikBooking view display method. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function display($tpl = null) |
| 27 |
{ |
| 28 |
if (!JFactory::getUser()->authorise('core.vbo.pms', 'com_vikbooking') && !JFactory::getUser()->authorise('core.vbo.tm', 'com_vikbooking')) { |
| 29 |
VBOHttpDocument::getInstance($app)->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 30 |
} |
| 31 |
|
| 32 |
// Set the toolbar |
| 33 |
$this->addToolBar(); |
| 34 |
|
| 35 |
$app = JFactory::getApplication(); |
| 36 |
|
| 37 |
if (!JFactory::getUser()->authorise('core.vbo.pms', 'com_vikbooking')) { |
| 38 |
VBOHttpDocument::getInstance($app)->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 39 |
} |
| 40 |
|
| 41 |
// list of allowed modes |
| 42 |
$allowedModes = [ |
| 43 |
'board' => [ |
| 44 |
'name' => JText::translate('VBO_BOARD'), |
| 45 |
'icon' => VikBookingIcons::i('table'), |
| 46 |
], |
| 47 |
'list' => [ |
| 48 |
'name' => JText::translate('VBO_LIST'), |
| 49 |
'icon' => VikBookingIcons::i('th-list'), |
| 50 |
], |
| 51 |
'calendar' => [ |
| 52 |
'name' => JText::translate('VBMENUQUICKRES'), |
| 53 |
'icon' => VikBookingIcons::i('calendar'), |
| 54 |
], |
| 55 |
'overv' => [ |
| 56 |
'name' => JText::translate('VBMENUTHREE'), |
| 57 |
'icon' => VikBookingIcons::i('calendar-check'), |
| 58 |
'link' => VBOFactory::getPlatform()->getUri()->admin('index.php?option=com_vikbooking&task=overv', false), |
| 59 |
], |
| 60 |
]; |
| 61 |
|
| 62 |
// user mode preferences |
| 63 |
$user = JFactory::getUser(); |
| 64 |
$uname = $user->name; |
| 65 |
$preferences = (array) VBOFactory::getConfig()->getArray('tm_modes', []); |
| 66 |
|
| 67 |
// check for mode switch |
| 68 |
$mode = $app->getUserStateFromRequest("vbo.tm.mode", 'mode', '', 'string'); |
| 69 |
|
| 70 |
if (!$mode || !isset($allowedModes[$mode])) { |
| 71 |
// check if there's a user mode preference |
| 72 |
if ($user_mode = ($preferences[$uname] ?? null)) { |
| 73 |
$mode = $user_mode; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
$mode = $mode && isset($allowedModes[$mode]) ? $mode : key($allowedModes); |
| 78 |
|
| 79 |
// update preferences |
| 80 |
$preferences[$uname] = $mode; |
| 81 |
VBOFactory::getConfig()->set('tm_modes', $preferences); |
| 82 |
|
| 83 |
// get the current View filters |
| 84 |
$filters = (array) $app->getUserStateFromRequest("vbo.tm.filters", 'filters', [], 'array'); |
| 85 |
|
| 86 |
// access task manager |
| 87 |
$taskManager = VBOFactory::getTaskManager(); |
| 88 |
|
| 89 |
// get the first visible areas |
| 90 |
$visibleAreas = $taskManager->getVisibleAreas(0, 3); |
| 91 |
$activeAreas = array_map('intval', array_column($visibleAreas, 'id')); |
| 92 |
|
| 93 |
// set View properties |
| 94 |
$this->visibleAreas = $visibleAreas; |
| 95 |
$this->activeAreas = $activeAreas; |
| 96 |
$this->allowedModes = $allowedModes; |
| 97 |
$this->mode = $mode; |
| 98 |
$this->filters = $filters; |
| 99 |
|
| 100 |
// Display the template |
| 101 |
parent::display($tpl); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Setting the toolbar. |
| 106 |
* |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
protected function addToolBar() |
| 110 |
{ |
| 111 |
// add menu title and some buttons to the page |
| 112 |
JToolBarHelper::title(JText::translate('VBO_TITLE_TASK_MANAGER'), 'vikbooking'); |
| 113 |
|
| 114 |
if (JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) { |
| 115 |
JToolBarHelper::apply('tm.settings', JText::translate('VBOADMINLEGENDSETTINGS')); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|