PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / states / view.html.php
vikappointments / admin / views / states Last commit date
tmpl 2 years ago index.html 4 years ago view.html.php 2 years ago
view.html.php
180 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 states view.
16 *
17 * @since 1.5
18 */
19 class VikAppointmentsViewstates 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 $id_country = $input->get('id_country', 0, 'uint');
33
34 /**
35 * The filters are also handled by the export gateway.
36 *
37 * @see libraries.import.classes.states
38 */
39 $filters = array();
40 $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName($id_country) . '.keys', 'keys', '', 'string');
41 $filters['status'] = $app->getUserStateFromRequest($this->getPoolName($id_country) . '.status', 'status', '', 'string');
42 $filters['id_country'] = $id_country;
43
44 $this->filters = $filters;
45
46 $this->ordering = $app->getUserStateFromRequest('vapstates.ordering', 'filter_order', 's.state_name', 'string');
47 $this->orderDir = $app->getUserStateFromRequest('vapstates.orderdir', 'filter_order_Dir', 'ASC', 'string');
48
49 // db object
50 $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint');
51 $lim0 = $this->getListLimitStart($filters, $id_country);
52 $navbut = "";
53
54 $q = $dbo->getQuery(true)
55 ->select($dbo->qn('country_name'))
56 ->from($dbo->qn('#__vikappointments_countries'))
57 ->where($dbo->qn('id') . ' = ' . $filters['id_country']);
58
59 $dbo->setQuery($q, 0, 1);
60 $countryName = $dbo->loadResult();
61
62 if (!$countryName)
63 {
64 // country not found, back to list
65 $app->redirect('index.php?option=com_vikappointments&view=countries');
66 exit;
67 }
68
69 // set the toolbar
70 $this->addToolBar($countryName);
71
72 $rows = array();
73
74 $citiesCount = $dbo->getQuery(true)
75 ->select('COUNT(1)')
76 ->from($dbo->qn('#__vikappointments_cities', 'c'))
77 ->where($dbo->qn('c.id_state') . ' = ' . $dbo->qn('s.id'));
78
79 $q = $dbo->getQuery(true)
80 ->select('SQL_CALC_FOUND_ROWS s.*')
81 ->select('(' . $citiesCount . ') AS ' . $dbo->qn('cities_count'))
82 ->from($dbo->qn('#__vikappointments_states', 's'))
83 ->where($dbo->qn('s.id_country') . ' = ' . $id_country)
84 ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir);
85
86 if (strlen($filters['keys']))
87 {
88 $q->where($dbo->qn('s.state_name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"));
89 }
90
91 if (strlen($filters['status']))
92 {
93 $q->where($dbo->qn('s.published') . ' = ' . (int) $filters['status']);
94 }
95
96 /**
97 * Add support for manipulating query through the plugins.
98 *
99 * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery()
100 *
101 * @since 1.7
102 */
103 $this->onBeforeListQuery($q);
104
105 $dbo->setQuery($q, $lim0, $lim);
106 $dbo->execute();
107
108 // assert limit used for list query
109 $this->assertListQuery($lim0, $lim, $id_country);
110
111 if ($dbo->getNumRows() > 0)
112 {
113 $rows = $dbo->loadAssocList();
114 $dbo->setQuery('SELECT FOUND_ROWS();');
115 jimport('joomla.html.pagination');
116 $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim);
117 $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]);
118 }
119
120 $this->rows = $rows;
121 $this->navbut = $navbut;
122
123 // display the template (default.php)
124 parent::display($tpl);
125 }
126
127 /**
128 * Setting the toolbar.
129 *
130 * @return void
131 */
132 protected function addToolBar($country_name)
133 {
134 // add menu title and some buttons to the page
135 JToolBarHelper::title(JText::sprintf('VAPMAINTITLEVIEWSTATES', $country_name), 'vikappointments');
136
137 $user = JFactory::getUser();
138
139 JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_vikappointments&view=countries');
140
141 if ($user->authorise('core.create', 'com_vikappointments'))
142 {
143 JToolBarHelper::addNew('state.add');
144 }
145
146 if ($user->authorise('core.edit', 'com_vikappointments'))
147 {
148 JToolBarHelper::editList('state.edit');
149 }
150
151 if ($user->authorise('core.edit.state', 'com_vikappointments'))
152 {
153 JToolBarHelper::publishList('state.publish');
154 JToolBarHelper::unpublishList('state.unpublish');
155 }
156
157 if ($user->authorise('core.create', 'com_vikappointments'))
158 {
159 JToolBarHelper::custom('import', 'upload', 'upload', JText::translate('VAPIMPORT'), false);
160 }
161
162 JToolBarHelper::custom('export', 'download', 'download', JText::translate('VAPEXPORT'), false);
163
164 if ($user->authorise('core.delete', 'com_vikappointments'))
165 {
166 JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'state.delete');
167 }
168 }
169
170 /**
171 * Checks for advanced filters set in the request.
172 *
173 * @return boolean True if active, otherwise false.
174 */
175 protected function hasFilters()
176 {
177 return (strlen($this->filters['status']));
178 }
179 }
180