| @@ -1,0 +1,60 @@ | ||
| 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 | + * Browser notification display-data-builder handler. | |
| 16 | + * | |
| 17 | + * @since 1.15.0 (J) - 1.5.0 (WP) | |
| 18 | + */ | |
| 19 | +final class VBONotificationBuilder extends JObject | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * Proxy for immediately getting the object and bind data. | |
| 23 | + * | |
| 24 | + * @param array|object $data the notification payload data to bind. | |
| 25 | + */ | |
| 26 | + public static function getInstance($data = null) | |
| 27 | + { | |
| 28 | + return new static($data); | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Returns an instance of the appropriate notification displayer object. | |
| 33 | + * | |
| 34 | + * @param string $type optional displayer type to force. | |
| 35 | + * | |
| 36 | + * @return null|object | |
| 37 | + */ | |
| 38 | + public function getDisplayer($type = null) | |
| 39 | + { | |
| 40 | + // get the type of notification | |
| 41 | + $notif_type = !empty($type) ? $type : (string)$this->get('type'); | |
| 42 | + if (empty($notif_type)) { | |
| 43 | + return null; | |
| 44 | + } | |
| 45 | + | |
| 46 | + // compose the notification type class | |
| 47 | + $base_notif_class = 'VBONotificationDisplay'; | |
| 48 | + $type_class = ucwords(str_replace(array('-', '_'), ' ', $notif_type)); | |
| 49 | + $type_class = preg_replace("/[^a-zA-Z0-9]/", '', $type_class); | |
| 50 | + | |
| 51 | + $notif_class_name = $base_notif_class . $type_class; | |
| 52 | + | |
| 53 | + if (!class_exists($notif_class_name)) { | |
| 54 | + return null; | |
| 55 | + } | |
| 56 | + | |
| 57 | + // return an instance of the apposite displayer by re-binding the payload | |
| 58 | + return $notif_class_name::getInstance($this->getProperties()); | |
| 59 | + } | |
| 60 | +} | |