<?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 menuViewOrders extends JViewLegacy {
    function display($tmpl = null) {
        $this->menu = 'orders';
        $model = $this->getModel();

        JHTML::_('behavior.core');
        $this->app = JFactory::getApplication();
        $this->user = JFactory::getUser();
		$this->params = JComponentHelper::getParams('com_fwfoodmenu');

        $this->plugin_installed = fwFoodMenuHelper::pluginInstalled('cart');
        $this->plugin_enabled = fwFoodMenuHelper::pluginEnabled('cart');

		$this->fields = array('search', 'state','limit', 'limitstart');

        switch ($this->getLayout()) {
        case 'edit' :
			$this->object = $model->loadObject();
            foreach ($this->fields as $field) {
                $this->$field = (string)$this->app->input->getString($field);
            }
			fwFoodMenuHelper::triggerEvent('onLoadMainMenu', array('com_fwfoodmenu', 'order', $this));
        break;
        default:
			$this->list = $model->loadList();
			$this->pagination = $model->getPagination();
			$this->extra_link = '';
			$this->extra_state_link = '';
            foreach ($this->fields as $field) {
                $this->$field = (string)$this->app->input->getString($field);
				if (is_string($this->$field) and !empty($this->$field)) {
                    if  ($field != 'state') {
    					$this->extra_state_link .= '&amp;'.$field.'='.urlencode($this->$field);
                    }
					$this->extra_link .= '&amp;'.$field.'='.urlencode($this->$field);
    				$this->pagination->setAdditionalUrlParam($field, $this->$field);
    			}
            }
			fwFoodMenuHelper::triggerEvent('onLoadMainMenu', array('com_fwfoodmenu', 'orders', $this));
        }
        parent::display($tmpl);
    }
}
