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 / employees / view.html.php
vikappointments / admin / views / employees Last commit date
tmpl 3 days ago index.html 3 days ago view.html.php 3 days ago
view.html.php
209 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 employees view.
16 *
17 * @since 1.0
18 */
19 class VikAppointmentsViewemployees extends JViewVAP
20 {
21 /**
22 * VikAppointments view display method.
23 *
24 * @return void
25 */
26 function display($tpl = null)
27 {
28 $app = JFactory::getApplication();
29 $input = $app->input;
30 $dbo = JFactory::getDbo();
31
32 // set the toolbar
33 $this->addToolBar();
34
35 $filters = array();
36 $filters['keys'] = $app->getUserStateFromRequest('vapemployees.keys', 'keys', '', 'string');
37 $filters['status'] = $app->getUserStateFromRequest('vapemployees.status', 'status', '', 'string');
38 $filters['id_group'] = $app->getUserStateFromRequest('vapemployees.group', 'id_group', -1, 'int');
39
40 $this->filters = $filters;
41
42 $this->ordering = $app->getUserStateFromRequest('vapemployees.ordering', 'filter_order', 'e.id', 'string');
43 $this->orderDir = $app->getUserStateFromRequest('vapemployees.orderdir', 'filter_order_Dir', 'ASC', 'string');
44
45 // db object
46 $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint');
47 $lim0 = $this->getListLimitStart($filters);
48 $navbut = "";
49
50 $rows = array();
51
52 $q = $dbo->getQuery(true);
53
54 $q->select('SQL_CALC_FOUND_ROWS `e`.*')
55 ->select(array($dbo->qn('g.id', 'gid'), $dbo->qn('g.name', 'gname')))
56 ->from($dbo->qn('#__vikappointments_employee', 'e'))
57 ->leftjoin($dbo->qn('#__vikappointments_employee_group', 'g') . ' ON ' . $dbo->qn('e.id_group') . ' = ' . $dbo->qn('g.id'))
58 ->where(1)
59 ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir);
60
61 /**
62 * Added status filter.
63 *
64 * @since 1.7
65 */
66 if (strlen($filters['status']))
67 {
68 $q->where($dbo->qn('e.listable') . ' = ' . (int) $filters['status']);
69 }
70
71 if ($filters['id_group'] != -1)
72 {
73 $cmp = $filters['id_group'] == 0 ? '<=' : '=';
74
75 $q->where($dbo->qn('e.id_group') . ' ' . $cmp . ' ' . $filters['id_group']);
76 }
77
78 if (strlen($filters['keys']))
79 {
80 $key = $dbo->q("%{$filters['keys']}%");
81
82 $where = array(
83 $dbo->qn('e.firstname') . ' LIKE ' . $key,
84 $dbo->qn('e.lastname') . ' LIKE ' . $key,
85 $dbo->qn('e.email') . ' LIKE ' . $key,
86 );
87
88 $sprintf = 'CONCAT_WS(\' \', %s, %s) LIKE %s';
89
90 /**
91 * Search also by full name (first + last and last + first).
92 *
93 * @since 1.7
94 */
95 $where[] = sprintf($sprintf, $dbo->qn('e.firstname'), $dbo->qn('e.lastname'), $key);
96 $where[] = sprintf($sprintf, $dbo->qn('e.lastname'), $dbo->qn('e.firstname'), $key);
97
98 $q->andWhere($where, 'OR');
99 }
100
101 /**
102 * Add support for manipulating query through the plugins.
103 *
104 * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery()
105 *
106 * @since 1.6.6
107 */
108 $this->onBeforeListQuery($q);
109
110 $dbo->setQuery($q, $lim0, $lim);
111 $dbo->execute();
112
113 // assert limit used for list query
114 $this->assertListQuery($lim0, $lim);
115
116 if ($dbo->getNumRows())
117 {
118 $rows = $dbo->loadAssocList();
119 $dbo->setQuery('SELECT FOUND_ROWS();');
120 jimport('joomla.html.pagination');
121 $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim);
122 $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]);
123 }
124
125 if (VikAppointments::isMultilanguage())
126 {
127 $translator = VAPFactory::getTranslator();
128
129 // find available translations
130 $lang = $translator->getAvailableLang(
131 'employee',
132 array_map(function($row) {
133 return $row['id'];
134 }, $rows)
135 );
136
137 // assign languages found to the related elements
138 foreach ($rows as $k => $row)
139 {
140 $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array();
141 }
142 }
143
144 $this->rows = $rows;
145 $this->navbut = $navbut;
146
147 // display the template (default.php)
148 parent::display($tpl);
149 }
150
151 /**
152 * Setting the toolbar.
153 *
154 * @return void
155 */
156 protected function addToolBar()
157 {
158 // add menu title and some buttons to the page
159 JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWEMPLOYEES'), 'vikappointments');
160
161 $user = JFactory::getUser();
162
163 if ($user->authorise('core.create', 'com_vikappointments'))
164 {
165 JToolBarHelper::addNew('employee.add', JText::translate('VAPNEW'));
166 JToolBarHelper::custom('employee.duplicate', 'copy', 'copy', JText::translate('VAPCLONE'), true);
167 }
168
169 if ($user->authorise('core.edit', 'com_vikappointments'))
170 {
171 JToolBarHelper::editList('employee.edit', JText::translate('VAPEDIT'));
172 }
173
174 if ($user->authorise('core.access.analytics.employees', 'com_vikappointments'))
175 {
176 JToolBarHelper::custom('reportsemp', 'bars', 'bars', JText::translate('VAPREPORTS'), true);
177 }
178
179 if ($user->authorise('core.create', 'com_vikappointments')
180 && $user->authorise('core.access.reservations', 'com_vikappointments'))
181 {
182 JToolBarHelper::custom('closure.add', 'unpublish', 'unpublish', JText::translate('VAPBLOCK'));
183 }
184
185 if ($user->authorise('core.delete', 'com_vikappointments'))
186 {
187 JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'employee.delete', JText::translate('VAPDELETE'));
188 }
189
190 if ($user->authorise('core.create', 'com_vikappointments'))
191 {
192 JToolBarHelper::custom('import', 'upload', 'upload', JText::translate('VAPIMPORT'), false);
193 }
194
195 JToolBarHelper::custom('export', 'download', 'download', JText::translate('VAPEXPORT'), false);
196 }
197
198 /**
199 * Checks for advanced filters set in the request.
200 *
201 * @return boolean True if active, otherwise false.
202 */
203 protected function hasFilters()
204 {
205 return strlen($this->filters['status'])
206 || $this->filters['id_group'] != -1;
207 }
208 }
209