PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.4
VikBooking Hotel Booking Engine & PMS v1.6.4
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / helpers / src / notification / adapter.php

adapter.php in VikBooking Hotel Booking Engine & PMS 1.6.4, at admin/helpers/src/notification/adapter.php

151 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author Alessio Gaggii - E4J s.r.l.
6 * @copyright Copyright (C) 2022 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 * Defines an abstract adapter to extend the browser notification data model.
16 *
17 * @since 1.15.0 (J) - 1.5.0 (WP)
18 */
19 abstract class VBONotificationAdapter extends JObject implements VBONotificationData
20 {
21 /**
22 * The type of the scheduled notification.
23 *
24 * @var string
25 */
26 protected $_notification_type = '';
27
28 /**
29 * The default admin endpoint for displaying (building) a notification. Those notification
30 * types that must be built through AJAX will have to convert this relative URL to an AJAX URL.
31 *
32 * @var string
33 */
34 protected $_notif_display_url = 'index.php?option=com_vikbooking&task=notification_displayer';
35
36 /**
37 * Proxy to immediately access the object.
38 *
39 * @param object|array $data optional data to bind.
40 *
41 * @return self
42 */
43 public static function getInstance($data = [])
44 {
45 return new static($data);
46 }
47
48 /**
49 * Gets the type of notification.
50 *
51 * @return string
52 */
53 public function getType()
54 {
55 return $this->_notification_type;
56 }
57
58 /**
59 * Gets the notification expiration date time.
60 *
61 * @return string "now" by default for no scheduling.
62 */
63 public function getDateTime()
64 {
65 return (string)$this->get('_date_time', 'now');
66 }
67
68 /**
69 * Sets the notification expiration date time.
70 *
71 * @param string|DateTime $dtime
72 *
73 * @return self
74 */
75 public function setDateTime($dtime)
76 {
77 if ($dtime instanceof DateTime) {
78 $dtime = $dtime->format('Y-m-d H:i:s');
79 }
80 // this sets a "reserved" property starting with "_"
81 $this->set('_date_time', $dtime);
82
83 return $this;
84 }
85
86 /**
87 * Accesses the flag to declare a date as with no time.
88 *
89 * @return bool true if time is disabled.
90 */
91 public function getNoTime()
92 {
93 return (bool)$this->set('_no_time', false);
94 }
95
96 /**
97 * Controls the flag to declare a date as with no time.
98 *
99 * @param bool $set true to disable time.
100 *
101 * @return self
102 */
103 public function setNoTime($set = true)
104 {
105 // this sets a "reserved" property starting with "_"
106 $this->set('_no_time', (bool)$set);
107
108 return $this;
109 }
110
111 /**
112 * Returns the notification data object to be encoded.
113 *
114 * @return object the notification data object for the document.
115 */
116 public function toDataObject()
117 {
118 // access all "public" (not reserved) properties
119 $props = $this->getProperties($public = true);
120
121 // build data object
122 $data = (object)$props;
123 $data->type = $this->getType();
124 $data->dtime = $this->getDateTime();
125 if ($this->getNoTime()) {
126 $data->no_time = 1;
127 }
128 $data->build_url = $this->generateBuildUrl();
129
130 return $data;
131 }
132
133 /**
134 * Extending classes can override this method when a notification does
135 * NOT require scheduling or building, but rather instant display data.
136 *
137 * @return bool true if display data were built.
138 */
139 public function buildDisplayData()
140 {
141 return false;
142 }
143
144 /**
145 * Returns the URL to build the notification display data.
146 *
147 * @return null|string the url to build the notification display data.
148 */
149 abstract protected function generateBuildUrl();
150 }
151