/** * 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); }