PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / models / emplocwdays.php
vikappointments / site / models Last commit date
allorders.php 1 month ago calendarweek.php 1 month ago cart.php 1 month ago confirmapp.php 1 month ago empaccountstat.php 1 month ago empattachser.php 1 month ago empcoupons.php 1 month ago empcustfields.php 1 month ago empeditcoupon.php 1 month ago empeditcustfield.php 1 month ago empeditlocation.php 1 month ago empeditpay.php 1 month ago empeditprofile.php 1 month ago empeditservice.php 1 month ago empeditwdays.php 1 month ago emplocations.php 1 month ago emplocwdays.php 1 month ago emplogin.php 1 month ago employeesearch.php 1 month ago employeeslist.php 1 month ago empmanres.php 1 month ago emppaylist.php 1 month ago empserviceslist.php 1 month ago empsettingsman.php 1 month ago empsubscrcart.php 1 month ago empsubscrhistory.php 1 month ago empsubscrorder.php 1 month ago empwdays.php 1 month ago index.html 1 month ago packages.php 1 month ago packagescart.php 1 month ago packagesconfirm.php 1 month ago packorders.php 1 month ago servicesearch.php 1 month ago serviceslist.php 1 month ago subscrcart.php 1 month ago subscrhistory.php 1 month ago subscrpayment.php 1 month ago
emplocwdays.php
94 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 locations-working days assignment model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelEmplocwdays 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 $auth = VAPEmployeeAuth::getInstance();
33
34 // extract locations lookup
35 $locations = isset($data['locations']) ? (array) $data['locations'] : array();
36
37 // get working times model
38 $model = JModelVAP::getInstance('worktime');
39
40 $aclLookup = array();
41
42 $result = false;
43
44 foreach ($locations as $id_worktime => $id_location)
45 {
46 if (!isset($aclLookup[$id_location]))
47 {
48 // check whether the location can be used by the employee
49 $aclLookup[$id_location] = $auth->manageLocations($id_location, $readOnly = true);
50 }
51
52 if (!$aclLookup[$id_location])
53 {
54 // cannot use the specified location
55 $this->setError(JText::translate('JERROR_ALERTNOAUTHOR'));
56 continue;
57 }
58
59 // also make sure that the employee is the owner of the working day
60 if (!$auth->manageWorkDays($id_worktime))
61 {
62 // not the owner
63 $this->setError(JText::translate('JERROR_ALERTNOAUTHOR'));
64 continue;
65 }
66
67 // create relation array
68 $assoc = array(
69 'id' => (int) $id_worktime,
70 'id_location' => (int) $id_location,
71 // the employee ID is needed to trigger the update for
72 // all the children working days
73 'id_employee' => $auth->id,
74 );
75
76 // delegate model to perform saving process
77 if ($model->save($assoc))
78 {
79 $result = true;
80 }
81 else
82 {
83 if ($error = $model->getError())
84 {
85 // propagate registered error message
86 $this->setError($error);
87 }
88 }
89 }
90
91 return $result;
92 }
93 }
94