PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / manageservice / view.html.php
vikappointments / admin / views / manageservice Last commit date
tmpl 2 days ago index.html 2 days ago view.html.php 2 days ago
view.html.php
192 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 service management view.
16 *
17 * @since 1.0
18 */
19 class VikAppointmentsViewmanageservice 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->getUint('cid', array());
33 $type = $ids ? 'edit' : 'new';
34
35 // set the toolbar
36 $this->addToolBar($type);
37
38 $service = null;
39
40 if ($type == 'edit')
41 {
42 $q = $dbo->getQuery(true)
43 ->select('*')
44 ->from($dbo->qn('#__vikappointments_service'))
45 ->where($dbo->qn('id') . ' = ' . $ids[0]);
46
47 $dbo->setQuery($q, 0, 1);
48 $service = $dbo->loadObject();
49
50 if ($service)
51 {
52 // decode attachments, if any
53 $service->attachments = $service->attachments ? (array) json_decode($service->attachments, true) : array();
54
55 // decode metadata
56 $service->metadata = $service->metadata ? (object) json_decode($service->metadata, true) : new stdClass;
57
58 // get assigned options
59 $q = $dbo->getQuery(true)
60 ->select($dbo->qn(array('o.id', 'o.name', 'o.published')))
61 ->select($dbo->qn('a.id', 'id_assoc'))
62 ->from($dbo->qn('#__vikappointments_option', 'o'))
63 ->leftjoin($dbo->qn('#__vikappointments_ser_opt_assoc', 'a') . ' ON ' . $dbo->qn('o.id') . ' = ' . $dbo->qn('a.id_option'))
64 ->where($dbo->qn('a.id_service') . ' = ' . $service->id);
65
66 $dbo->setQuery($q);
67 $service->options = $dbo->loadObjectList();
68
69 // get assigned employees
70 $q = $dbo->getQuery(true)
71 ->select('a.*')
72 ->select($dbo->qn('e.nickname'))
73 ->from($dbo->qn('#__vikappointments_employee', 'e'))
74 ->leftjoin($dbo->qn('#__vikappointments_ser_emp_assoc', 'a') . ' ON ' . $dbo->qn('e.id') . ' = ' . $dbo->qn('a.id_employee'))
75 ->where($dbo->qn('a.id_service') . ' = ' . $service->id)
76 ->order($dbo->qn('a.ordering') . ' ASC');
77
78 $dbo->setQuery($q);
79 $service->employees = $dbo->loadObjectList();
80 }
81 }
82
83 if (empty($service))
84 {
85 $service = (object) $this->getBlankItem();
86 }
87
88 // use service data stored in user state
89 $this->injectUserStateData($service, 'vap.service.data');
90
91 /**
92 * Load com_contents language file to obtain metadata
93 * labels and descriptions.
94 *
95 * @since 1.6.1
96 */
97 JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
98
99 $this->service = $service;
100
101 // display the template
102 parent::display($tpl);
103 }
104
105 /**
106 * Setting the toolbar.
107 *
108 * @return void
109 */
110 protected function addToolBar($type)
111 {
112 // add menu title and some buttons to the page
113 if ($type == 'edit')
114 {
115 JToolBarHelper::title(JText::translate('VAPMAINTITLEEDITSERVICE'), 'vikappointments');
116 }
117 else
118 {
119 JToolBarHelper::title(JText::translate('VAPMAINTITLENEWSERVICE'), 'vikappointments');
120 }
121
122 $user = JFactory::getUser();
123
124 if ($user->authorise('core.edit', 'com_vikappointments')
125 || $user->authorise('core.create', 'com_vikappointments'))
126 {
127 JToolbarHelper::apply('service.save', JText::translate('VAPSAVE'));
128 JToolbarHelper::save('service.saveclose', JText::translate('VAPSAVEANDCLOSE'));
129 }
130
131 if ($user->authorise('core.edit', 'com_vikappointments')
132 && $user->authorise('core.create', 'com_vikappointments'))
133 {
134 JToolbarHelper::save2new('service.savenew', JText::translate('VAPSAVEANDNEW'));
135 }
136
137 if ($type == 'edit' && $user->authorise('core.create', 'com_vikappointments'))
138 {
139 JToolbarHelper::save2copy('service.savecopy', JText::translate('VAPSAVEASCOPY'));
140 }
141
142 JToolBarHelper::cancel('service.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL');
143 }
144
145 /**
146 * Returns a blank item.
147 *
148 * @return array A blank item for new requests.
149 */
150 protected function getBlankItem()
151 {
152 return array(
153 'id' => 0,
154 'name' => '',
155 'alias' => '',
156 'description' => '',
157 'duration' => 60,
158 'sleep' => 0,
159 'interval' => 1,
160 'minrestr' => -1,
161 'mindate' => -1,
162 'maxdate' => -1,
163 'price' => 0.0,
164 'id_tax' => 0,
165 'max_capacity' => 1,
166 'min_per_res' => 1,
167 'max_per_res' => 1,
168 'priceperpeople' => 1,
169 'app_per_slot' => 1,
170 'published' => 1,
171 'quick_contact' => 0,
172 'choose_emp' => 0,
173 'random_emp' => 0,
174 'has_own_cal' => 0,
175 'checkout_selection' => 0,
176 'display_seats' => 0,
177 'enablezip' => 0,
178 'use_recurrence' => 0,
179 'image' => '',
180 'layout' => 'default-layout',
181 'start_publishing' => '',
182 'end_publishing' => '',
183 'id_group' => 0,
184 'level' => 1,
185 'metadata' => null,
186 'attachments' => array(),
187 'employees' => array(),
188 'options' => array(),
189 );
190 }
191 }
192