widgetName = JText::translate('VBO_QUOTES'); $this->widgetDescr = JText::translate('VBO_W_QUOTES_DESCR'); $this->widgetId = basename(__FILE__, '.php'); $this->widgetIcon = ''; $this->widgetStyleName = 'orange'; } /** * Custom method for this widget only to load the next page of quote records. * 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. * * @return array */ public function loadNextQuotes() { $input = JFactory::getApplication()->input; $wrapper = $input->getString('wrapper', ''); $unsent = $input->getBool('unsent', false); $page_num = $input->getUInt('page_num', 1); $page_num = $page_num ?: 1; // access the quote model $quoteModel = VBOMvcModel::getInstance('quote'); // build query filters $filters = []; if ($unsent) { // filter by those quotes that were not sent before $filters['sent'] = [ [ 'operand' => '=', 'value' => '0', ], ]; } // determine the query limit start $lim_start = ($page_num - 1) * $this->records_per_page; // get and build the latest quotes $html_content = $this->buildQuotesHTML( $quoteModel->loadBookingRecords($lim_start, $this->records_per_page, ['filters' => $filters]), ($page_num - 1) ); // return an associative array of values return [ 'html' => $html_content, 'page_number' => $page_num, 'pages_count' => ceil($quoteModel->countRecordsFound() / $this->records_per_page), ]; } /** * Main method to invoke the widget. * * @param ?VBOMultitaskData $data * * @return void */ public function render(?VBOMultitaskData $data = null) { // increase widget's instance counter static::$instance_counter++; // check whether the widget is being rendered via AJAX $is_ajax = $this->isAjaxRendering(); // generate a unique ID for the wrapper instance $wrapper_instance = !$is_ajax ? static::$instance_counter : rand(); $wrapper_id = 'vbo-widget-quotes-' . $wrapper_instance; // check permissions $vbo_auth_bookings = JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking'); if (!$vbo_auth_bookings) { // permissions are not met return; } // check multitask data $js_modal_id = ''; $is_modal_rendering = false; if ($data) { // access Multitask data $is_modal_rendering = $data->isModalRendering(); if ($is_modal_rendering) { // get modal JS identifier $js_modal_id = $data->getModalJsIdentifier(); } } // check if a booking ID was requested for loading (ignore multi-task data) $bookingId = $this->options()->fetchBookingId(); // access the quote model $quoteModel = VBOMvcModel::getInstance('quote'); // start quotes list $quotes = []; // load all quotes or the one assigned to the given booking ID if ($bookingId) { // make sure the booking exists $bookingRecord = VikBooking::getBookingInfoFromID((int) $bookingId); if (!empty($bookingRecord['idquote'])) { // load the involved quote record $quotes = $quoteModel->loadBookingRecords(0, 1, [ 'filters' => [ 'id' => (int) $bookingRecord['idquote'], ], ]); } } else { // load latest quotes by default $quotes = $quoteModel->loadBookingRecords(0, $this->records_per_page); } // immediately count the number of pages to show all quotes $pages_count = ceil($quoteModel->countRecordsFound() / $this->records_per_page); ?>
valid_until) && JFactory::getDate($quote->valid_until)->getTimestamp() < time()) { $isExpired = true; } ?>