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 / empeditcustfield.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
empeditcustfield.php
185 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 custom fields management model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelEmpeditcustfield 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 // always force the group to "shop"
35 $data['group'] = 0;
36
37 $auth = VAPEmployeeAuth::getInstance();
38
39 JFactory::getApplication()->setUserState('vap.emparea.field.data', $data);
40
41 // get field model
42 $fieldModel = JModelVAP::getInstance('customf');
43
44 if (@$data['type'] == 'file' && isset($data['choose']))
45 {
46 // get media model to validate file types
47 $media = JModelVAP::getInstance('media');
48
49 // convert extensions string into an array
50 $data['choose'] = preg_split("/\s*,\s*/", $data['choose']);
51
52 // validate specified extensions against supported media types
53 $data['choose'] = array_filter($data['choose'], function($type) use ($media)
54 {
55 // make sure the file type is allowed
56 return $type && $media->detectMediaType($type);
57 });
58
59 if (empty($data['choose']))
60 {
61 // use default allowed extensions
62 $data['choose'] = 'png, jpg, jpeg, pdf';
63 }
64 else
65 {
66 // merge valid types again
67 $data['choose'] = implode(', ', $data['choose']);
68 }
69 }
70
71 // auto assign to this employee
72 $data['id_employee'] = $auth->id;
73
74 // delegate save to field model
75 $id = $fieldModel->save($data);
76
77 if (!$id)
78 {
79 // obtain error from model
80 $error = $fieldModel->getError();
81
82 if ($error)
83 {
84 // propagate error
85 $this->setError($error);
86 }
87
88 return false;
89 }
90
91 return $id;
92 }
93
94 /**
95 * Extend delete implementation to delete any related records
96 * stored within a separated table.
97 *
98 * @param mixed $ids Either the record ID or a list of records.
99 *
100 * @return boolean True on success, false otherwise.
101 */
102 public function delete($ids)
103 {
104 $auth = VAPEmployeeAuth::getInstance();
105
106 if (!$auth->isEmployee())
107 {
108 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
109 }
110
111 $result = false;
112
113 // only int values are accepted
114 $ids = array_map('intval', (array) $ids);
115
116 // get rid of those records that do not belong to this employee
117 $ids = array_values(array_filter($ids, function($id) use ($auth)
118 {
119 // make sure the employee can manage this record
120 return $auth->manageCustomFields($id);
121 }));
122
123 if (!$ids)
124 {
125 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
126 }
127
128 // delegate delete to field model
129 return JModelVAP::getInstance('customf')->delete($ids);
130 }
131
132 /**
133 * Basic publish/unpublish implementation.
134 *
135 * @param mixed $ids Either the record ID or a list of records.
136 * @param integer $state The publishing status.
137 *
138 * @return boolean True on success, false otherwise.
139 */
140 public function publish($ids, $state = 1, $alias = null)
141 {
142 $auth = VAPEmployeeAuth::getInstance();
143
144 if (!$auth->isEmployee())
145 {
146 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
147 }
148
149 // only int values are accepted
150 $ids = array_map('intval', (array) $ids);
151
152 // get rid of those records that do not belong to this employee
153 $ids = array_values(array_filter($ids, function($id) use ($auth)
154 {
155 // make sure the employee can manage this record
156 return $auth->manageCustomFields($id);
157 }));
158
159 if (!$ids)
160 {
161 // there's noting to publish/unpublish
162 return false;
163 }
164
165 // delegate publish to field model
166 return JModelVAP::getInstance('customf')->publish($ids, $state, $alias);
167 }
168
169 /**
170 * Method to get a table object.
171 *
172 * @param string $name The table name.
173 * @param string $prefix The class prefix.
174 * @param array $options Configuration array for table.
175 *
176 * @return JTable A table object.
177 *
178 * @throws Exception
179 */
180 public function getTable($name = 'customf', $prefix = '', $options = array())
181 {
182 return parent::getTable($name, $prefix, $options);
183 }
184 }
185