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 / empeditpay.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
empeditpay.php
189 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 payment management model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelEmpeditpay extends JModelVAP
22 {
23 /**
24 * Basic save implementation.
25 *
26 * @param mixed $data Either an array or an object of data to save.
27 *
28 * @return mixed The ID of the record on success, false otherwise.
29 */
30 public function save($data)
31 {
32 $data = (array) $data;
33
34 $auth = VAPEmployeeAuth::getInstance();
35
36 // get payment model
37 $paymentModel = JModelVAP::getInstance('payment');
38
39 if (isset($data['icon']))
40 {
41 // set font icon type in case an icon was selected
42 $data['icontype'] = $data['icon'] ? 1 : 0;
43 }
44
45 // force author and owner
46 $data['createdby'] = JFactory::getUser()->id;
47 $data['id_employee'] = $auth->id;
48
49 // Check whether the file has been specified or not, which would mean that
50 // we are trying to edit the payment of an employee without being the author.
51 // This way we can prevent the update of the driver and its parameters.
52 if (!empty($data['file']))
53 {
54 $input = JFactory::getApplication()->input;
55
56 try
57 {
58 // get payment configuration
59 $config = VAPApplication::getInstance()->getPaymentConfig($data['file']);
60
61 $data['params'] = array();
62
63 // load configuration from request
64 foreach ($config as $k => $p)
65 {
66 $data['params'][$k] = $input->get('gp_' . $k, '', 'string');
67 }
68 }
69 catch (Exception $e)
70 {
71 // unset file to raise error before saving the payment
72 $data['file'] = false;
73 }
74 }
75
76 JFactory::getApplication()->setUserState('vap.emparea.payment.data', $data);
77
78 // delegate save to payment model
79 $id = $paymentModel->save($data);
80
81 if (!$id)
82 {
83 // obtain error from model
84 $error = $paymentModel->getError();
85
86 if ($error)
87 {
88 // propagate error
89 $this->setError($error);
90 }
91
92 return false;
93 }
94
95 return $id;
96 }
97
98 /**
99 * Extend delete implementation to delete any related records
100 * stored within a separated table.
101 *
102 * @param mixed $ids Either the record ID or a list of records.
103 *
104 * @return boolean True on success, false otherwise.
105 */
106 public function delete($ids)
107 {
108 $auth = VAPEmployeeAuth::getInstance();
109
110 if (!$auth->isEmployee())
111 {
112 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
113 }
114
115 $result = false;
116
117 // only int values are accepted
118 $ids = array_map('intval', (array) $ids);
119
120 // get rid of those records that do not belong to this employee
121 $ids = array_values(array_filter($ids, function($id) use ($auth)
122 {
123 // make sure the employee can manage this record
124 return $auth->managePayments($id);
125 }));
126
127 if (!$ids)
128 {
129 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
130 }
131
132 // delegate delete to payment model
133 return JModelVAP::getInstance('payment')->delete($ids);
134 }
135
136 /**
137 * Basic publish/unpublish implementation.
138 *
139 * @param mixed $ids Either the record ID or a list of records.
140 * @param integer $state The publishing status.
141 *
142 * @return boolean True on success, false otherwise.
143 */
144 public function publish($ids, $state = 1, $alias = null)
145 {
146 $auth = VAPEmployeeAuth::getInstance();
147
148 if (!$auth->isEmployee())
149 {
150 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
151 }
152
153 // only int values are accepted
154 $ids = array_map('intval', (array) $ids);
155
156 // get rid of those records that do not belong to this employee
157 $ids = array_values(array_filter($ids, function($id) use ($auth)
158 {
159 // make sure the employee can manage this record
160 return $auth->managePayments($id);
161 }));
162
163 if (!$ids)
164 {
165 // there's noting to publish/unpublish
166 return false;
167 }
168
169 // delegate publish to payment model
170 return JModelVAP::getInstance('payment')->publish($ids, $state, $alias);
171 }
172
173 /**
174 * Method to get a table object.
175 *
176 * @param string $name The table name.
177 * @param string $prefix The class prefix.
178 * @param array $options Configuration array for table.
179 *
180 * @return JTable A table object.
181 *
182 * @throws Exception
183 */
184 public function getTable($name = 'payment', $prefix = '', $options = array())
185 {
186 return parent::getTable($name, $prefix, $options);
187 }
188 }
189