idorder; ?>
format('D, d M Y H:i', true); ?>
days . ' ' . $nights_lbl; ?>
validType($history->type, true); ?>
widgetName = JText::translate('VBO_W_LATESTEVS_TITLE'); $this->widgetDescr = JText::translate('VBO_W_LATESTEVS_DESCR'); $this->widgetId = basename(__FILE__, '.php'); // define widget and icon and style name $this->widgetIcon = ''; $this->widgetStyleName = 'blue'; // load widget's settings $this->widgetSettings = $this->loadSettings(); $this->widgetSettings = !is_array($this->widgetSettings) ? [] : $this->widgetSettings; } /** * This widget returns the latest history record ID to schedule * periodic watch data in order to be able to trigger notifications. * No CSS/JS assets are needed during preloading. * * @return void|object */ public function preload() { // lang vars for JS JText::script('VBOBOOKHISTORYLBLTYPE'); JText::script('VBANYTHING'); JText::script('VBO_HISTORY_GROUPS'); // use the history class to get the latest event id $history_obj = VikBooking::getBookingHistoryInstance(); $events = $history_obj->getLatestBookingEvents(0, 1); if ($events) { $watch_data = new stdClass; $watch_data->history_id = $events[0]->id; return $watch_data; } return null; } /** * Checks for new notifications by using the previous preloaded watch-data. * * @param VBONotificationWatchdata $watch_data the preloaded watch-data object. * * @return array data object to watch next and notifications array. * * @see preload() * * @since 1.15.0 (J) - 1.5.0 (WP) */ public function getNotifications(VBONotificationWatchdata $watch_data = null) { // default empty values $watch_next = null; $notifications = null; if (!$watch_data) { return [$watch_next, $notifications]; } $latest_history_id = (int)$watch_data->get('history_id', 0); if (empty($latest_history_id)) { return [$watch_next, $notifications]; } // load the latest worthy-of-notification history events $history_obj = VikBooking::getBookingHistoryInstance(); $events = $history_obj->getWorthyEvents($latest_history_id, 10); if (!$events) { return [$watch_next, $notifications]; } // first off, build the next watch data for this widget $watch_next = new stdClass; $watch_next->history_id = $events[(count($events) - 1)]->id; // filter the newest events by those who have not been dispatched before through Push notifications $events = $watch_data->filterPushedReservations($events); // compose the notification(s) to dispatch, if any if ($events) { $notifications = VBONotificationScheduler::getInstance()->buildHistoryDataObjects($events); } return [$watch_next, $notifications]; } /** * Custom method for this widget only to load the history events. * The method is called by the admin controller through an AJAX request. * The visibility should be public, it should not exit the process, and * any content sent to output will be returned to the AJAX response. * In this case we return an array because this method requires "return":1. * * It's the actual rendering of the widget which also allows navigation. * * @return mixed boolean false in case of error, or associative array. */ public function loadHistoryEvents() { $instance = VikRequest::getInt('instance', 0, 'request'); $offset = VikRequest::getInt('offset', 0, 'request'); $evtype = VikRequest::getString('evtype', '', 'request'); $length = VikRequest::getInt('length', $this->events_per_page, 'request'); $wrapper = VikRequest::getString('wrapper', '', 'request'); // update widget's settings if ($instance >= 0) { if (!isset($this->widgetSettings[$instance])) { // push a new instance $this->widgetSettings[] = $this->getDefaultEventSettings($evtype); $instance = count($this->widgetSettings) - 1; } $this->widgetSettings[$instance]->evtype = $evtype; $this->updateSettings(json_encode($this->widgetSettings)); } // use the history class to get the events $history_obj = VikBooking::getBookingHistoryInstance(); $events = $history_obj->getLatestBookingEvents($offset, $length, $min_id = 0, [$evtype]); // check if a next page can be available $has_next_page = (count($events) >= $length); // start output buffering ob_start(); // loop through all history events $now = time(); $today = date('Y-m-d'); foreach ($events as $history) { if ($history->status == 'confirmed') { $ord_status = '' . JText::translate('VBCONFIRMED') . ''; } elseif ($history->status == 'standby') { $ord_status = '' . JText::translate('VBSTANDBY') . ''; } else { $ord_status = '' . JText::translate('VBCANCELLED') . ''; } if (!empty($history->booking_type) && !strcasecmp($history->booking_type, 'overbooking')) { $ord_status .= ' ' . JText::translate('VBO_BTYPE_OVERBOOKING') . ''; } $nominative = strlen($history->nominative) > 1 ? $history->nominative : VikBooking::getFirstCustDataField($history->custdata); $ch_logo_obj = VikBooking::getVcmChannelsLogo($history->channel, true); $channel_logo = is_object($ch_logo_obj) ? $ch_logo_obj->getSmallLogoURL() : ''; $nights_lbl = $history->days > 1 ? JText::translate('VBDAYS') : JText::translate('VBDAY'); $dt_obj = new JDate($history->dt); $dt_obj->setTimezone(new DateTimeZone(date_default_timezone_get())); // calculate check-in date information $checkin_info = getdate($history->checkin); if (date('Y-m-d', $history->checkin) == $today) { // check-in today $checkind_lbl = JText::translate('VBTODAY'); $checkind_icn = ''; } elseif ($history->checkin > $now) { // check-in in the future $checkind_lbl = VikBooking::sayWeekDay($checkin_info['wday'], true) . ', ' . date(str_replace("/", $this->datesep, $this->df), $history->checkin); $checkind_icn = ' '; } else { // check-in in the past $checkind_lbl = VikBooking::sayWeekDay($checkin_info['wday'], true) . ', ' . date(str_replace("/", $this->datesep, $this->df), $history->checkin); $checkind_icn = ' '; } ?>
$html_content, 'tot_records' => count($events), 'next_page' => (int)$has_next_page, ); } public function render(VBOMultitaskData $data = null) { // increase widget's instance counter static::$instance_counter++; // check whether the widget is being rendered via AJAX when adding it through the customizer $is_ajax = $this->isAjaxRendering(); // check whether we are in the multitask panel $is_multitask = $this->isMultitaskRendering(); // check whether the widget requires settings $needs_settings = !$is_ajax; $data_instance = !$is_ajax ? static::$instance_counter : '-1'; if ($is_multitask && $is_ajax) { $guess_inst_counter = $this->guessMultitaskHistoryInstance($data); if ($guess_inst_counter !== false) { // force the loading of the guessed widget instance's settings static::$instance_counter = $guess_inst_counter; $data_instance = $guess_inst_counter; $needs_settings = true; } } // generate a unique ID for the sticky notes wrapper instance $wrapper_instance = !$is_ajax ? static::$instance_counter : rand(); $wrapper_id = 'vbo-widget-latestevents-' . $wrapper_instance; // get permissions $vbo_auth_bookings = JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking'); // load the settings for this specific instance of the widget $instance_settings = $this->getDefaultEventSettings(); if ($needs_settings && is_array($this->widgetSettings) && isset($this->widgetSettings[static::$instance_counter])) { if (is_object($this->widgetSettings[static::$instance_counter]) && count(get_object_vars($this->widgetSettings[static::$instance_counter]))) { $instance_settings = $this->widgetSettings[static::$instance_counter]; } } // history object $history_obj = VikBooking::getBookingHistoryInstance(); // get all history types and groups $history_types = $history_obj->getTypesMap(); $history_groups = $history_obj->getTypeGroups(); // get the current event-type filter $current_evtype = ''; $current_evname = ''; if (!empty($instance_settings->evtype)) { if (isset($history_types[$instance_settings->evtype])) { $current_evtype = $instance_settings->evtype; $current_evname = $history_types[$current_evtype]; } elseif (isset($history_groups[$instance_settings->evtype])) { $current_evtype = $instance_settings->evtype; $current_evname = JText::translate('VBO_HISTORY_GROUPS') . ' - ' . $history_groups[$current_evtype]['name']; } } ?> widgetSettings) || !count($this->widgetSettings)) { // nothing to guess if this widget has got no saved settings return false; } if (!is_object($data)) { // multitask data object must be set return false; } // the page must be set in the multitask object $vbo_page = $data->getPage(); if (empty($vbo_page)) { // nothing to guess if no current page set return false; } // get the map for the current page $page_map = VikBooking::getAdminWidgetsInstance()->getMultitaskingMap($vbo_page, $whole = false); if (!is_array($page_map) || !count($page_map)) { // the multitask panel of this page has got no widgets saved, return the first index for settings return 0; } // count how many widgets of this type are already on this page $guessed_index = 0; foreach ($page_map as $widget_type) { if ($widget_type == $this->getIdentifier()) { $guessed_index++; } } // return the guessed index, which will load the next hypothetical instance return $guessed_index; } /** * Returns the default settings object for reading the latest history events. * * @param string $evtype optional event type requested. * * @return stdClass default object with default setting properties. * * @since 1.16.0 (J) - 1.6.0 (WP) */ protected function getDefaultEventSettings($evtype = null) { $opts = new stdClass; $opts->evtype = ''; if (!empty($evtype)) { $opts->evtype = $evtype; } elseif (!$this->isAjaxRendering() && !$this->isMultitaskRendering() && static::$instance_counter > 0) { // by default, the 2nd instance of the widget will fetch a group of events $opts->evtype = $this->hasChannelManager() ? 'GCM' : 'GBK'; } return $opts; } }