allorders.php
2 days ago
calendarweek.php
2 days ago
cart.php
2 days ago
confirmapp.php
2 days ago
empaccountstat.php
2 days ago
empattachser.php
2 days ago
empcoupons.php
2 days ago
empcustfields.php
2 days ago
empeditcoupon.php
2 days ago
empeditcustfield.php
2 days ago
empeditlocation.php
2 days ago
empeditpay.php
2 days ago
empeditprofile.php
2 days ago
empeditservice.php
2 days ago
empeditwdays.php
2 days ago
emplocations.php
2 days ago
emplocwdays.php
2 days ago
emplogin.php
2 days ago
employeesearch.php
2 days ago
employeeslist.php
2 days ago
empmanres.php
2 days ago
emppaylist.php
2 days ago
empserviceslist.php
2 days ago
empsettingsman.php
2 days ago
empsubscrcart.php
2 days ago
empsubscrhistory.php
2 days ago
empsubscrorder.php
2 days ago
empwdays.php
2 days ago
index.html
2 days ago
packages.php
2 days ago
packagescart.php
2 days ago
packagesconfirm.php
2 days ago
packorders.php
2 days ago
servicesearch.php
2 days ago
serviceslist.php
2 days ago
subscrcart.php
2 days ago
subscrhistory.php
2 days ago
subscrpayment.php
2 days 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 |