PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / emprates / view.html.php
vikappointments / admin / views / emprates Last commit date
tmpl 1 year ago index.html 4 years ago view.html.php 2 years ago
view.html.php
116 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 * VikAppointments employee-services relations management view.
16 *
17 * @since 1.3
18 */
19 class VikAppointmentsViewemprates extends JViewVAP
20 {
21 /**
22 * VikAppointments view display method.
23 *
24 * @return void
25 */
26 function display($tpl = null)
27 {
28 $dbo = JFactory::getDbo();
29 $app = JFactory::getApplication();
30 $input = $app->input;
31
32 $ids = $input->get('cid', array(0), 'uint');
33
34 $q = $dbo->getQuery(true)
35 ->select($dbo->qn('nickname'))
36 ->from($dbo->qn('#__vikappointments_employee'))
37 ->where($dbo->qn('id') . ' = ' . $ids[0]);
38
39 $dbo->setQuery($q, 0, 1);
40 $employeeName = $dbo->loadResult();
41
42 if (!$employeeName)
43 {
44 // employee not found, back to the list
45 $app->redirect('index.php?option=com_vikappointments&view=employees');
46 }
47
48 // set the toolbar
49 $this->addToolBar($employeeName);
50
51 // load services
52 $services = array();
53
54 $q = $dbo->getQuery(true)
55 ->select($dbo->qn(array(
56 's.id', 's.name', 's.price', 's.duration', 's.sleep',
57 )))
58 ->from($dbo->qn('#__vikappointments_service', 's'))
59 ->order($dbo->qn('s.ordering') . ' ASC');
60
61 $dbo->setQuery($q);
62
63 // map services by ID for easy access
64 foreach ($dbo->loadObjectList() as $service)
65 {
66 $services[$service->id] = $service;
67 }
68
69 // load overrides
70 $assigned = array();
71
72 $q = $dbo->getQuery(true)
73 ->select('a.*')
74 ->from($dbo->qn('#__vikappointments_ser_emp_assoc', 'a'))
75 ->where($dbo->qn('a.id_employee') . ' = ' . $ids[0])
76 ->order($dbo->qn('a.id') . ' ASC');
77
78 $dbo->setQuery($q);
79
80 // assign service name to relations
81 foreach ($dbo->loadObjectList() as $assoc)
82 {
83 $assoc->name = $services[$assoc->id_service]->name;
84
85 $assigned[] = $assoc;
86 }
87
88 $this->services = $services;
89 $this->assigned = $assigned;
90 $this->idEmployee = $ids[0];
91
92 // display the template (default.php)
93 parent::display($tpl);
94 }
95
96 /**
97 * Setting the toolbar.
98 *
99 * @return void
100 */
101 protected function addToolBar($nickname)
102 {
103 // add menu title and some buttons to the page
104 JToolBarHelper::title(JText::sprintf('VAPMAINTITLEVIEWEMPRATES', $nickname), 'vikappointments');
105
106 if (JFactory::getUser()->authorise('core.edit', 'com_vikappointments'))
107 {
108 JToolBarHelper::apply('emprates.save', JText::translate('VAPSAVE'));
109 JToolBarHelper::save('emprates.saveclose', JText::translate('VAPSAVEANDCLOSE'));
110 JToolBarHelper::divider();
111 }
112
113 JToolBarHelper::cancel('employee.cancel');
114 }
115 }
116