PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / modules / mod_vikappointments_zip / libraries / helper.php
vikappointments / modules / mod_vikappointments_zip / libraries Last commit date
helper.php 1 month ago index.html 1 month ago
helper.php
196 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage mod_vikappointments_zip
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 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 to this file
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.helpers.module');
15
16 /**
17 * Helper class used by the ZIP Checker module.
18 *
19 * @since 1.2
20 */
21 class VikAppointmentsZipCheckerHelper
22 {
23 /**
24 * Use methods defined by modules trait for a better reusability.
25 *
26 * @see VAPModuleHelper
27 *
28 * @since 1.3
29 */
30 use VAPModuleHelper;
31
32 /**
33 * Returns the list of all the services that can be evaluated.
34 *
35 * @param JRegistry $params The configuration registry.
36 *
37 * @return array The services list.
38 */
39 public static function getServices($params)
40 {
41 $dbo = JFactory::getDbo();
42 $user = JFactory::getUser();
43
44 // get services
45
46 $services = array();
47
48 $group_ids = $service_ids = array();
49
50 /**
51 * Fixed an issue that was joining the services with the groups
52 * by using a wrong ON condition.
53 *
54 * @since 1.3
55 */
56 $q = $dbo->getQuery(true)
57 ->select($dbo->qn(array('s.id', 's.name', 's.choose_emp', 's.id_group')))
58 ->select($dbo->qn('g.id', 'gid'))
59 ->select($dbo->qn('g.name', 'gname'))
60 ->from($dbo->qn('#__vikappointments_service', 's'))
61 ->leftjoin($dbo->qn('#__vikappointments_group', 'g') . ' ON ' . $dbo->qn('s.id_group') . ' = ' . $dbo->qn('g.id'))
62 ->where($dbo->qn('s.published') . ' = 1')
63 ->order(array(
64 $dbo->qn('g.ordering') . ' ASC',
65 $dbo->qn('s.ordering') . ' ASC',
66 $dbo->qn('s.name') . ' ASC',
67 ));
68
69 if ($params->get('displayser') == 2)
70 {
71 $q->where($dbo->qn('s.enablezip') . ' = 1');
72 }
73
74 /**
75 * Retrieve only the services that belong to the view
76 * access level of the current user.
77 *
78 * @since 1.2
79 */
80 $levels = $user->getAuthorisedViewLevels();
81
82 if ($levels)
83 {
84 $q->where($dbo->qn('s.level') . ' IN (' . implode(', ', $levels) . ')');
85 }
86
87 $dbo->setQuery($q);
88
89 foreach ($dbo->loadAssocList() as $r)
90 {
91 if (!isset($services[$r['id_group']]))
92 {
93 $services[$r['id_group']] = array(
94 'id' => $r['gid'],
95 'name' => $r['gname'],
96 'list' => array(),
97 );
98
99 if ($r['id_group'])
100 {
101 $group_ids[] = $r['id_group'];
102 }
103 }
104
105 $services[$r['id_group']]['list'][] = array(
106 'id' => $r['id'],
107 'name' => $r['name'],
108 'choose_emp' => $r['choose_emp'],
109 'id_group' => $r['id_group'],
110 );
111
112 $service_ids[] = $r['id'];
113 }
114
115 $translator = VAPFactory::getTranslator();
116
117 $lang = JFactory::getLanguage()->getTag();
118
119 // preload translations
120 $serLang = $translator->load('service', array_unique($service_ids), $lang);
121 $grpLang = $translator->load('group', array_unique($group_ids), $lang);
122
123 foreach ($services as $id_group => $group)
124 {
125 // translate record for the given language
126 $tx = $grpLang->getTranslation($id_group, $lang);
127
128 if ($tx)
129 {
130 $group['name'] = $tx->name;
131 }
132
133 foreach ($group['list'] as $i => $service)
134 {
135 // translate record for the given language
136 $tx = $serLang->getTranslation($service['id'], $lang);
137
138 if ($tx)
139 {
140 $group['list'][$i]['name'] = $tx->name;
141 }
142 }
143
144 // update group
145 $services[$id_group] = $group;
146 }
147
148 // always append services without group at the end of the list
149 if (isset($services[0]))
150 {
151 $tmp = $services[0];
152 unset($services[0]);
153 $services[0] = $tmp;
154 }
155
156 return $services;
157 }
158
159 /**
160 * Returns the list of all the employees that are assigned to the specified service.
161 *
162 * @param integer $id_service The service ID.
163 *
164 * @return array The employees list.
165 */
166 public static function getEmployees($id_service)
167 {
168 /**
169 * Include the folder containing all the VikAppointments models for the site client.
170 *
171 * @since 1.3.2
172 */
173 JModelLegacy::addIncludePath(VAPBASE . DIRECTORY_SEPARATOR . 'models');
174
175 /**
176 * Take only the employees that should be listed.
177 *
178 * @since 1.2.2
179 */
180 $employees = JModelVAP::getInstance('service')->getEmployees($id_service, $strict = true);
181
182 if ($employees)
183 {
184 // convert to array for backward compatibility
185 $employees = array_map(function($elem)
186 {
187 return (array) $elem;
188 }, $employees);
189
190 VikAppointments::translateEmployees($employees);
191 }
192
193 return $employees;
194 }
195 }
196