PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / usernotes / view.html.php
vikappointments / admin / views / usernotes Last commit date
tmpl 4 years ago index.html 4 years ago view.html.php 2 years ago
view.html.php
236 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 user notes view.
16 *
17 * @since 1.7
18 */
19 class VikAppointmentsViewusernotes 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 $layout = $input->get('layout');
33
34 $filters = array();
35 $filters['id_user'] = $input->getUint('id_user', 0);
36 $filters['id_parent'] = $input->getUint('id_parent', 0);
37 $filters['group'] = $input->get('group');
38
39 if ($layout != 'modal')
40 {
41 // set the toolbar
42 $this->addToolBar();
43
44 $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName() . '.keys', 'keys', '', 'string');
45 $filters['status'] = $app->getUserStateFromRequest($this->getPoolName() . '.status', 'status', '', 'string');
46 $filters['tag'] = $app->getUserStateFromRequest($this->getPoolName() . '.tag', 'tag', 0, 'uint');
47
48 $this->ordering = $app->getUserStateFromRequest($this->getPoolName() . '.ordering', 'filter_order', 'n.createdon', 'string');
49 $this->orderDir = $app->getUserStateFromRequest($this->getPoolName() . '.orderdir', 'filter_order_Dir', 'DESC', 'string');
50
51 $lim0 = $this->getListLimitStart($filters);
52 }
53 else
54 {
55 // ignore filters
56 $filters['keys'] = $filters['status'] = $filters['tag'] = '';
57
58 // always sort in descending order when using the modal layout
59 $this->ordering = 'n.modifiedon';
60 $this->orderDir = 'DESC';
61
62 $this->headingTitle = '';
63
64 // reset list limit
65 $lim0 = 0;
66
67 if ($filters['id_user'])
68 {
69 $q = $dbo->getQuery(true)
70 ->select('billing_name')
71 ->from($dbo->qn('#__vikappointments_users'))
72 ->where($dbo->qn('id') . ' = ' . (int) $filters['id_user']);
73
74 $dbo->setQuery($q, 0, 1);
75 $customerName = $dbo->loadResult();
76
77 if ($customerName)
78 {
79 $this->headingTitle = JText::sprintf('VAPMODALTITLEUSERNOTES', $customerName);
80 }
81 }
82
83 $this->setLayout('modal');
84 }
85
86 $this->filters = $filters;
87
88 // db object
89 $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint');
90 $navbut = "";
91
92 $rows = array();
93
94 $q = $dbo->getQuery(true);
95
96 $q->select('SQL_CALC_FOUND_ROWS n.*')
97 ->select($dbo->qn('u.name', 'author_name'))
98 ->from($dbo->qn('#__vikappointments_user_notes', 'n'))
99 ->leftjoin($dbo->qn('#__users', 'u') . ' ON ' . $dbo->qn('u.id') . ' = ' . $dbo->qn('n.author'))
100 ->where(1);
101
102 if ($this->ordering == 'n.modifiedon')
103 {
104 // sort by modify date (use creation date if null)
105 $q->order(sprintf(
106 'IFNULL(%s, %s) %s',
107 $dbo->qn('n.modifiedon'),
108 $dbo->qn('n.createdon'),
109 $this->orderDir
110 ));
111 }
112 else
113 {
114 $q->order($dbo->qn($this->ordering) . ' ' . $this->orderDir);
115 }
116
117 if (!empty($filters['keys']))
118 {
119 $q->andWhere(array(
120 $dbo->qn('n.title') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
121 $dbo->qn('n.content') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"),
122 ), 'OR');
123 }
124
125 if ($filters['id_user'])
126 {
127 // filter by user ID
128 $q->where($dbo->qn('n.id_user') . ' = ' . $filters['id_user']);
129 }
130
131 if ($filters['id_parent'])
132 {
133 // filter by parent ID
134 $q->where($dbo->qn('n.id_parent') . ' = ' . $filters['id_parent']);
135 }
136
137 if ($filters['group'])
138 {
139 // filter by user ID
140 $q->where($dbo->qn('n.group') . ' = ' . $dbo->q($filters['group']));
141 }
142
143 if (strlen($filters['status']))
144 {
145 $q->where($dbo->qn('n.status') . ' = ' . (int) $filters['status']);
146 }
147
148 if ($filters['tag'])
149 {
150 $q->andWhere(array(
151 // only one tag
152 $dbo->qn('n.tags') . ' = ' . $dbo->q($filters['tag']),
153 // tag in the middle
154 $dbo->qn('n.tags') . ' LIKE ' . $dbo->q("%,{$filters['tag']},%"),
155 // first tag of the list
156 $dbo->qn('n.tags') . ' LIKE ' . $dbo->q("{$filters['tag']},%"),
157 // last tag of the list
158 $dbo->qn('n.tags') . ' LIKE ' . $dbo->q("%,{$filters['tag']}"),
159 ), 'OR');
160 }
161
162 /**
163 * Add support for manipulating query through the plugins.
164 *
165 * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery()
166 *
167 * @since 1.7
168 */
169 $this->onBeforeListQuery($q);
170
171 $dbo->setQuery($q, $lim0, $lim);
172 $dbo->execute();
173
174 // assert limit used for list query
175 $this->assertListQuery($lim0, $lim);
176
177 if ($dbo->getNumRows())
178 {
179 $rows = $dbo->loadAssocList();
180 $dbo->setQuery('SELECT FOUND_ROWS();');
181 jimport('joomla.html.pagination');
182 $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim);
183 $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]);
184 }
185
186 $this->rows = $rows;
187 $this->navbut = $navbut;
188
189 $this->tagModel = JModelVAP::getInstance('tag');
190
191 // display the template (default.php)
192 parent::display($tpl);
193 }
194
195 /**
196 * Setting the toolbar.
197 *
198 * @return void
199 */
200 protected function addToolBar()
201 {
202 // add menu title and some buttons to the page
203 JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWUSERNOTES'), 'vikappointments');
204
205 $user = JFactory::getUser();
206
207 JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_vikappointments&view=customers');
208
209 if ($user->authorise('core.create', 'com_vikappointments'))
210 {
211 JToolBarHelper::addNew('usernote.add');
212 }
213
214 if ($user->authorise('core.edit', 'com_vikappointments'))
215 {
216 JToolBarHelper::editList('usernote.edit');
217 }
218
219 if ($user->authorise('core.delete', 'com_vikappointments'))
220 {
221 JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'usernote.delete');
222 }
223 }
224
225 /**
226 * Checks for advanced filters set in the request.
227 *
228 * @return boolean True if active, otherwise false.
229 */
230 protected function hasFilters()
231 {
232 return strlen($this->filters['status'])
233 || $this->filters['tag'];
234 }
235 }
236