shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

google_base.php (3736B)


      1 <?php
      2 class ModelExtensionFeedGoogleBase extends Model {
      3 	public function install() {
      4 		$this->db->query("
      5 			CREATE TABLE `" . DB_PREFIX . "google_base_category` (
      6 				`google_base_category_id` INT(11) NOT NULL AUTO_INCREMENT,
      7 				`name` varchar(255) NOT NULL,
      8 				PRIMARY KEY (`google_base_category_id`)
      9 			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
     10 		");
     11 
     12 		$this->db->query("
     13 			CREATE TABLE `" . DB_PREFIX . "google_base_category_to_category` (
     14 				`google_base_category_id` INT(11) NOT NULL,
     15 				`category_id` INT(11) NOT NULL,
     16 				PRIMARY KEY (`google_base_category_id`, `category_id`)
     17 			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
     18 		");
     19 	}
     20 
     21 	public function uninstall() {
     22 		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "google_base_category`");
     23 		$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "google_base_category_to_category`");
     24 	}
     25 
     26     public function import($string) {
     27         $this->db->query("DELETE FROM " . DB_PREFIX . "google_base_category");
     28 
     29         $lines = explode("\n", $string);
     30 
     31         foreach ($lines as $line) {
     32 			if (substr($line, 0, 1) != '#') {
     33 	            $part = explode(' - ', $line, 2);
     34 
     35 	            if (isset($part[1])) {
     36 	                $this->db->query("INSERT INTO " . DB_PREFIX . "google_base_category SET google_base_category_id = '" . (int)$part[0] . "', name = '" . $this->db->escape($part[1]) . "'");
     37 	            }
     38 			}
     39         }
     40     }
     41 
     42     public function getGoogleBaseCategories($data = array()) {
     43         $sql = "SELECT * FROM `" . DB_PREFIX . "google_base_category` WHERE name LIKE '%" . $this->db->escape($data['filter_name']) . "%' ORDER BY name ASC";
     44 
     45 		if (isset($data['start']) || isset($data['limit'])) {
     46 			if ($data['start'] < 0) {
     47 				$data['start'] = 0;
     48 			}
     49 
     50 			if ($data['limit'] < 1) {
     51 				$data['limit'] = 20;
     52 			}
     53 
     54 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     55 		}
     56 
     57 		$query = $this->db->query($sql);
     58 
     59 		return $query->rows;
     60     }
     61 
     62 	public function addCategory($data) {
     63 		$this->db->query("DELETE FROM " . DB_PREFIX . "google_base_category_to_category WHERE category_id = '" . (int)$data['category_id'] . "'");
     64 
     65 		$this->db->query("INSERT INTO " . DB_PREFIX . "google_base_category_to_category SET google_base_category_id = '" . (int)$data['google_base_category_id'] . "', category_id = '" . (int)$data['category_id'] . "'");
     66 	}
     67 
     68 	public function deleteCategory($category_id) {
     69 		$this->db->query("DELETE FROM " . DB_PREFIX . "google_base_category_to_category WHERE category_id = '" . (int)$category_id . "'");
     70 	}
     71 
     72     public function getCategories($data = array()) {
     73         $sql = "SELECT google_base_category_id, (SELECT name FROM `" . DB_PREFIX . "google_base_category` gbc WHERE gbc.google_base_category_id = gbc2c.google_base_category_id) AS google_base_category, category_id, (SELECT name FROM `" . DB_PREFIX . "category_description` cd WHERE cd.category_id = gbc2c.category_id AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS category FROM `" . DB_PREFIX . "google_base_category_to_category` gbc2c ORDER BY google_base_category ASC";
     74 
     75 		if (isset($data['start']) || isset($data['limit'])) {
     76 			if ($data['start'] < 0) {
     77 				$data['start'] = 0;
     78 			}
     79 
     80 			if ($data['limit'] < 1) {
     81 				$data['limit'] = 20;
     82 			}
     83 
     84 			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
     85 		}
     86 
     87 		$query = $this->db->query($sql);
     88 
     89 		return $query->rows;
     90     }
     91 
     92 	public function getTotalCategories() {
     93 		$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "google_base_category_to_category`");
     94 
     95 		return $query->row['total'];
     96     }
     97 }