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
empeditlocation.php
102 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 location management model. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsModelEmpeditlocation 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 | JFactory::getApplication()->setUserState('vap.emparea.location.data', $data); |
| 37 | |
| 38 | // get location model |
| 39 | $locationModel = JModelVAP::getInstance('location'); |
| 40 | |
| 41 | // automatically assign to this employee |
| 42 | $data['id_employee'] = $auth->id; |
| 43 | |
| 44 | // delegate save to location model |
| 45 | $id = $locationModel->save($data); |
| 46 | |
| 47 | if (!$id) |
| 48 | { |
| 49 | // obtain error from model |
| 50 | $error = $locationModel->getError(); |
| 51 | |
| 52 | if ($error) |
| 53 | { |
| 54 | // propagate error |
| 55 | $this->setError($error); |
| 56 | } |
| 57 | |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | return $id; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Extend delete implementation to delete any related records |
| 66 | * stored within a separated table. |
| 67 | * |
| 68 | * @param mixed $ids Either the record ID or a list of records. |
| 69 | * |
| 70 | * @return boolean True on success, false otherwise. |
| 71 | */ |
| 72 | public function delete($ids) |
| 73 | { |
| 74 | $auth = VAPEmployeeAuth::getInstance(); |
| 75 | |
| 76 | if (!$auth->isEmployee()) |
| 77 | { |
| 78 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403); |
| 79 | } |
| 80 | |
| 81 | $result = false; |
| 82 | |
| 83 | // only int values are accepted |
| 84 | $ids = array_map('intval', (array) $ids); |
| 85 | |
| 86 | // get rid of those records that do not belong to this employee |
| 87 | $ids = array_values(array_filter($ids, function($id) use ($auth) |
| 88 | { |
| 89 | // make sure the employee can manage this record |
| 90 | return $auth->manageLocations($id); |
| 91 | })); |
| 92 | |
| 93 | if (!$ids) |
| 94 | { |
| 95 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403); |
| 96 | } |
| 97 | |
| 98 | // delegate delete to location model |
| 99 | return JModelVAP::getInstance('location')->delete($ids); |
| 100 | } |
| 101 | } |
| 102 |