PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / services / view.html.php
vikappointments / admin / views / services Last commit date
tmpl 4 years ago index.html 6 years ago view.html.php 2 years ago
view.html.php
182 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 services view.
16 *
17 * @since 1.0
18 */
19 class VikAppointmentsViewservices 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('vapservices.keys', 'keys', '', 'string');
37 $filters['status'] = $app->getUserStateFromRequest('vapservices.status', 'status', '', 'string');
38 $filters['id_group'] = $app->getUserStateFromRequest('vapservices.group', 'id_group', -1, 'int');
39
40 $this->filters = $filters;
41
42 $this->ordering = $app->getUserStateFromRequest('vapservices.ordering', 'filter_order', 's.ordering', 'string');
43 $this->orderDir = $app->getUserStateFromRequest('vapservices.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 s.*')
55 ->select($dbo->qn('g.name', 'group_name'))
56 ->from($dbo->qn('#__vikappointments_service', 's'))
57 ->leftjoin($dbo->qn('#__vikappointments_group', 'g') . ' ON ' . $dbo->qn('s.id_group') . ' = ' . $dbo->qn('g.id'))
58 ->where(1)
59 ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir);
60
61 if (!empty($filters['keys']))
62 {
63 $q->andWhere(array(
64 $dbo->qn('s.name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
65 $dbo->qn('s.description') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
66 ), 'OR');
67 }
68
69 if (strlen($filters['status']))
70 {
71 $q->where($dbo->qn('s.published') . ' = ' . (int) $filters['status']);
72 }
73
74 if ($filters['id_group'] != -1)
75 {
76 $cmp = $filters['id_group'] == 0 ? '<=' : '=';
77
78 $q->where($dbo->qn('s.id_group') . ' ' . $cmp . ' ' . $filters['id_group']);
79 }
80
81 /**
82 * Add support for manipulating query through the plugins.
83 *
84 * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery()
85 *
86 * @since 1.6.6
87 */
88 $this->onBeforeListQuery($q);
89
90 $dbo->setQuery($q, $lim0, $lim);
91 $dbo->execute();
92
93 // assert limit used for list query
94 $this->assertListQuery($lim0, $lim);
95
96 if ($dbo->getNumRows())
97 {
98 $rows = $dbo->loadAssocList();
99 $dbo->setQuery('SELECT FOUND_ROWS();');
100 jimport('joomla.html.pagination');
101 $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim);
102 $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]);
103 }
104
105 if (VikAppointments::isMultilanguage())
106 {
107 $translator = VAPFactory::getTranslator();
108
109 // find available translations
110 $lang = $translator->getAvailableLang(
111 'service',
112 array_map(function($row) {
113 return $row['id'];
114 }, $rows)
115 );
116
117 // assign languages found to the related elements
118 foreach ($rows as $k => $row)
119 {
120 $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array();
121 }
122 }
123
124 $this->rows = $rows;
125 $this->navbut = $navbut;
126
127 // display the template (default.php)
128 parent::display($tpl);
129 }
130
131 /**
132 * Setting the toolbar.
133 *
134 * @return void
135 */
136 protected function addToolBar()
137 {
138 // add menu title and some buttons to the page
139 JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWSERVICES'), 'vikappointments');
140
141 $user = JFactory::getUser();
142
143 if ($user->authorise('core.create', 'com_vikappointments'))
144 {
145 JToolBarHelper::addNew('service.add');
146 }
147
148 if ($user->authorise('core.edit', 'com_vikappointments'))
149 {
150 JToolBarHelper::editList('service.edit');
151 }
152
153 if ($user->authorise('core.access.analytics.services', 'com_vikappointments'))
154 {
155 JToolBarHelper::custom('reportsser', 'bars', 'bars', JText::translate('VAPREPORTS'), true);
156 }
157
158 if ($user->authorise('core.delete', 'com_vikappointments'))
159 {
160 JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'service.delete');
161 }
162
163 if ($user->authorise('core.create', 'com_vikappointments'))
164 {
165 JToolBarHelper::custom('import', 'upload', 'upload', JText::translate('VAPIMPORT'), false);
166 }
167
168 JToolBarHelper::custom('export', 'download', 'download', JText::translate('VAPEXPORT'), false);
169 }
170
171 /**
172 * Checks for advanced filters set in the request.
173 *
174 * @return boolean True if active, otherwise false.
175 */
176 protected function hasFilters()
177 {
178 return strlen($this->filters['status'])
179 || $this->filters['id_group'] != -1;
180 }
181 }
182