| 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 |
* Builds a browser notification data object for a history event. |
| 16 |
* |
| 17 |
* @since 1.15.0 (J) - 1.5.0 (WP) |
| 18 |
*/ |
| 19 |
final class VBONotificationDataHistory extends VBONotificationAdapter |
| 20 |
{ |
| 21 |
/** |
| 22 |
* The type of the scheduled notification. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
protected $_notification_type = 'history'; |
| 27 |
|
| 28 |
/** |
| 29 |
* Public method to be called after setting the history |
| 30 |
* record data properties as "reserved" (starting with "_"). |
| 31 |
* Needed to set "public" properties for the notification |
| 32 |
* data object to serve as display data for instant dispatch. |
| 33 |
* |
| 34 |
* @return bool true if display data were built. |
| 35 |
*/ |
| 36 |
public function buildDisplayData() |
| 37 |
{ |
| 38 |
// make sure the booking id is set |
| 39 |
$booking_id = $this->get('_idorder'); |
| 40 |
if (empty($booking_id)) { |
| 41 |
$booking_id = $this->get('idorder'); |
| 42 |
} |
| 43 |
if (empty($booking_id)) { |
| 44 |
// useless to proceed if no reservation ID set |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
// access any kind of object-property set |
| 49 |
$props = $this->getProperties($public = false); |
| 50 |
|
| 51 |
// convert "reserved" keys into "public" ones |
| 52 |
foreach ($props as $prop => $val) { |
| 53 |
if ('_' == substr($prop, 0, 1)) { |
| 54 |
$props[substr($prop, 1)] = $val; |
| 55 |
unset($props[$prop]); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// get the notification displayer for "history" |
| 60 |
$displayer = VBONotificationBuilder::getInstance($props)->getDisplayer($this->_notification_type); |
| 61 |
if (!$displayer) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
|
| 65 |
// build notification display data |
| 66 |
try { |
| 67 |
$display_data = $displayer->getData(); |
| 68 |
if (!$display_data) { |
| 69 |
throw new Exception('Error building the notification display data', 500); |
| 70 |
} |
| 71 |
} catch (Exception $e) { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
// set display data "public" properties |
| 76 |
foreach ($display_data as $prop_name => $prop_val) { |
| 77 |
$this->set($prop_name, $prop_val); |
| 78 |
} |
| 79 |
|
| 80 |
return true; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* This kind of notification will be returned inclusive of |
| 85 |
* display data for dispatching. It won't need to be built. |
| 86 |
* |
| 87 |
* @return null always null for never building this notification. |
| 88 |
*/ |
| 89 |
protected function generateBuildUrl() |
| 90 |
{ |
| 91 |
return null; |
| 92 |
} |
| 93 |
} |
| 94 |
|