<?php
class ModelExtensionModuleCustommenu extends Model {
	public function getCustommenu($custommenu_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "custommenu c LEFT JOIN " . DB_PREFIX . "custommenu_description cd ON (c.custommenu_id = cd.custommenu_id) LEFT JOIN " . DB_PREFIX . "custommenu_to_store c2s ON (c.custommenu_id = c2s.custommenu_id) WHERE c.custommenu_id = '" . (int)$custommenu_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 getCategories($parent_id = 0) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "custommenu c LEFT JOIN " . DB_PREFIX . "custommenu_description cd ON (c.custommenu_id = cd.custommenu_id) LEFT JOIN " . DB_PREFIX . "custommenu_to_store c2s ON (c.custommenu_id = c2s.custommenu_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 getTotalCategoriesByCustommenuId($parent_id = 0) {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "custommenu c LEFT JOIN " . DB_PREFIX . "custommenu_to_store c2s ON (c.custommenu_id = c2s.custommenu_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'];
	}
}