<?php
class ModelCatalogCategory extends Model {
	public function getCategory($category_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'");
		 
		return $query->row;
	}
	
	public function getInformations() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=13");
		
		return $query->rows;
	}
	
	public function getdetailinformation() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=14");
		
		return $query->rows;
	}
	
	public function getdetailinformation2() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=15");
		
		return $query->rows;
	}
	
	public function getpersonaldesigner() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=16");
		
		return $query->rows;
	}
	
	public function getshipping1() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=17");
		
		return $query->rows;
	}
	
	public function getshipping2() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=18");
		
		return $query->rows;
	}
	
	public function getshipping3() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=19");
		
		return $query->rows;
	}
	
	public function getshipping4() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=20");
		
		return $query->rows;
	}
	
	public function getaboutdesign() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=21");
		
		return $query->rows;
	}
	
	public function getfaqs() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=22");
		
		return $query->rows;
	}
	
	public function getcontacts() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=23");
		
		return $query->rows;
	}
	
	public function getCategories($parent_id = 0) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)");
		
		return $query->rows;
	}

	public function getCategoriesByParentId($category_id) {
		$category_data = array();
		
		$category_query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE parent_id = '" . (int)$category_id . "'");
		
		foreach ($category_query->rows as $category) {
			$category_data[] = $category['category_id'];
			
			$children = $this->getCategoriesByParentId($category['category_id']);
			
			if ($children) {
				$category_data = array_merge($children, $category_data);
			}			
		}
		
		return $category_data;
	}
		
	public function getCategoryLayoutId($category_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_to_layout WHERE category_id = '" . (int)$category_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		if ($query->num_rows) {
			return $query->row['layout_id'];
		} else {
			return $this->config->get('config_layout_category');
		}
	}
					
	public function getTotalCategoriesByCategoryId($parent_id = 0) {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'");
		
		return $query->row['total'];
	}
}
?>