<?php
 class ModelExtensionModuleCategorySeoContent extends Model {

    public function install() {
        $sql = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "category_seo_content` (
                    `seo_content_id` int(11) NOT NULL auto_increment,
                    `category_id` int(11) NOT NULL,
                    `language_id` int(4) default NULL,
                    `description` text collate utf8_bin  default NULL,
                    PRIMARY KEY  (`seo_content_id`)
                    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin;";
        $this->db->query($sql);
    }

    public function uninstall() {
        $sql = "DROP TABLE IF EXISTS `" . DB_PREFIX . "category_seo_content`";
        $this->db->query($sql);
    }

    public function get_desrc_category($category_id) {
        $query = $this->db->query("SELECT *  FROM " . DB_PREFIX . "category_seo_content WHERE category_id ='" . (int) $category_id . "'");
        $category_seo_content_data = array();
        if ($query->rows) {
            foreach ($query->rows as $result) {
                $category_seo_content_data[$result['language_id']] = array(
                    'seo_content_id' => $result['seo_content_id'],
                    'category_id' => $result['category_id'],
                    'description' => $result['description']
                );
            }
        }
        return $category_seo_content_data;
    }

    public function insert($category_id, $data) {
        $this->db->query("DELETE FROM " . DB_PREFIX . "category_seo_content WHERE category_id = '" . (int) $category_id . "'");

        foreach ($data['category_seo_content'] as $language_id => $category_desrc) {
            
            $category_desrc['seo_content_id'] = isset($category_desrc['seo_content_id']) ? (int) $category_desrc['seo_content_id'] : '';
            if (isset($language_id) && $category_desrc['description']) {
                $this->db->query("INSERT INTO " . DB_PREFIX . "category_seo_content SET seo_content_id = '" . $category_desrc['seo_content_id'] . "', category_id = '" . (int) $category_id . "', language_id = '" . (int) $language_id . "', description = '" . $category_desrc['description'] . "'");
            }
        }
    }

}

?>