<?php
/**
 * @package DJ-Events
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 * @developer Szymon Woronowski - szymon.woronowski@design-joomla.eu
 *
 */

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

jimport('joomla.application.component.view');

class DJEventsViewEvents extends JViewLegacy
{
	protected $items;
	protected $pagination;
	protected $state;
    public $filterForm;
    public $activeFilters;

	public function display($tpl = null)
	{
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');
        $this->filterForm    = $this->get('FilterForm');
        $this->activeFilters = $this->get('ActiveFilters');
		
		$this->categories = $this->get('Categories');
		$this->cities = $this->get('Cities');
		
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			throw new Exception(implode("\n", $errors), 500);
			return false;
		}
		$this->addToolbar();


		
		$this->classes = DJEventsHelper::getBSClasses();


        $version = new JVersion;
        if (version_compare($version->getShortVersion(), '4.0.0-rc3', '<')) {
            $this->sidebar = JHtmlSidebar::render();
            $this->setLayout('legacy');
        }

		parent::display($tpl);
	}

	protected function addToolbar()
	{
		JToolBarHelper::title(JText::_('COM_DJEVENTS_EVENTS'), 'generic.png');
		JToolBarHelper::addNew('event.add','JTOOLBAR_NEW');
		JToolBarHelper::editList('event.edit','JTOOLBAR_EDIT');
		JToolBarHelper::divider();
		JToolBarHelper::custom('events.publish', 'publish.png', 'publish_f2.png','JTOOLBAR_PUBLISH', true);
		JToolBarHelper::custom('events.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
		JToolbarHelper::custom('events.featured', 'featured.png', 'featured_f2.png', 'JFEATURE', true);
		JToolbarHelper::custom('events.unfeatured', 'unfeatured.png', 'featured_f2.png', 'JUNFEATURE', true);
		JToolBarHelper::deleteList('', 'events.delete','JTOOLBAR_DELETE');
		JToolBarHelper::divider();
		JToolBarHelper::preferences('com_djevents', '450', '900');
		JToolBarHelper::divider();
	}
}
