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

function smarty_function_fetch_sliders($params, &$smarty) {
	
	$assign   = fetch_getParam('assign', $params, 'sliders');
	$fields   = fetch_getParam('fields', $params, 'sliderId, title, alias, text, summary, url, fileId, orderBy');
	$status   = fetch_getParam('status', $params, 'V');
	$limit    = (int) fetch_getParam('limit', $params,  5);
    $orderBy  = fetch_getParam('orderBy', $params, 'orderBy ASC');

	/* conditions */
	if(!empty($status)) connect()->where('status',  $status);

    $sliders = connect()->table('sliders')->select($fields)->orderBy($orderBy)->limit($limit)->getAll('array');
    foreach ($sliders as $sliderId => $slider) {
        $sliders[$sliderId]['images'] = prepareSlider($slider['fileId']);
    }

//    print_r($sliders);
	$smarty->assign($assign, $sliders);

}