<?php
class ModelDesignBanner extends Model {
	public function getBanner($banner_id) {

        /*if ($banner_id==8 && isset($_COOKIE['DADEVICE']) && $_COOKIE['DADEVICE'] != 'other') {

            $deviceName = str_replace('_', ' ', $_COOKIE['DADEVICE']);

            $categoryResult = $this->db->query("SELECT category_id FROM ps_category_description WHERE full_name='$deviceName' LIMIT 1")->row;

            if (isset($categoryResult['category_id']) && !empty($categoryResult['category_id'])) {

                $deviceBanner = $this->db->query("SELECT banner_id FROM ps_banner WHERE model={$categoryResult['category_id']} LIMIT 1")->row;

                if (isset($deviceBanner['banner_id']) && !empty($deviceBanner['banner_id'])) {
                    $banner_id = $deviceBanner['banner_id'];
                }

            }

        }*/

        if($this->cache->cache_get('banner_sql-' . $this->session->data['language'] . '-' . $this->session->data['currency'] . $banner_id, 'banners/'))
            return $this->cache->cache_get('banner_sql-' . $this->session->data['language'] . '-' . $this->session->data['currency'] . $banner_id, 'banners/');


		$query = $this->db->query("SELECT * FROM ps_banner b 
        LEFT JOIN ps_banner_image bi ON (b.banner_id = bi.banner_id) 
        WHERE b.banner_id = '" . (int)$banner_id . "' AND b.status = '1' AND bi.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY bi.sort_order ASC");


        $this->cache->cache_set('banner_sql-' . $this->session->data['language'] . '-' . $this->session->data['currency'] . $banner_id, $query->rows, 'banners/');
        return $query->rows;
        //return $this->cache->cache_get('banner-' . $this->session->data['language'] . '-' . $this->session->data['currency'] . $banner_id, 'banners/');
	}
}
