PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / availability / timeline / parser.php
vikappointments / site / helpers / libraries / availability / timeline Last commit date
parser 4 days ago renderer 4 days ago block.php 4 days ago factory.php 4 days ago index.html 4 days ago parser.php 4 days ago renderer.php 4 days ago
parser.php
136 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.search');
15 VAPLoader::import('libraries.availability.timeline');
16
17 /**
18 * Timeline parser abstract interface.
19 *
20 * @since 1.7
21 */
22 abstract class VAPAvailabilityTimelineParser extends JObject
23 {
24 /**
25 * The search handler.
26 *
27 * @var VAPAvailabilitySearch
28 */
29 protected $search;
30
31 /**
32 * Class constructor.
33 *
34 * @param VAPAvailabilitySearch $search The search handler.
35 */
36 public function __construct(VAPAvailabilitySearch $search)
37 {
38 $this->search = $search;
39 }
40
41 /**
42 * Calculates the availability timeline for the specified date.
43 * In case of error, it is possible to retrieve a message by
44 * calling the internal getError() method.
45 *
46 * @param string $date The UTC date in military format.
47 * @param integer $people The number of participants.
48 * @param integer $id The selected appointment ID.
49 *
50 * @return mixed The resulting timeline on success, false otherwise.
51 */
52 final public function getTimeline($date, $people = 1, $id = 0)
53 {
54 try
55 {
56 /**
57 * Trigger hook to check whether the availability timeline should be displayed
58 * or not. Useful in example to avoid showing the timeline to guest users.
59 *
60 * Throw an exception to display an error message to the front-end user.
61 *
62 * @param JObject $search The search handler.
63 * @param string $date The UTC date in military format.
64 * @param int $people The number of participants.
65 * @param int $id The selected appointment ID.
66 *
67 * @return bool Return false to prevent the timeline building.
68 *
69 * @throws Exception
70 *
71 * @since 1.7
72 */
73 if (VAPFactory::getEventDispatcher()->false('onBeforeBuildTimeline', [$this->search, $date, $people, $id]))
74 {
75 // do not build the timeline as instructed by a plugin
76 return false;
77 }
78 }
79 catch (Exception $e)
80 {
81 // register error message thrown by the plugin
82 $this->setError($e);
83 return false;
84 }
85
86 // invoke internal method to build the timeline
87 $timeline = $this->buildTimeline($date, $people, $id);
88
89 if ($timeline instanceof VAPAvailabilityTimeline)
90 {
91 try
92 {
93 /**
94 * Fire an event to manipulate the timeline without having to create a new parser.
95 * DO NOT trigger in case the timeline building returned an invalid instance.
96 *
97 * Throw an exception to display an error message to the front-end user.
98 *
99 * @param VAPAvailabilityTimeline $timeline The timeline object.
100 *
101 * @return bool Return false to prevent the timeline building.
102 *
103 * @throws Exception
104 *
105 * @since 1.7.4
106 */
107 if (VAPFactory::getEventDispatcher()->false('onAfterBuildTimeline', [$timeline]))
108 {
109 // do not build the timeline as instructed by a plugin
110 return false;
111 }
112 }
113 catch (Exception $e)
114 {
115 // register error message thrown by the plugin
116 $this->setError($e);
117 return false;
118 }
119 }
120
121 return $timeline;
122 }
123
124 /**
125 * Internal method used by children classes to implement their own logic
126 * to fetch the availability timeline.
127 *
128 * @param string $date The UTC date in military format.
129 * @param integer $people The number of participants.
130 * @param integer $id The selected appointment ID.
131 *
132 * @return mixed The resulting timeline on success, false otherwise.
133 */
134 abstract protected function buildTimeline($date, $people = 1, $id = 0);
135 }
136