allorders.php
2 years ago
calendarweek.php
1 month ago
cart.php
1 month ago
confirmapp.php
1 month ago
empaccountstat.php
2 years ago
empattachser.php
2 years ago
empcoupons.php
2 years ago
empcustfields.php
2 years ago
empeditcoupon.php
3 years ago
empeditcustfield.php
3 years ago
empeditlocation.php
3 years ago
empeditpay.php
3 years ago
empeditprofile.php
5 months ago
empeditservice.php
3 years ago
empeditwdays.php
3 years ago
emplocations.php
2 years ago
emplocwdays.php
4 years ago
emplogin.php
1 month ago
employeesearch.php
1 month ago
employeeslist.php
1 month ago
empmanres.php
2 years ago
emppaylist.php
2 years ago
empserviceslist.php
2 years ago
empsettingsman.php
4 years ago
empsubscrcart.php
4 years ago
empsubscrhistory.php
2 years ago
empsubscrorder.php
5 months ago
empwdays.php
2 years ago
index.html
4 years ago
packages.php
2 years ago
packagescart.php
4 years ago
packagesconfirm.php
5 months ago
packorders.php
2 years ago
servicesearch.php
2 years ago
serviceslist.php
2 years ago
subscrcart.php
2 years ago
subscrhistory.php
2 years ago
subscrpayment.php
5 months ago
emplocations.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 list view model. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsModelEmplocations extends JModelVAP |
| 22 | { |
| 23 | /** |
| 24 | * Loads a list of locations to be displayed within the |
| 25 | * employees area view. |
| 26 | * |
| 27 | * @param array &$filters An array of filters. |
| 28 | * @param array &$options An array of options, such as the ordering mode. |
| 29 | * |
| 30 | * @return array A list of locations. |
| 31 | */ |
| 32 | public function getItems(array &$filters = array(), array &$options = array()) |
| 33 | { |
| 34 | $auth = VAPEmployeeAuth::getInstance(); |
| 35 | |
| 36 | if (!$auth->isEmployee()) |
| 37 | { |
| 38 | // raise error in case of no employee |
| 39 | throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403); |
| 40 | } |
| 41 | |
| 42 | $dbo = JFactory::getDbo(); |
| 43 | |
| 44 | $rows = array(); |
| 45 | |
| 46 | $q = $dbo->getQuery(true) |
| 47 | ->select('l.*') |
| 48 | ->select($dbo->qn(array('c.country_name', 'c.country_2_code', 's.state_name', 's.state_2_code', 'ci.city_name'))) |
| 49 | ->from($dbo->qn('#__vikappointments_employee_location', 'l')) |
| 50 | ->leftjoin($dbo->qn('#__vikappointments_countries', 'c') . ' ON ' . $dbo->qn('c.id') . ' = ' . $dbo->qn('l.id_country')) |
| 51 | ->leftjoin($dbo->qn('#__vikappointments_states', 's') . ' ON ' . $dbo->qn('s.id') . ' = ' . $dbo->qn('l.id_state')) |
| 52 | ->leftjoin($dbo->qn('#__vikappointments_cities', 'ci') . ' ON ' . $dbo->qn('ci.id') . ' = ' . $dbo->qn('l.id_city')) |
| 53 | ->where(array( |
| 54 | $dbo->qn('id_employee') . ' = ' . $auth->id, |
| 55 | $dbo->qn('id_employee') . ' <= 0', |
| 56 | ), 'OR') |
| 57 | ->order($dbo->qn('id_employee') . ' DESC'); |
| 58 | |
| 59 | $dbo->setQuery($q); |
| 60 | |
| 61 | foreach ($dbo->loadObjectList() as $location) |
| 62 | { |
| 63 | $components = array(); |
| 64 | |
| 65 | // register address first |
| 66 | $components[] = $location->address; |
| 67 | |
| 68 | $block = array(); |
| 69 | |
| 70 | // register ZIP within 2nd block |
| 71 | $block[] = $location->zip; |
| 72 | |
| 73 | // register city within 2nd block |
| 74 | $block[] = $location->city_name; |
| 75 | |
| 76 | // register state/province code within 2nd block |
| 77 | $block[] = $location->state_2_code; |
| 78 | |
| 79 | // register 2nd block |
| 80 | $components[] = implode(' ', array_filter($block)); |
| 81 | |
| 82 | // register country code (2 letters) |
| 83 | $components[] = $location->country_2_code; |
| 84 | |
| 85 | // join string components |
| 86 | $location->text = implode(', ', array_filter($components)); |
| 87 | |
| 88 | $rows[] = $location; |
| 89 | } |
| 90 | |
| 91 | return $rows; |
| 92 | } |
| 93 | } |
| 94 |