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