<?php
/**
 * FW Food menu 5.1.1
 * @copyright (C) 2020 Fastw3b
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.fastw3b.net/ Official website
 **/

defined( '_JEXEC' ) or die( 'Restricted access' );

class MenuViewCategory extends JViewLegacy {
	function display($tmpl=null) {
		$model = $this->getModel();

		$this->direct_link = false;
		$this->link = JURI::getInstance()->toString();
		$this->category = $model->loadCategory();
		if ($this->category->id and !$this->category->published) {
			return;
//			throw new Exception(fwFoodMenuHelper::jtext('FWFM_CATEGORY_NOT_PUBISHED', $name, $type, $prefix), 500);
		}

		$this->list = $model->loadList();
		$this->app = JFactory::getApplication();
		if ($this->category->id) {
			$this->params = new JFParams($this->category->params, fwFoodMenuHelper::getParentCategories($this->category->parent));
		} elseif ($this->list) {
			$this->params = new JFParams($this->list[0]->params, fwFoodMenuHelper::getParentCategories($this->list[0]->parent));
		} else {
			$this->params = new JFParams(new JRegistry);
		}

		$this->app->triggerEvent('onBeforeCategoryDisplay', array('com_fwfoodmenu', $this, $this->list));

		if ($title = $this->params->get('page_title')) {
			JFactory::getDocument()->setTitle($title);
		}
		if ($this->params->get('show_page_heading') and !$this->params->get('page_heading')) {
			if ($this->category->id) {
				$this->params->set('page_heading', $this->category->name);
			} else {
				$this->params->set('page_heading', $this->params->get('page_title'));
			}
		}
		parent::display($tmpl);
	}
}
