PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / models / packorders.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 4 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 4 months ago empwdays.php 2 years ago index.html 4 years ago packages.php 2 years ago packagescart.php 4 years ago packagesconfirm.php 4 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 4 months ago
packorders.php
168 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 packages orders list view model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelPackorders 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 employees 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('o.id'));
81 $q->from($dbo->qn('#__vikappointments_package_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 *
97 * @return void
98 *
99 * @since 1.7
100 */
101 $dispatcher->trigger('onBuildPackagesOrdersQuery', array(&$q, &$options));
102
103 $dbo->setQuery($q, $options['start'], $options['limit']);
104
105 if ($rows = $dbo->loadColumn())
106 {
107 // fetch pagination
108 $this->getPagination($options);
109
110 VAPLoader::import('libraries.order.factory');
111 $tag = JFactory::getLanguage()->getTag();
112
113 foreach ($rows as $id_order)
114 {
115 // get order details
116 $orders[] = VAPOrderFactory::getPackages($id_order, $tag);
117 }
118 }
119
120 /**
121 * Trigger hook to manipulate the query response at runtime. Third party
122 * plugins can alter the resulting list of orders.
123 *
124 * @param array &$orders An array of fetched orders.
125 * @param JModel $model The current model.
126 *
127 * @return void
128 *
129 * @since 1.7
130 */
131 $dispatcher->trigger('onBuildPackagesOrdersData', array(&$orders, $this));
132
133 return $orders;
134 }
135
136 /**
137 * Returns the list pagination.
138 *
139 * @param array $options An array of options.
140 *
141 * @return JPagination
142 */
143 public function getPagination(array $options = array())
144 {
145 if (!$this->pagination)
146 {
147 jimport('joomla.html.pagination');
148 $dbo = JFactory::getDbo();
149 $dbo->setQuery('SELECT FOUND_ROWS();');
150 $this->total = (int) $dbo->loadResult();
151
152 $this->pagination = new JPagination($this->total, $options['start'], $options['limit']);
153 }
154
155 return $this->pagination;
156 }
157
158 /**
159 * Returns the total number of employees matching the search query.
160 *
161 * @return integer
162 */
163 public function getTotal()
164 {
165 return $this->total;
166 }
167 }
168