PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / customf / view.html.php
vikappointments / admin / views / customf Last commit date
tmpl 5 months ago index.html 6 years ago view.html.php 2 years ago
view.html.php
227 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 VAPLoader::import('libraries.customfields.factory');
15
16 /**
17 * VikAppointments custom fields view.
18 *
19 * @since 1.0
20 */
21 class VikAppointmentsViewcustomf extends JViewVAP
22 {
23 /**
24 * VikAppointments view display method.
25 *
26 * @return void
27 */
28 function display($tpl = null)
29 {
30 $app = JFactory::getApplication();
31 $input = $app->input;
32 $dbo = JFactory::getDbo();
33
34 // set the toolbar
35 $this->addToolBar();
36
37 $filters = array();
38 $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName() . '.keys', 'keys', '', 'string');
39 $filters['status'] = $app->getUserStateFromRequest($this->getPoolName() . '.status', 'status', '', 'string');
40 $filters['type'] = $app->getUserStateFromRequest($this->getPoolName() . '.type', 'type', '', 'string');
41 $filters['group'] = $app->getUserStateFromRequest($this->getPoolName() . '.group', 'group', 0, 'uint');
42 $filters['rule'] = $app->getUserStateFromRequest($this->getPoolName() . '.rule', 'rule', -1, 'int');
43 $filters['owner'] = $app->getUserStateFromRequest($this->getPoolName() . '.owner', 'owner', -1, 'int');
44
45
46 if ($filters['group'] == 1)
47 {
48 // unset unsupported filters
49 $filters['rule'] = -1;
50 $filters['owner'] = -1;
51 }
52
53 $this->filters = $filters;
54
55 $this->ordering = $app->getUserStateFromRequest($this->getPoolName() . '.ordering', 'filter_order', 'f.ordering', 'string');
56 $this->orderDir = $app->getUserStateFromRequest($this->getPoolName() . '.orderdir', 'filter_order_Dir', 'ASC', 'string');
57
58 // db object
59 $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint');
60 $lim0 = $this->getListLimitStart($filters, $filters['group']);
61 $navbut = "";
62
63 $rows = array();
64
65 $inner = $dbo->getQuery(true)
66 ->select('COUNT(1)')
67 ->from($dbo->qn('#__vikappointments_cf_service_assoc', 'a'))
68 ->where($dbo->qn('a.id_field') . ' = ' . $dbo->qn('f.id'));
69
70 $q = $dbo->getQuery(true);
71
72 $q->select('SQL_CALC_FOUND_ROWS f.*')
73 ->select($dbo->qn('e.nickname', 'ename'))
74 ->select('(' . $inner . ') AS ' . $dbo->qn('services_count'))
75 ->from($dbo->qn('#__vikappointments_custfields', 'f'))
76 ->leftjoin($dbo->qn('#__vikappointments_employee', 'e') . ' ON ' . $dbo->qn('e.id') . ' = ' . $dbo->qn('f.id_employee'))
77 ->where($dbo->qn('group') . ' = ' . $filters['group'])
78 ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir);
79
80 if (strlen($filters['keys']))
81 {
82 $q->andWhere(array(
83 $dbo->qn('f.name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
84 $dbo->qn('e.nickname') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
85 ), 'OR');
86 }
87
88 if (!empty($filters['type']))
89 {
90 $q->where($dbo->qn('f.type') . ' = ' . $dbo->q($filters['type']));
91 }
92
93 if ($filters['rule'] != -1)
94 {
95 $q->where($dbo->qn('f.rule') . ' = ' . $filters['rule']);
96 }
97
98 if ($filters['owner'] != -1)
99 {
100 if ($filters['owner'] == 1)
101 {
102 $q->where($dbo->qn('f.id_employee') . ' > 0');
103 }
104 else if ($filters['owner'] == 2)
105 {
106 $q->having($dbo->qn('services_count') . ' > 0');
107 }
108 else
109 {
110 $q->where($dbo->qn('f.id_employee') . ' <= 0');
111 $q->having($dbo->qn('services_count') . ' = 0');
112 }
113 }
114
115 if (strlen($filters['status']))
116 {
117 if ($filters['status'] == 2)
118 {
119 // filter repeatable custom fields
120 $q->where($dbo->qn('f.repeat') . ' = 1');
121 }
122 else
123 {
124 // filter required/optional custom fields
125 $q->where($dbo->qn('f.required') . ' = ' . (int) $filters['status']);
126 }
127 }
128
129 /**
130 * Add support for manipulating query through the plugins.
131 *
132 * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery()
133 *
134 * @since 1.7
135 */
136 $this->onBeforeListQuery($q);
137
138 $dbo->setQuery($q, $lim0, $lim);
139 $dbo->execute();
140
141 // assert limit used for list query
142 $this->assertListQuery($lim0, $lim, $filters['group']);
143
144 if ($dbo->getNumRows())
145 {
146 $rows = $dbo->loadAssocList();
147 $dbo->setQuery('SELECT FOUND_ROWS();');
148 jimport('joomla.html.pagination');
149 $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim);
150 $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]);
151 }
152
153 if (VikAppointments::isMultilanguage())
154 {
155 $translator = VAPFactory::getTranslator();
156
157 // find available translations
158 $lang = $translator->getAvailableLang(
159 'custfield',
160 array_map(function($row) {
161 return $row['id'];
162 }, $rows)
163 );
164
165 // assign languages found to the related elements
166 foreach ($rows as $k => $row)
167 {
168 if ($row['locale'] && $row['locale'] != '*')
169 {
170 // use only the locale set
171 $rows[$k]['languages'] = array($row['locale']);
172 }
173 else
174 {
175 // the the available translations
176 $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array();
177 }
178 }
179 }
180
181 $this->rows = $rows;
182 $this->navbut = $navbut;
183
184 // display the template (default.php)
185 parent::display($tpl);
186 }
187
188 /**
189 * Setting the toolbar.
190 *
191 * @return void
192 */
193 protected function addToolBar()
194 {
195 // add menu title and some buttons to the page
196 JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWCUSTOMFS'), 'vikappointments');
197
198 $user = JFactory::getUser();
199
200 if ($user->authorise('core.create', 'com_vikappointments'))
201 {
202 JToolBarHelper::addNew('customf.add');
203 }
204 if ($user->authorise('core.edit', 'com_vikappointments'))
205 {
206 JToolBarHelper::editList('customf.edit');
207 }
208 if ($user->authorise('core.delete', 'com_vikappointments'))
209 {
210 JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'customf.delete');
211 }
212 }
213
214 /**
215 * Checks for advanced filters set in the request.
216 *
217 * @return boolean True if active, otherwise false.
218 */
219 protected function hasFilters()
220 {
221 return (!empty($this->filters['type'])
222 || $this->filters['rule'] != -1
223 || $this->filters['owner'] != -1
224 || strlen($this->filters['status']));
225 }
226 }
227