PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / models / allorders.php
vikappointments / site / models Last commit date
allorders.php 2 years ago calendarweek.php 1 month ago cart.php 1 month ago confirmapp.php 1 month ago empaccountstat.php 2 years ago empattachser.php 2 years ago empcoupons.php 2 years ago empcustfields.php 2 years ago empeditcoupon.php 3 years ago empeditcustfield.php 3 years ago empeditlocation.php 3 years ago empeditpay.php 3 years ago empeditprofile.php 5 months ago empeditservice.php 3 years ago empeditwdays.php 3 years ago emplocations.php 2 years ago emplocwdays.php 4 years ago emplogin.php 1 month ago employeesearch.php 1 month ago employeeslist.php 1 month ago empmanres.php 2 years ago emppaylist.php 2 years ago empserviceslist.php 2 years ago empsettingsman.php 4 years ago empsubscrcart.php 4 years ago empsubscrhistory.php 2 years ago empsubscrorder.php 5 months ago empwdays.php 2 years ago index.html 4 years ago packages.php 2 years ago packagescart.php 4 years ago packagesconfirm.php 5 months ago packorders.php 2 years ago servicesearch.php 2 years ago serviceslist.php 2 years ago subscrcart.php 2 years ago subscrhistory.php 2 years ago subscrpayment.php 5 months ago
allorders.php
216 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 all orders list view model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelAllorders extends JModelVAP
22 {
23 /**
24 * The list view pagination object.
25 *
26 * @var JPagination
27 */
28 protected $pagination = null;
29
30 /**
31 * The total number of fetched rows.
32 *
33 * @var integer
34 */
35 protected $total = 0;
36
37 /**
38 * Loads a list of appointments to be displayed within the
39 * all orders site view.
40 *
41 * @param array &$options An array of options.
42 *
43 * @return array A list of orders.
44 */
45 public function getItems(array &$options = array())
46 {
47 // always reset pagination and total count
48 $this->pagination = null;
49 $this->total = 0;
50
51 $dispatcher = VAPFactory::getEventDispatcher();
52
53 // get currently logged in user
54 $user = JFactory::getUser();
55
56 if ($user->guest)
57 {
58 // do not load orders assigned to guest user
59 return array();
60 }
61
62 if (!array_key_exists('start', $options))
63 {
64 // start from the beginning
65 $options['start'] = 0;
66 }
67
68 if (!array_key_exists('limit', $options))
69 {
70 // use default number of items
71 $options['limit'] = 5;
72 }
73
74 $dbo = JFactory::getDbo();
75
76 $orders = array();
77
78 $q = $dbo->getQuery(true);
79
80 $q->select('SQL_CALC_FOUND_ROWS ' . $dbo->qn('r.id'));
81 $q->from($dbo->qn('#__vikappointments_reservation', 'r'));
82 $q->leftjoin($dbo->qn('#__vikappointments_users', 'u') . ' ON ' . $dbo->qn('r.id_user') . ' = ' . $dbo->qn('u.id'));
83
84 // filter reservations by user
85 $q->where($dbo->qn('u.jid') . ' = ' . (int) $user->id);
86
87 // get parent orders or single appointments
88 $q->andWhere(array(
89 $dbo->qn('r.id_parent') . ' <= 0',
90 $dbo->qn('r.id_parent') . ' = ' . $dbo->qn('r.id'),
91 ), 'OR');
92
93 $q->order($dbo->qn('r.id') . ' DESC');
94
95 /**
96 * Trigger hook to manipulate the query at runtime. Third party plugins
97 * can extend the query by applying further conditions or selecting
98 * additional data.
99 *
100 * @param mixed &$query Either a query builder or a query string.
101 * @param array &$options An array of options.
102 *
103 * @return void
104 *
105 * @since 1.7
106 */
107 $dispatcher->trigger('onBuildAllOrdersQuery', array(&$q, &$options));
108
109 $dbo->setQuery($q, $options['start'], $options['limit']);
110
111 if ($rows = $dbo->loadColumn())
112 {
113 // fetch pagination
114 $this->getPagination($options);
115
116 VAPLoader::import('libraries.order.factory');
117 $tag = JFactory::getLanguage()->getTag();
118
119 foreach ($rows as $id_order)
120 {
121 // get order details
122 $orders[] = VAPOrderFactory::getAppointments($id_order, $tag);
123 }
124 }
125
126 /**
127 * Trigger hook to manipulate the query response at runtime. Third party
128 * plugins can alter the resulting list of orders.
129 *
130 * @param array &$orders An array of fetched orders.
131 * @param JModel $model The current model.
132 *
133 * @return void
134 *
135 * @since 1.7
136 */
137 $dispatcher->trigger('onBuildAllOrdersData', array(&$orders, $this));
138
139 return $orders;
140 }
141
142 /**
143 * Returns the list pagination.
144 *
145 * @param array $options An array of options.
146 *
147 * @return JPagination
148 */
149 public function getPagination(array $options = array())
150 {
151 if (!$this->pagination)
152 {
153 jimport('joomla.html.pagination');
154 $dbo = JFactory::getDbo();
155 $dbo->setQuery('SELECT FOUND_ROWS();');
156 $this->total = (int) $dbo->loadResult();
157
158 $this->pagination = new JPagination($this->total, $options['start'], $options['limit']);
159 }
160
161 return $this->pagination;
162 }
163
164 /**
165 * Returns the total number of employees matching the search query.
166 *
167 * @return integer
168 */
169 public function getTotal()
170 {
171 return $this->total;
172 }
173
174 /**
175 * Checks whether the specified customer purchased
176 * at least a package order.
177 *
178 * @param integer $id_user The customer ID.
179 *
180 * @return boolean True in case of packages, false otherwise.
181 */
182 public function hasPackages($id_user)
183 {
184 $dbo = JFactory::getDbo();
185
186 $q = $dbo->getQuery(true)
187 ->select(1)
188 ->from($dbo->qn('#__vikappointments_package_order'))
189 ->where($dbo->qn('id_user') . ' = ' . (int) $id_user);
190
191 $dbo->setQuery($q, 0, 1);
192 return $dbo->loadResult();
193 }
194
195 /**
196 * Checks whether the specified customer purchased
197 * at least a subscription order.
198 *
199 * @param integer $id_user The customer ID.
200 *
201 * @return boolean True in case of subscriptions, false otherwise.
202 */
203 public function hasSubscriptions($id_user)
204 {
205 $dbo = JFactory::getDbo();
206
207 $q = $dbo->getQuery(true)
208 ->select(1)
209 ->from($dbo->qn('#__vikappointments_subscr_order'))
210 ->where($dbo->qn('id_user') . ' = ' . (int) $id_user);
211
212 $dbo->setQuery($q, 0, 1);
213 return $dbo->loadResult();
214 }
215 }
216