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 / site / helpers / libraries / update / adapters / 1_6_4.php
vikappointments / site / helpers / libraries / update / adapters Last commit date
1_7 1 month ago 1_7_2 1 month ago 1_6.php 1 month ago 1_6_4.php 1 month ago 1_7.php 1 month ago 1_7_2.php 1 month ago index.html 1 month ago
1_6_4.php
139 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 * Update adapter for com_vikappointments 1.6.4 version.
16 *
17 * This class can include update() and finalise().
18 *
19 * NOTE. do not call exit() or die() because the update won't be finalised correctly.
20 * Return false instead to stop in anytime the flow without errors.
21 *
22 * @since 1.6.4
23 */
24 abstract class VAPUpdateAdapter1_6_4
25 {
26 /**
27 * Method run during update process.
28 *
29 * @param object $parent The parent that calls this method.
30 *
31 * @return boolean True on success, otherwise false to stop the flow.
32 */
33 public static function update($parent)
34 {
35 try
36 {
37 // updates the ordering of the subscriptions
38 self::fixSubscriptionsOrdering();
39
40 // updates the ordering of the services-employees relations
41 self::fixServicesEmployeesOrdering();
42 }
43 catch (Exception $e)
44 {
45 JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
46
47 return false;
48 }
49
50 return true;
51 }
52
53 /**
54 * Updates the ordering columns of the subscriptions.
55 *
56 * @return boolean True on success, false otherwise.
57 */
58 protected static function fixSubscriptionsOrdering()
59 {
60 $dbo = JFactory::getDbo();
61
62 $q = $dbo->getQuery(true)
63 ->select('*')
64 ->from($dbo->qn('#__vikappointments_subscription'))
65 ->order(array(
66 $dbo->qn('type') . ' ASC',
67 $dbo->qn('amount') . ' ASC',
68 ));
69
70 $dbo->setQuery($q);
71 $dbo->execute();
72
73 if ($dbo->getNumRows())
74 {
75 foreach ($dbo->loadObjectList() as $i => $subscr)
76 {
77 // update ordering
78 $subscr->ordering = $i + 1;
79
80 $dbo->updateObject('#__vikappointments_subscription', $subscr, 'id');
81 }
82 }
83
84 return true;
85 }
86
87 /**
88 * Updates the ordering columns of the services-employees relations.
89 *
90 * @return boolean True on success, false otherwise.
91 */
92 protected static function fixServicesEmployeesOrdering()
93 {
94 $dbo = JFactory::getDbo();
95
96 $q = $dbo->getQuery(true)
97 ->select($dbo->qn('id'))
98 ->from($dbo->qn('#__vikappointments_service'));
99
100 $dbo->setQuery($q);
101 $dbo->execute();
102
103 if (!$dbo->getNumRows())
104 {
105 // no installed services
106 return true;
107 }
108
109 foreach ($dbo->loadColumn() as $id_service)
110 {
111 $q = $dbo->getQuery(true)
112 ->select($dbo->qn('a.id'))
113 ->from($dbo->qn('#__vikappointments_ser_emp_assoc', 'a'))
114 ->leftjoin($dbo->qn('#__vikappointments_employee', 'e') . ' ON ' . $dbo->qn('e.id') . ' = ' . $dbo->qn('a.id_employee'))
115 ->where($dbo->qn('a.id_service') . ' = ' . $id_service)
116 ->order($dbo->qn('e.nickname') . ' ASC');
117
118 $dbo->setQuery($q);
119 $dbo->execute();
120
121 if ($dbo->getNumRows())
122 {
123 foreach ($dbo->loadColumn() as $i => $id)
124 {
125 $q = $dbo->getQuery(true)
126 ->update($dbo->qn('#__vikappointments_ser_emp_assoc'))
127 ->set($dbo->qn('ordering') . ' = ' . ($i + 1))
128 ->where($dbo->qn('id') . ' = ' . $id);
129
130 $dbo->setQuery($q);
131 $dbo->execute();
132 }
133 }
134 }
135
136 return true;
137 }
138 }
139