shop.balmet.com

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

d_twig_manager.php (5549B)


      1 <?php
      2 /*
      3  *  location: admin/model
      4  */
      5 
      6 class ModelExtensionModuleDTwigManager extends Model {
      7 
      8     /**
      9 
     10      Modal functions
     11 
     12      **/
     13 
     14     public function editTheme($store_id, $theme, $route, $code) {
     15         $this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE store_id = '" . (int)$store_id . "' AND theme = '" . $this->db->escape($theme) . "' AND route = '" . $this->db->escape($route) . "'");
     16         
     17         $this->db->query("INSERT INTO `" . DB_PREFIX . "theme` SET store_id = '" . (int)$store_id . "', theme = '" . $this->db->escape($theme) . "', route = '" . $this->db->escape($route) . "', code = '" . $this->db->escape($code) . "', date_added = NOW()");
     18     }
     19 
     20     public function deleteTheme($theme_id) {
     21         $this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE theme_id = '" . (int)$theme_id . "'");
     22     }
     23 
     24     public function getTheme($store_id, $theme, $route) {
     25         $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "theme` WHERE store_id = '" . (int)$store_id . "' AND theme = '" . $this->db->escape($theme) . "' AND route = '" . $this->db->escape($route) . "'");
     26 
     27         return $query->row;
     28     }
     29     
     30     public function getThemes($start = 0, $limit = 10) {
     31         if ($start < 0) {
     32             $start = 0;
     33         }
     34 
     35         if ($limit < 1) {
     36             $limit = 10;
     37         }       
     38         
     39         $query = $this->db->query("SELECT *, (SELECT name FROM `" . DB_PREFIX . "store` s WHERE s.store_id = t.store_id) AS store FROM `" . DB_PREFIX . "theme` t ORDER BY t.date_added DESC LIMIT " . (int)$start . "," . (int)$limit);
     40 
     41         return $query->rows;
     42     }
     43     
     44     public function getTotalThemes() {
     45         $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "theme`");
     46 
     47         return $query->row['total'];
     48     }
     49 
     50     public function installDatabase(){
     51         
     52         $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "theme` (
     53           `theme_id` int(11) NOT NULL AUTO_INCREMENT,
     54           `store_id` int(11) NOT NULL,
     55           `theme` varchar(64) NOT NULL,
     56           `route` varchar(64) NOT NULL,
     57           `code` mediumtext NOT NULL,
     58           `date_added` datetime NOT NULL,
     59           PRIMARY KEY (`theme_id`)
     60         ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
     61 
     62 
     63         $result = $this->db->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".DB_DATABASE."' AND TABLE_NAME = '" . DB_PREFIX . "theme' ORDER BY ORDINAL_POSITION")->rows; 
     64         $columns = array();
     65         foreach($result as $column){
     66             $columns[] = $column['COLUMN_NAME'];
     67         }
     68 
     69         if(in_array('code', $columns)){
     70              $this->db->query("ALTER TABLE `" . DB_PREFIX . "theme` MODIFY COLUMN `code` mediumtext NOT NULL");
     71         }
     72 
     73         if(!in_array('date_added', $columns)){
     74              $this->db->query("ALTER TABLE `" . DB_PREFIX . "theme` ADD `date_added` datetime NOT NULL");
     75         }
     76 
     77     }
     78 
     79     public function isCompatible(){
     80 
     81         $d_opencart_patch = (file_exists(DIR_SYSTEM.'library/d_shopunity/extension/d_opencart_patch.json'));
     82         if(!$d_opencart_patch){
     83             return false;
     84         }
     85 
     86         $this->load->model('extension/d_opencart_patch/modification');
     87 
     88         $compatibility = $this->model_extension_d_opencart_patch_modification->getModificationByName('d_twig_manager');
     89         if($compatibility){
     90             if(!empty($compatibility['status'])){
     91                 return true;
     92             }
     93         }
     94 
     95         return false;
     96 
     97     }
     98 
     99     public function installCompatibility(){
    100 
    101         $d_opencart_patch = (file_exists(DIR_SYSTEM.'library/d_shopunity/extension/d_opencart_patch.json'));
    102         if(!$d_opencart_patch){
    103             return false;
    104         }
    105 
    106         if(!$this->isCompatible()){
    107             $this->load->model('extension/d_opencart_patch/modification');
    108 
    109             $this->model_extension_d_opencart_patch_modification->setModification('d_twig_manager.xml', 0);
    110             $this->model_extension_d_opencart_patch_modification->setModification('d_twig_manager.xml', 1);
    111 
    112             $this->installDatabase();
    113 
    114             $this->model_extension_d_opencart_patch_modification->refreshCache();
    115 
    116             $this->load->model('extension/d_opencart_patch/url');
    117             $this->response->redirect($this->model_extension_d_opencart_patch_url->link($this->request->get['route']));
    118         }
    119 
    120         return true;
    121     }
    122 
    123     public function uninstallCompatibility(){
    124 
    125         $d_opencart_patch = (file_exists(DIR_SYSTEM.'library/d_shopunity/extension/d_opencart_patch.json'));
    126         if(!$d_opencart_patch){
    127             return false;
    128         }
    129 
    130         $this->load->model('extension/d_opencart_patch/modification');
    131         $this->model_extension_d_opencart_patch_modification->setModification('d_twig_manager.xml', 0);
    132         $this->model_extension_d_opencart_patch_modification->refreshCache();
    133 
    134         return true;
    135     }
    136         
    137 
    138     /**
    139 
    140      Helper functions
    141 
    142      **/
    143 
    144     /*
    145     *   Format the link to work with ajax requests
    146     */
    147     public function ajax($route, $url = '', $ssl = true){
    148         return str_replace('&amp;', '&', $this->url->link($route, $url, $ssl));
    149     }
    150 
    151     public function getSettingValue($key, $store_id = 0) {
    152         $query = $this->db->query("SELECT value FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
    153 
    154         if ($query->num_rows) {
    155             return $query->row['value'];
    156         } else {
    157             return null;    
    158         }
    159     }
    160 }
    161 ?>