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 / empwdays.php
vikappointments / site / models Last commit date
allorders.php 1 day ago calendarweek.php 1 day ago cart.php 1 day ago confirmapp.php 1 day ago empaccountstat.php 1 day ago empattachser.php 1 day ago empcoupons.php 1 day ago empcustfields.php 1 day ago empeditcoupon.php 1 day ago empeditcustfield.php 1 day ago empeditlocation.php 1 day ago empeditpay.php 1 day ago empeditprofile.php 1 day ago empeditservice.php 1 day ago empeditwdays.php 1 day ago emplocations.php 1 day ago emplocwdays.php 1 day ago emplogin.php 1 day ago employeesearch.php 1 day ago employeeslist.php 1 day ago empmanres.php 1 day ago emppaylist.php 1 day ago empserviceslist.php 1 day ago empsettingsman.php 1 day ago empsubscrcart.php 1 day ago empsubscrhistory.php 1 day ago empsubscrorder.php 1 day ago empwdays.php 1 day ago index.html 1 day ago packages.php 1 day ago packagescart.php 1 day ago packagesconfirm.php 1 day ago packorders.php 1 day ago servicesearch.php 1 day ago serviceslist.php 1 day ago subscrcart.php 1 day ago subscrhistory.php 1 day ago subscrpayment.php 1 day ago
empwdays.php
161 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 employee area working days view model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelEmpwdays 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 working days to be displayed within the
39 * employees area view.
40 *
41 * @param array &$filters An array of filters.
42 * @param array &$options An array of options, such as the ordering mode.
43 *
44 * @return array A list of working days.
45 */
46 public function getItems(array &$filters = array(), array &$options = array())
47 {
48 // always reset pagination and total count
49 $this->pagination = null;
50 $this->total = 0;
51
52 $auth = VAPEmployeeAuth::getInstance();
53
54 if (!$auth->isEmployee())
55 {
56 // raise error in case of no employee
57 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
58 }
59
60 $dbo = JFactory::getDbo();
61
62 $rows = array();
63
64 $q = $dbo->getQuery(true)
65 ->select('SQL_CALC_FOUND_ROWS w.*')
66 ->select($dbo->qn(array('l.name', 'l.address', 'l.zip')))
67 ->from($dbo->qn('#__vikappointments_emp_worktime', 'w'))
68 ->leftjoin($dbo->qn('#__vikappointments_employee_location', 'l') . ' ON ' . $dbo->qn('l.id') . ' = ' . $dbo->qn('w.id_location'))
69 ->where($dbo->qn('w.id_employee') . ' = ' . $auth->id)
70 ->order(array(
71 $dbo->qn('w.ts') . ' ASC',
72 $dbo->qn('w.day') . ' ASC',
73 $dbo->qn('w.fromts') . ' ASC',
74 $dbo->qn('w.closed') . ' DESC',
75 ));
76
77 if (isset($filters['service']) && (int) $filters['service'] > 0)
78 {
79 // take the working days assigned to the specified service
80 $q->where($dbo->qn('w.id_service') . ' = ' . (int) $filters['service']);
81 }
82 else
83 {
84 // take the global working days
85 $q->where($dbo->qn('w.id_service') . ' <= 0');
86 }
87
88 if (isset($filters['closed']))
89 {
90 // include/exclude closures
91 $q->where($dbo->qn('w.closed') . ' = ' . (int) $filters['closed']);
92 }
93
94 $dbo->setQuery($q, $options['start'], $options['limit']);
95 $rows = $dbo->loadObjectList();
96
97 if ($rows)
98 {
99 // fetch pagination
100 $this->getPagination($filters, $options);
101 }
102
103 $rows = array_map(function($w)
104 {
105 $w->location = '';
106
107 if (!empty($w->address))
108 {
109 $w->location = "{$w->name} ({$w->address}, {$w->zip})";
110 }
111
112 return $w;
113 }, $rows);
114
115 return $rows;
116 }
117
118 /**
119 * Returns the list pagination.
120 *
121 * @param array $filters An array of filters.
122 * @param array $options An array of options.
123 *
124 * @return JPagination
125 */
126 public function getPagination(array $filters = array(), array $options = array())
127 {
128 if (!$this->pagination)
129 {
130 jimport('joomla.html.pagination');
131 $dbo = JFactory::getDbo();
132 $dbo->setQuery('SELECT FOUND_ROWS();');
133 $this->total = (int) $dbo->loadResult();
134
135 $this->pagination = new JPagination($this->total, $options['start'], $options['limit']);
136
137 foreach ($filters as $k => $v)
138 {
139 // append only filters that own a value as it doesn't
140 // make sense to populate the URL using empty variables
141 if ($v)
142 {
143 $this->pagination->setAdditionalUrlParam($k, $v);
144 }
145 }
146 }
147
148 return $this->pagination;
149 }
150
151 /**
152 * Returns the total number of employees matching the search query.
153 *
154 * @return integer
155 */
156 public function getTotal()
157 {
158 return $this->total;
159 }
160 }
161