<?php
/**
 * @package DJ-Catalog2-Yootheme
 * @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@m.herzberg
 */
defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\String\StringHelper;

//Required code form view.html.php (items)
$app = JFactory::getApplication();
$jinput = $app->input;
$params = ComponentHelper::getParams('com_djcatalog2');
$filter_order		= $jinput->get( 'order',$params->get('items_default_order','i.ordering'),'cmd' );
$filter_order_Dir	= $jinput->get( 'dir',	$params->get('items_default_order_dir','asc'), 'word' );
$search				= urldecode($jinput->get( 'search','','string' ));
$search				= StringHelper::strtolower( $search );

$lists = array();

if (StringHelper::strlen($search) > 0 && (StringHelper::strlen($search)) < 1 || StringHelper::strlen($search) > 40) {
	echo JText::_( 'COM_DJCATALOG2_SEARCH_RESTRICTION');
}
if ($filter_order_Dir == '' || $filter_order_Dir == 'desc') {
	$lists['order_Dir'] = 'asc';
} else {
	$lists['order_Dir'] = 'desc';
}
$lists['order'] = $filter_order;



$html = '';
$html .= '<div class="djc_order_set">';
//Get Model Items
\JModelLegacy::addIncludePath(JPATH_ROOT . '/components/com_djcatalog2/models', 'DJCatalog2Model');
$model = \JModelLegacy::getInstance('Items', 'DJCatalog2Model', ['ignore_request' => true]);
$params = ComponentHelper::getParams('com_djcatalog2');
$sortables = $model->getSortables();

if (count($items) > 0 && (
		$params->get('show_category_orderby') > 0
		|| $params->get('show_producer_orderby') > 0
		|| $params->get('show_name_orderby') > 0
		|| $params->get('show_price_orderby') > 0
		|| $params->get('show_date_orderby') > 0
		|| $params->get('show_modify_date_orderby') > 0
		|| $params->get('show_hits_orderby') > 0
		|| count($sortables) > 0)) {
	$html .= '<div>';

	//Include order view for items
	ob_start();
	include(dirname(__FILE__).'/order_sort.php');
	$html .= ob_get_contents();
	ob_end_clean();

	$html .= '</div>';
}
$html .= '</div>';
echo $html;