PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / models / location.php
vikappointments / admin / models Last commit date
apiban.php 4 years ago apilog.php 2 years ago apiplugin.php 4 years ago apiuser.php 2 years ago apiuseroptions.php 2 years ago backup.php 4 months ago caldays.php 1 month ago calendar.php 1 month ago city.php 4 years ago closure.php 1 month ago configapp.php 4 years ago configcldays.php 4 years ago configcron.php 4 years ago configemp.php 4 years ago configsmsapi.php 4 years ago configuration.php 4 months ago conversion.php 4 years ago country.php 2 years ago coupon.php 2 years ago couponemployee.php 4 years ago coupongroup.php 2 years ago couponservice.php 4 years ago cronjob.php 2 years ago cronjoblog.php 4 years ago customer.php 4 months ago customf.php 2 years ago customfservice.php 4 years ago customizer.php 4 years ago empgroup.php 2 years ago employee.php 2 years ago empsettings.php 4 years ago file.php 4 years ago findreservation.php 1 month ago group.php 2 years ago import.php 4 years ago index.html 4 years ago invoice.php 1 month ago langcustomf.php 4 years ago langempgroup.php 4 years ago langemployee.php 4 years ago langgroup.php 4 years ago langmedia.php 4 years ago langoption.php 2 years ago langoptiongroup.php 4 years ago langoptionvar.php 4 years ago langpackage.php 4 years ago langpackgroup.php 4 years ago langpayment.php 4 years ago langservice.php 4 years ago langstatuscode.php 4 years ago langsubscr.php 4 years ago langtax.php 2 years ago langtaxrule.php 4 years ago location.php 2 years ago mailtext.php 2 years ago makerecurrence.php 1 month ago media.php 2 years ago multiorder.php 1 month ago option.php 1 year ago optiongroup.php 2 years ago optionvar.php 1 year ago orderstatus.php 2 years ago package.php 2 years ago packageservice.php 4 years ago packgroup.php 2 years ago packorder.php 2 years ago packorderitem.php 1 month ago payment.php 2 years ago rate.php 2 years ago reportsemp.php 4 months ago reportsser.php 4 months ago reservation.php 1 month ago resoptassoc.php 2 years ago restriction.php 2 years ago review.php 3 years ago serempassoc.php 1 year ago seroptassoc.php 4 years ago serrateassoc.php 4 years ago serrestrassoc.php 4 years ago service.php 2 years ago state.php 2 years ago statswidget.php 2 years ago statuscode.php 2 years ago subscription.php 1 month ago subscrorder.php 1 month ago tag.php 4 years ago tax.php 2 years ago taxrule.php 2 years ago updateprogram.php 4 years ago usernote.php 2 years ago waitinglist.php 1 month ago webhook.php 1 year ago worktime.php 1 month ago
location.php
197 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.mvc.model');
15
16 /**
17 * VikAppointments location model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelLocation extends JModelVAP
22 {
23 /**
24 * Cache of location details.
25 *
26 * @var array
27 */
28 public static $info = array();
29
30 /**
31 * Extend delete implementation to delete any related records
32 * stored within a separated table.
33 *
34 * @param mixed $ids Either the record ID or a list of records.
35 *
36 * @return boolean True on success, false otherwise.
37 */
38 public function delete($ids)
39 {
40 // only int values are accepted
41 $ids = array_map('intval', (array) $ids);
42
43 // invoke parent first
44 if (!parent::delete($ids))
45 {
46 // nothing to delete
47 return false;
48 }
49
50 $dbo = JFactory::getDbo();
51
52 // load any assigned working time
53 $q = $dbo->getQuery(true)
54 ->select($dbo->qn('id'))
55 ->from($dbo->qn('#__vikappointments_emp_worktime'))
56 ->where($dbo->qn('id_location') . ' IN (' . implode(',', $ids) . ')' );
57
58 $dbo->setQuery($q);
59
60 if ($worktime_ids = $dbo->loadColumn())
61 {
62 // get worktime model
63 $model = JModelVAP::getInstance('worktime');
64
65 // detach location from worktimes
66 foreach ($worktime_ids as $worktime_id)
67 {
68 $data = array(
69 'id' => (int) $worktime_id,
70 'id_location' => 0,
71 );
72
73 $model->save($data);
74 }
75 }
76
77 return true;
78 }
79
80 /**
81 * Method used to return the details of the given location.
82 *
83 * @param integer $id_location The location ID.
84 *
85 * @return mixed The location details on success, null otherwise.
86 */
87 public function getInfo($id_location)
88 {
89 if ((int) $id_location <= 0)
90 {
91 return null;
92 }
93
94 // load details only if not yet cached
95 if (!isset(static::$info[$id_location]))
96 {
97 $dbo = JFactory::getDbo();
98
99 $q = $dbo->getQuery(true)
100 ->select('l.*')
101 ->select($dbo->qn('c.country_2_code', 'countryCode2'))
102 ->select($dbo->qn('c.country_3_code', 'countryCode3'))
103 ->select($dbo->qn('c.country_name', 'countryName'))
104 ->select($dbo->qn('s.state_2_code', 'stateCode2'))
105 ->select($dbo->qn('s.state_name', 'stateName'))
106 ->select($dbo->qn('ci.city_name', 'cityName'))
107 ->from($dbo->qn('#__vikappointments_employee_location', 'l'))
108 ->leftjoin($dbo->qn('#__vikappointments_countries', 'c') . ' ON ' . $dbo->qn('l.id_country') . ' = ' . $dbo->qn('c.id'))
109 ->leftjoin($dbo->qn('#__vikappointments_states', 's') . ' ON ' . $dbo->qn('l.id_state') . ' = ' . $dbo->qn('s.id'))
110 ->leftjoin($dbo->qn('#__vikappointments_cities', 'ci') . ' ON ' . $dbo->qn('l.id_city') . ' = ' . $dbo->qn('ci.id'))
111 ->where($dbo->qn('l.id') . ' = ' . (int) $id_location);
112
113 $dbo->setQuery($q, 0, 1);
114
115 // get location data
116 $location = $dbo->loadObject();
117
118 if (!$location)
119 {
120 return null;
121 }
122
123 // create LONG location text by using the following format
124 // [ADDRESS], [ZIP] [CITY] [STATE], [COUNTRY]
125
126 $components = array();
127
128 // register address first
129 $components[] = $location->address;
130
131 $block = array();
132
133 // register ZIP within 2nd block
134 $block[] = $location->zip;
135
136 // register city within 2nd block
137 $block[] = $location->cityName;
138
139 // register state/province code within 2nd block
140 $block[] = $location->stateCode2;
141
142 // register 2nd block
143 $components[] = implode(' ', array_filter($block));
144
145 // register country code (2 letters)
146 $components[] = $location->countryCode2;
147
148 // join string components
149 $location->text = implode(', ', array_filter($components));
150
151 // create SHORT location text by using the following format
152 // [ADDRESS], [ZIP] [CITY]
153
154 $components = array();
155
156 // register address first
157 $components[] = $location->address;
158
159 $block = array();
160
161 // register ZIP within 2nd block
162 $block[] = $location->zip;
163
164 // register city within 2nd block
165 $block[] = $location->cityName;
166
167 // register 2nd block
168 $components[] = implode(' ', array_filter($block));
169
170 // join string components
171 $location->short = implode(', ', array_filter($components));
172
173 /**
174 * This event can be used to manipulate the location details and the
175 * full address strings at runtime. It is suggested to override the
176 * following properties in case the default format is not suitable
177 * to a specific area:
178 *
179 * $location->text
180 * $location->short
181 *
182 * @param object $location The location object.
183 *
184 * @return void
185 *
186 * @since 1.7
187 */
188 VAPFactory::getEventDispatcher()->false('onLocationGetInfo', array($location));
189
190 // cache result
191 static::$info[$id_location] = $location;
192 }
193
194 return static::$info[$id_location];
195 }
196 }
197