allemployees.php
4 days ago
employee.php
4 days ago
group.php
4 days ago
groupext.php
4 days ago
index.html
4 days ago
service.php
4 days ago
allemployees.php
88 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.availability.timeline.parser'); |
| 15 | |
| 16 | /** |
| 17 | * Timeline parser for all the employees assigned to the requested service. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VAPAvailabilityTimelineParserAllemployees extends VAPAvailabilityTimelineParser |
| 22 | { |
| 23 | /** |
| 24 | * Internal method used by children classes to implement their own logic |
| 25 | * to fetch the availability timeline. |
| 26 | * |
| 27 | * @param string $date The UTC date in military format. |
| 28 | * @param integer $people The number of participants. |
| 29 | * @param integer $id The selected appointment ID. |
| 30 | * |
| 31 | * @return mixed The resulting timeline on success, false otherwise. |
| 32 | */ |
| 33 | protected function buildTimeline($date, $people = 1, $id = 0) |
| 34 | { |
| 35 | $id_service = (int) $this->search->get('id_service'); |
| 36 | |
| 37 | // load all supported employees |
| 38 | $employees = JModelVAP::getInstance('service')->getEmployees($id_service); |
| 39 | |
| 40 | $timelines = array(); |
| 41 | |
| 42 | $error = null; |
| 43 | |
| 44 | // iterate employees |
| 45 | foreach ($employees as $employee) |
| 46 | { |
| 47 | // temporarily set the employee |
| 48 | $this->search->set('id_employee', (int) $employee->id); |
| 49 | |
| 50 | // get proper parser with updated searcher |
| 51 | $parser = VAPAvailabilityTimelineFactory::getParser($this->search); |
| 52 | |
| 53 | // obtain timeline from parent |
| 54 | $timeline = $parser->getTimeline($date, $people, $id); |
| 55 | |
| 56 | if ($timeline) |
| 57 | { |
| 58 | $tmp = new stdClass; |
| 59 | $tmp->id = $employee->id; |
| 60 | $tmp->name = $employee->nickname; |
| 61 | $tmp->timeline = $timeline; |
| 62 | |
| 63 | // register timeline only if existing |
| 64 | $timelines[] = $tmp; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | // get error from parser |
| 69 | $error = $parser->getError(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // reset employee from search |
| 74 | $this->search->set('id_employee', 0); |
| 75 | |
| 76 | // make sure all the times are not in the past |
| 77 | if (!$timelines) |
| 78 | { |
| 79 | // use error returned by the parser |
| 80 | $this->setError($error ? $error : JText::translate('VAPFINDRESNOLONGERAVAILABLE')); |
| 81 | |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | return $timelines; |
| 86 | } |
| 87 | } |
| 88 |