<?php
/******************************************************************************/
//                                                                            //
//                             Smarty plugin                                  //
//                            @package Smarty                                 //
//							 @subpackage plugins                              //
//                        https://life-style.uz/                              //
//                   produced by Life Style, life-style.uz                    //
//                                                                            //
/******************************************************************************/

function smarty_function_fetch_banner($params, &$smarty) {
	
	$assign   = fetch_getParam('assign', $params, 'banner');
	$fields   = fetch_getParam('fields', $params, 'bannerId, title, alias, text, summary, url, fileId, orderBy');
	$status   = fetch_getParam('status', $params, 'V');
    $sectionId  = fetch_getParam('section', $params);
	$limit    = (int) fetch_getParam('limit', $params,  10);
    $orderBy  = fetch_getParam('orderBy', $params, 'orderBy ASC');

    $banner = null;

    if ($group = connect('banners_group')->usingJoin('banner_tracking', 'groupId')->select('*')->where('sectionId', $sectionId)->where('status', $status)->get('array')) {
        $banner = connect()->table('banners')->select($fields)->where('status', $status)->where('groupId', $group['groupId'])->orderBy($orderBy)->limit($limit)->get('array');
        $banner['image'] = prepareBanner($banner['bannerId']);

    }
//    print_r($banners);
	$smarty->assign($assign, $banner);

}