<?php
/**
 * Joomla! component sexypolling
 *
 * @version $Id: view.html.php 2012-04-05 14:30:25 svn $
 * @author 2GLux.com
 * @package Sexy Polling
 * @subpackage com_sexypolling
 * @license GNU/GPL
 *
 */

// no direct access
defined('_JEXEC') or die('Restircted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');

class SexyContactFormViewSexyfields extends JViewLegacy {
	
	protected $items;
	protected $pagination;
	protected $state;
	
	/**
	 * Display the view
	 *
	 * @return	void
	 */
    public function display($tpl = null) {
    	
    	$this->items		= $this->get('Items');
    	$this->pagination	= $this->get('Pagination');
    	$this->state		= $this->get('State');
    	$forms	= $this->get('sexyForms');
    	$types	= $this->get('sexyTypes');
 
    	//get form options
    	$options        = array();
    	foreach($forms AS $form) {
    		$options[]      = JHtml::_('select.option', $form->id, $form->name);
    	}
    	//get type options
    	$type_options = array();
    	foreach($types AS $type) {
    		$type_options[]      = JHtml::_('select.option', $type->id, $type->name);
    	}
    	if(JV == 'j2') {
    		$this->assignRef( 'form_options', $options );
    		$this->assignRef( 'type_options', $type_options );
    	}
    	else {
    		JHtmlSidebar::addFilter(
    				JText::_('JOPTION_SELECT_PUBLISHED'),
    				'filter_published',
    				JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)
    		);
    		 
    		JHtmlSidebar::addFilter(
    				JText::_('COM_SEXYCONTACTFORM_SELECT_FORM'),
    				'filter_form_id',
    				JHtml::_('select.options', $options, 'value', 'text', $this->state->get('filter.form_id'))
    		);
    		 
    		JHtmlSidebar::addFilter(
    				JText::_('COM_SEXYCONTACTFORM_SELECT_TYPE'),
    				'filter_type_id',
    				JHtml::_('select.options', $type_options, 'value', 'text', $this->state->get('filter.type_id'))
    		);
    	}
       	$this->addToolbar();
       	if(JV == 'j3')
       		$this->sidebar = JHtmlSidebar::render();
		parent::display($tpl);
    }
	    
    /**
     * Add the page title and toolbar.
     *
     * @since	1.6
     */
    protected function addToolbar()
    {
    	JToolBarHelper::addNew('sexyfield.add');
    	JToolBarHelper::editList('sexyfield.edit');
	    	
		JToolBarHelper::divider();
 		JToolBarHelper::publish('sexyfields.publish', 'JTOOLBAR_PUBLISH', true);
		JToolBarHelper::unpublish('sexyfields.unpublish', 'JTOOLBAR_UNPUBLISH', true);
	    
    	if ($this->state->get('filter.published') == -2) {
    		JToolBarHelper::deleteList('', 'sexyfields.delete', 'JTOOLBAR_EMPTY_TRASH');
    		JToolBarHelper::divider();
    	}
    	else {
    		JToolBarHelper::trash('sexyfields.trash');
    		JToolBarHelper::divider();
    	}
	    
    }
    
    /**
     * Returns an array of fields the table can be sorted by
     *
     * @return  array  Array containing the field name to sort by as the key and display text as value
     *
     * @since   3.0
     */
    protected function getSortFields()
    {
    	return array(
    			'sp.ordering' => JText::_('JGRID_HEADING_ORDERING'),
    			'sp.name' => JText::_('COM_SEXYCONTACTFORM_NAME'),
    			'form' => JText::_('COM_SEXYCONTACTFORM_FORM'),
    			'sp.published' => JText::_('JSTATUS'),
    			'type' => JText::_('COM_SEXYCONTACTFORM_TYPE'),
    			'sp.id' => JText::_('JGRID_HEADING_ID')
    	);
    }
}