/** * Execute the action */ public function execute() { parent::execute(); $hotelId = \SpoonFilter::getPostValue('hotel_id', null, 0); if (!$hotelId) { $this->output(self::ERROR, 'Missing values'); } $hotel = FrontendBookingsModel::getHotel($hotelId); if ($hotel) { $museums = FrontendBookingsModel::getMuseums($hotel['country'], $hotel['city']); $tpl = FRONTEND_MODULES_PATH . '/Bookings/Layout/Templates/Museums.tpl'; $museumsTpl = new Template(false); $museumsTpl->assign('hotel', $hotel); $museumsTpl->assign('museums', $museums); $html = $museumsTpl->getContent($tpl, true, true); } else { $html = ''; } // output $this->output(self::OK, $html); }
/** * Execute the action */ public function execute() { parent::execute(); $hotelId = \SpoonFilter::getPostValue('hotel_id', null, 0); $arrival = \SpoonFilter::getPostValue('arrival', null, 0); $departure = \SpoonFilter::getPostValue('departure', null, 0); if (!$hotelId && !$arrival && !$departure) { $this->output(self::ERROR, 'Missing values'); } $rooms = FrontendBookingsModel::getRooms($hotelId, $arrival, $departure); foreach ($rooms as &$room) { if ($room['available_rooms'] < 1) { $room['disabled'] = true; } } $tpl = FRONTEND_MODULES_PATH . '/Bookings/Layout/Templates/Rooms.tpl'; $roomsTpl = new Template(false); $roomsTpl->assign('rooms', $rooms); $html = $roomsTpl->getContent($tpl, true, true); // output $this->output(self::OK, $html); }
/** * Execute the action */ public function execute() { parent::execute(); $roomId = \SpoonFilter::getPostValue('room_id', null, 0); $room = FrontendBookingsModel::getRoom($roomId); $room['arrival'] = \SpoonFilter::getPostValue('arrival', null, ''); $room['departure'] = \SpoonFilter::getPostValue('departure', null, ''); if (!$room['arrival'] || !$room['departure'] || !$roomId) { $this->output(self::ERROR, 'Missing values'); } if (empty($room)) { $this->output(self::ERROR, 'Room not found'); } $room['stay_duration'] = floor((strtotime($room['departure']) - strtotime($room['arrival'])) / (60 * 60 * 24)); $room['total_price'] = $room['stay_duration'] * $room['price']; $tpl = FRONTEND_MODULES_PATH . '/Bookings/Layout/Templates/Room.tpl'; $roomTpl = new Template(false); $roomTpl->assign('room', $room); $html = $roomTpl->getContent($tpl, true, true); // output $this->output(self::OK, $html); }
/** * Get parsed template content * * @return string */ public function getContent() { return $this->tpl->getContent($this->templatePath, false, true); }
/** * Get navigation HTML * * @param string $type The type of navigation the HTML should be build for. * @param int $parentId The parentID to start of. * @param int $depth The maximum depth to parse. * @param array $excludeIds PageIDs to be excluded. * @param string $tpl The template that will be used. * @param int $depthCounter A counter that will hold the current depth. * @return string */ public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $tpl = '/Core/Layout/Templates/Navigation.tpl', $depthCounter = 1) { // get navigation $navigation = self::getNavigation(); // merge the exclude ids with the previously set exclude ids $excludeIds = array_merge((array) $excludeIds, self::$excludedPageIds); // meta-navigation is requested but meta isn't enabled if ($type == 'meta' && (!Model::get('fork.settings')->get('Pages', 'meta_navigation', true) || !isset($navigation['meta']))) { return ''; } // validate if (!isset($navigation[$type])) { throw new Exception('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.'); } if (!isset($navigation[$type][$parentId])) { throw new Exception('The parent (' . $parentId . ') doesn\'t exists.'); } // special construction to merge home with it's immediate children $mergedHome = false; while (true) { // loop elements foreach ($navigation[$type][$parentId] as $id => $page) { // home is a special item, it should live on the same depth if ($page['page_id'] == 1 && !$mergedHome) { // extra checks otherwise exceptions will wbe triggered. if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) { $navigation[$type][$parentId] = array(); } if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) { $navigation[$type][$page['page_id']] = array(); } // add children $navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]); // mark as merged $mergedHome = true; // restart loop continue 2; } // not hidden and not an action if ($page['hidden'] || $page['tree_type'] == 'direct_action') { unset($navigation[$type][$parentId][$id]); continue; } // some ids should be excluded if (in_array($page['page_id'], (array) $excludeIds)) { unset($navigation[$type][$parentId][$id]); continue; } // if the item is in the selected page it should get an selected class if (in_array($page['page_id'], self::$selectedPageIds)) { $navigation[$type][$parentId][$id]['selected'] = true; } else { $navigation[$type][$parentId][$id]['selected'] = false; } // add nofollow attribute if needed if ($page['no_follow']) { $navigation[$type][$parentId][$id]['nofollow'] = true; } else { $navigation[$type][$parentId][$id]['nofollow'] = false; } // meta and footer subpages have the "page" type if ($type == 'meta' || $type == "footer") { $subType = 'page'; } else { $subType = $type; } // fetch children if needed if (isset($navigation[$subType][$page['page_id']]) && $page['page_id'] != 1 && ($depth == null || $depthCounter + 1 <= $depth)) { $navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($subType, $page['page_id'], $depth, $excludeIds, $tpl, $depthCounter + 1); } else { $navigation[$type][$parentId][$id]['children'] = false; } // add parent id $navigation[$type][$parentId][$id]['parent_id'] = $parentId; // add depth $navigation[$type][$parentId][$id]['depth'] = $depthCounter; // set link $navigation[$type][$parentId][$id]['link'] = static::getURL($page['page_id']); // is this an internal redirect? if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') { $navigation[$type][$parentId][$id]['link'] = static::getURL((int) $page['redirect_page_id']); } // is this an external redirect? if (isset($page['redirect_url']) && $page['redirect_url'] != '') { $navigation[$type][$parentId][$id]['link'] = $page['redirect_url']; } } // break the loop (it is only used for the special construction with home) break; } // create template $navigationTpl = new Template(false); // assign navigation to template $navigationTpl->assign('navigation', $navigation[$type][$parentId]); // return parsed content return $navigationTpl->getContent(FRONTEND_PATH . (string) $tpl, true, true); }
/** * Returns the content from a given template * * @param string $template The template to use. * @param array $variables The variables to assign. * @return string */ private function getTemplateContent($template, $variables = null) { // new template instance $tpl = null; if (APPLICATION === 'Backend') { $tpl = new BackendTemplate(false); } else { $tpl = new Template(false); } // set some options $tpl->setForceCompile(true); // variables were set if (!empty($variables)) { $tpl->assign($variables); } // grab the content return $tpl->getContent($template); }
/** * Parse pagination */ protected function parsePagination() { $pagination = null; $showFirstPages = false; $showLastPages = false; $useQuestionMark = true; // validate pagination array if (!isset($this->pagination['limit'])) { throw new Exception('no limit in the pagination-property.'); } if (!isset($this->pagination['offset'])) { throw new Exception('no offset in the pagination-property.'); } if (!isset($this->pagination['requested_page'])) { throw new Exception('no requested_page available in the pagination-property.'); } if (!isset($this->pagination['num_items'])) { throw new Exception('no num_items available in the pagination-property.'); } if (!isset($this->pagination['num_pages'])) { throw new Exception('no num_pages available in the pagination-property.'); } if (!isset($this->pagination['url'])) { throw new Exception('no URL available in the pagination-property.'); } // should we use a questionmark or an ampersand if (mb_strpos($this->pagination['url'], '?') !== false) { $useQuestionMark = false; } // no pagination needed if ($this->pagination['num_pages'] < 1) { return; } // populate count fields $pagination['num_pages'] = $this->pagination['num_pages']; $pagination['current_page'] = $this->pagination['requested_page']; // define anchor $anchor = isset($this->pagination['anchor']) ? '#' . $this->pagination['anchor'] : ''; // as long as we have more then 5 pages and are 5 pages from the end we should show all pages till the end if ($this->pagination['requested_page'] > 5 && $this->pagination['requested_page'] >= $this->pagination['num_pages'] - 4) { // init vars $pagesStart = $this->pagination['num_pages'] > 7 ? $this->pagination['num_pages'] - 5 : $this->pagination['num_pages'] - 6; $pagesEnd = $this->pagination['num_pages']; // fix for page 6 if ($this->pagination['num_pages'] == 6) { $pagesStart = 1; } // show first pages if ($this->pagination['num_pages'] > 7) { $showFirstPages = true; } } elseif ($this->pagination['requested_page'] <= 5) { // as long as we are below page 5 and below 5 from the end we should show all pages starting from 1 // init vars $pagesStart = 1; $pagesEnd = 6; // when we have 7 pages, show 7 as end if ($this->pagination['num_pages'] == 7) { $pagesEnd = 7; } elseif ($this->pagination['num_pages'] <= 6) { // when we have less then 6 pages, show the maximum page $pagesEnd = $this->pagination['num_pages']; } // show last pages if ($this->pagination['num_pages'] > 7) { $showLastPages = true; } } else { // page 6 // init vars $pagesStart = $this->pagination['requested_page'] - 2; $pagesEnd = $this->pagination['requested_page'] + 2; $showFirstPages = true; $showLastPages = true; } // show previous if ($this->pagination['requested_page'] > 1) { // build URL if ($useQuestionMark) { $URL = $this->pagination['url'] . '?page=' . ($this->pagination['requested_page'] - 1); } else { $URL = $this->pagination['url'] . '&page=' . ($this->pagination['requested_page'] - 1); } // set $pagination['show_previous'] = true; $pagination['previous_url'] = $URL . $anchor; // flip ahead $this->header->addLink(array('rel' => 'prev', 'href' => SITE_URL . $URL . $anchor)); } // show first pages? if ($showFirstPages) { // init var $pagesFirstStart = 1; $pagesFirstEnd = 1; // loop pages for ($i = $pagesFirstStart; $i <= $pagesFirstEnd; $i++) { // build URL if ($useQuestionMark) { $URL = $this->pagination['url'] . '?page=' . $i; } else { $URL = $this->pagination['url'] . '&page=' . $i; } // add $pagination['first'][] = array('url' => $URL . $anchor, 'label' => $i); } } // build array for ($i = $pagesStart; $i <= $pagesEnd; $i++) { // init var $current = $i == $this->pagination['requested_page']; // build URL if ($useQuestionMark) { $URL = $this->pagination['url'] . '?page=' . $i; } else { $URL = $this->pagination['url'] . '&page=' . $i; } // add $pagination['pages'][] = array('url' => $URL . $anchor, 'label' => $i, 'current' => $current); } // show last pages? if ($showLastPages) { // init var $pagesLastStart = $this->pagination['num_pages']; $pagesLastEnd = $this->pagination['num_pages']; // loop pages for ($i = $pagesLastStart; $i <= $pagesLastEnd; $i++) { // build URL if ($useQuestionMark) { $URL = $this->pagination['url'] . '?page=' . $i; } else { $URL = $this->pagination['url'] . '&page=' . $i; } // add $pagination['last'][] = array('url' => $URL . $anchor, 'label' => $i); } } // show next if ($this->pagination['requested_page'] < $this->pagination['num_pages']) { // build URL if ($useQuestionMark) { $URL = $this->pagination['url'] . '?page=' . ($this->pagination['requested_page'] + 1); } else { $URL = $this->pagination['url'] . '&page=' . ($this->pagination['requested_page'] + 1); } // set $pagination['show_next'] = true; $pagination['next_url'] = $URL . $anchor; // flip ahead $this->header->addLink(array('rel' => 'next', 'href' => SITE_URL . $URL . $anchor)); } // multiple pages $pagination['multiple_pages'] = $pagination['num_pages'] == 1 ? false : true; // assign pagination $this->tpl->assign('pagination', $pagination); }