PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / models / subscrhistory.php
vikappointments / site / models Last commit date
allorders.php 3 days ago calendarweek.php 3 days ago cart.php 3 days ago confirmapp.php 3 days ago empaccountstat.php 3 days ago empattachser.php 3 days ago empcoupons.php 3 days ago empcustfields.php 3 days ago empeditcoupon.php 3 days ago empeditcustfield.php 3 days ago empeditlocation.php 3 days ago empeditpay.php 3 days ago empeditprofile.php 3 days ago empeditservice.php 3 days ago empeditwdays.php 3 days ago emplocations.php 3 days ago emplocwdays.php 3 days ago emplogin.php 3 days ago employeesearch.php 3 days ago employeeslist.php 3 days ago empmanres.php 3 days ago emppaylist.php 3 days ago empserviceslist.php 3 days ago empsettingsman.php 3 days ago empsubscrcart.php 3 days ago empsubscrhistory.php 3 days ago empsubscrorder.php 3 days ago empwdays.php 3 days ago index.html 3 days ago packages.php 3 days ago packagescart.php 3 days ago packagesconfirm.php 3 days ago packorders.php 3 days ago servicesearch.php 3 days ago serviceslist.php 3 days ago subscrcart.php 3 days ago subscrhistory.php 3 days ago subscrpayment.php 3 days ago
subscrhistory.php
169 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 subscriptions orders list view model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelSubscrhistory 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 orders to be displayed within the subscriptions
39 * history 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('o.id'));
81 $q->from($dbo->qn('#__vikappointments_subscr_order', 'o'));
82 $q->leftjoin($dbo->qn('#__vikappointments_users', 'u') . ' ON ' . $dbo->qn('o.id_user') . ' = ' . $dbo->qn('u.id'));
83
84 // filter orders by user
85 $q->where($dbo->qn('u.jid') . ' = ' . (int) $user->id);
86
87 $q->order($dbo->qn('o.id') . ' DESC');
88
89 /**
90 * Trigger hook to manipulate the query at runtime. Third party plugins
91 * can extend the query by applying further conditions or selecting
92 * additional data.
93 *
94 * @param mixed &$query Either a query builder or a query string.
95 * @param array &$options An array of options.
96 * @param string $group The group alias (customer).
97 *
98 * @return void
99 *
100 * @since 1.7
101 */
102 $dispatcher->trigger('onBuildSubscriptionOrdersQuery', array(&$q, &$options, 'customer'));
103
104 $dbo->setQuery($q, $options['start'], $options['limit']);
105
106 if ($rows = $dbo->loadColumn())
107 {
108 // fetch pagination
109 $this->getPagination($options);
110
111 VAPLoader::import('libraries.order.factory');
112 $tag = JFactory::getLanguage()->getTag();
113
114 foreach ($rows as $id_order)
115 {
116 // get order details
117 $orders[] = VAPOrderFactory::getCustomerSubscription($id_order, $tag);
118 }
119 }
120
121 /**
122 * Trigger hook to manipulate the query response at runtime. Third party
123 * plugins can alter the resulting list of orders.
124 *
125 * @param array &$orders An array of fetched orders.
126 * @param JModel $model The current model.
127 *
128 * @return void
129 *
130 * @since 1.7
131 */
132 $dispatcher->trigger('onBuildSubscriptionOrdersData', array(&$orders, $this));
133
134 return $orders;
135 }
136
137 /**
138 * Returns the list pagination.
139 *
140 * @param array $options An array of options.
141 *
142 * @return JPagination
143 */
144 public function getPagination(array $options = array())
145 {
146 if (!$this->pagination)
147 {
148 jimport('joomla.html.pagination');
149 $dbo = JFactory::getDbo();
150 $dbo->setQuery('SELECT FOUND_ROWS();');
151 $this->total = (int) $dbo->loadResult();
152
153 $this->pagination = new JPagination($this->total, $options['start'], $options['limit']);
154 }
155
156 return $this->pagination;
157 }
158
159 /**
160 * Returns the total number of employees matching the search query.
161 *
162 * @return integer
163 */
164 public function getTotal()
165 {
166 return $this->total;
167 }
168 }
169