<?php
class ModelDesignLayout extends Model {
	public function getLayout($route) {

	    $route_name = str_replace('/','_',$route);
        if($this->cache->cache_get('layout_' . $route_name, 'common/'))
            return $this->cache->cache_get('layout_' . $route_name, 'common/');


		$query = $this->db->query("SELECT * FROM ps_layout_route WHERE '" . $this->db->escape($route) . "' LIKE route AND store_id = '0' ORDER BY route DESC LIMIT 1");

		if ($query->num_rows) {
            $this->cache->cache_set('layout_' . $route_name, $query->row['layout_id'], 'common/');
			return $this->cache->cache_get('layout_' . $route_name, 'common/');
		} else {
			return 0;
		}
	}
	
	public function getLayoutModules($layout_id, $position) {

        $route_name = $layout_id . '_' . $position;
        if($this->cache->cache_get('layout_modules' . $route_name, 'common/'))
            return $this->cache->cache_get('layout_modules' . $route_name, 'common/');

		$query = $this->db->query("SELECT * FROM ps_layout_module WHERE layout_id = '" . (int)$layout_id . "' AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");

        $this->cache->cache_set('layout_modules' . $route_name, $query->rows, 'common/');
        return $this->cache->cache_get('layout_modules' . $route_name, 'common/');


	}
}