timeline
3 days ago
implementor.php
3 days ago
index.html
3 days ago
manager.php
3 days ago
search.php
3 days ago
timeline.php
3 days ago
search.php
187 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 | /** |
| 15 | * Availability search abstract interface. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | abstract class VAPAvailabilitySearch extends JObject |
| 20 | { |
| 21 | /** |
| 22 | * Class constructor. |
| 23 | * |
| 24 | * @param integer $id_ser The service ID. |
| 25 | * @param integer $id_emp The employee ID (optional). |
| 26 | * @param array $options An array of options. |
| 27 | */ |
| 28 | public function __construct($id_ser, $id_emp = null, array $options = array()) |
| 29 | { |
| 30 | // construct with given options |
| 31 | parent::__construct($options); |
| 32 | |
| 33 | // manually set the specified service and employee |
| 34 | $this->set('id_service', (int) $id_ser); |
| 35 | $this->set('id_employee', (int) $id_emp); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Checks whether the availability is fetched by an administrator. |
| 40 | * |
| 41 | * @return boolean True in case of admin, false otherwise. |
| 42 | */ |
| 43 | public function isAdmin() |
| 44 | { |
| 45 | return (bool) $this->get('admin', false); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Checks whether there's at least an employee offering the |
| 50 | * requested service for the given day. In case an employee |
| 51 | * has been specified while constructing this object, then |
| 52 | * the availability will be restricted to the latter. |
| 53 | * |
| 54 | * @param string $date The UTC date in military format. |
| 55 | * |
| 56 | * @return boolean True if open, false otherwise. |
| 57 | */ |
| 58 | public function isDayOpen($date) |
| 59 | { |
| 60 | // look for a closing day/period |
| 61 | if ($this->isClosingDay($date)) |
| 62 | { |
| 63 | // the day is closed |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | // check whether the service is published for the given date |
| 68 | if (!$this->isServicePublished($date)) |
| 69 | { |
| 70 | // service not published |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | // check whether there's at least a working day |
| 75 | return $this->hasWorkingDay($date); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Approximative check to determine whether the specified day |
| 80 | * is available or not by returning the related availability |
| 81 | * status (0: full, 1: fully available, 2: partially available). |
| 82 | * |
| 83 | * @param string $date The UTC date in military format. |
| 84 | * |
| 85 | * @return integer The availability status. |
| 86 | */ |
| 87 | abstract public function isDayAvailable($date); |
| 88 | |
| 89 | /** |
| 90 | * Returns the employee working times for the given day. |
| 91 | * In case of 24h working days, the system will extend the ending |
| 92 | * time of the last working day in order to support midnight appointments. |
| 93 | * |
| 94 | * @param string $date The UTC date in military format. |
| 95 | * |
| 96 | * @return array A list containing the matching working days. |
| 97 | */ |
| 98 | abstract public function getWorkingTimes($date); |
| 99 | |
| 100 | /** |
| 101 | * Returns a list of appointments that stays between 2 dates. |
| 102 | * This method returns only the appointments that might alter |
| 103 | * the availability of the registered service/employee. |
| 104 | * |
| 105 | * @param string $date The UTC start date in military format. |
| 106 | * @param mixed $end The UTC end date in military format. Leave empty to |
| 107 | * auto-set the end date at midnight of start date. |
| 108 | * @param integer $id The selected appointment ID, which will be excluded. |
| 109 | * |
| 110 | * @return array A list of appointments. |
| 111 | */ |
| 112 | abstract public function getReservations($date, $end = null, $id = 0); |
| 113 | |
| 114 | /** |
| 115 | * Checks whether there's at least an open working time on the given |
| 116 | * day for the specified service-employee relation. |
| 117 | * |
| 118 | * @param string $date The UTC date in military format. |
| 119 | * |
| 120 | * @return boolean True if available, false if missing or closed. |
| 121 | */ |
| 122 | abstract public function hasWorkingDay($date); |
| 123 | |
| 124 | /** |
| 125 | * Checks whether the specified employee is able to host an appointment at |
| 126 | * the specified date and for the given duration. |
| 127 | * |
| 128 | * This method should simply check the intersection between this search and |
| 129 | * the existing appointments. It is assumed that the seleceted check-in is |
| 130 | * already supported by the employee. |
| 131 | * |
| 132 | * @param string $date The UTC start date in military format. |
| 133 | * @param mixed $duration The appointment duration. |
| 134 | * @param integer $people The number of participants. |
| 135 | * @param integer $id The selected appointment ID, which will be excluded. |
| 136 | * |
| 137 | * @return boolean True if available, false otherwise. |
| 138 | */ |
| 139 | abstract public function isEmployeeAvailable($date, $duration = null, $people = 1, $id = 0); |
| 140 | |
| 141 | /** |
| 142 | * Checks whether the specified service is able to host an appointment at |
| 143 | * the specified date and for the given duration. |
| 144 | * |
| 145 | * This method should simply check the intersection between this search and |
| 146 | * the existing appointments. The system will iterate all the employees |
| 147 | * assigned to the selected service to find the first one available. |
| 148 | * |
| 149 | * @param string $date The UTC start date in military format. |
| 150 | * @param mixed $duration The appointment duration. |
| 151 | * @param integer $people The number of participants. |
| 152 | * @param integer $id The selected appointment ID, which will be excluded. |
| 153 | * |
| 154 | * @return mixed The ID of the available employee, false otherwise. |
| 155 | */ |
| 156 | abstract public function isServiceAvailable($date, $duration = null, $people = 1, $id = 0); |
| 157 | |
| 158 | /** |
| 159 | * Checks whether there's a closing day/period on the given |
| 160 | * day and for the specified service. |
| 161 | * |
| 162 | * @param string $date The UTC date in military format. |
| 163 | * |
| 164 | * @return boolean True if closed, false otherwise. |
| 165 | */ |
| 166 | abstract public function isClosingDay($date); |
| 167 | |
| 168 | /** |
| 169 | * Checks whether the service is published on the given date. |
| 170 | * |
| 171 | * @param string $date The UTC date in military format. |
| 172 | * |
| 173 | * @return boolean True if closed, false otherwise. |
| 174 | */ |
| 175 | abstract public function isServicePublished($date); |
| 176 | |
| 177 | /** |
| 178 | * Checks if the specified date is in the past or doesn't follow the |
| 179 | * booking minutes restriction of the service. |
| 180 | * |
| 181 | * @param string $datetime The check-in date time (military format). |
| 182 | * |
| 183 | * @return boolean True if in the past, false otherwise. |
| 184 | */ |
| 185 | abstract public function isPastTime($datetime); |
| 186 | } |
| 187 |