d_validator.php (4324B)
1 <?php 2 3 class ModelExtensionDShopunityDValidator extends Model 4 { 5 public $codename = 'd_validator'; 6 7 public function reinstallEvents($modules) 8 { 9 $this->load->model('extension/module/d_event_manager'); 10 $this->model_extension_module_d_event_manager->deleteEvent($this->codename); 11 12 foreach ($modules as $module) { 13 $this->model_extension_module_d_event_manager->addEvent($this->codename, $module['trigger'], $module['action'], 1); 14 } 15 } 16 17 public function installCompatibility() 18 { 19 $this->load->config($this->codename); 20 $modules = $this->config->get($this->codename . '_modules'); 21 22 $this->load->model('user/user_group'); 23 $this->model_user_user_group->addPermission($this->getGroupId(), 'access', 'extension/'.$this->shopunity_codename); 24 $this->model_user_user_group->addPermission($this->getGroupId(), 'access', 'extension/'.$this->shopunity_codename.'/'.$this->codename); 25 26 $this->model_user_user_group->addPermission($this->getGroupId(), 'modify', 'extension/'.$this->shopunity_codename); 27 $this->model_user_user_group->addPermission($this->getGroupId(), 'modify', 'extension/'.$this->shopunity_codename.'/'.$this->codename); 28 29 if (!$this->isInstalledTable()){ 30 $this->createTable(); 31 } 32 33 if (!$this->isFillEventsTable() || (int)$this->isFillEventsTable()['COUNT(*)'] != count($modules)){ 34 $this->reinstallEvents($modules); 35 } 36 } 37 38 public function uninstallModule() 39 { 40 $this->load->model('setting/event'); 41 42 $this->model_setting_event->deleteEventByCode($this->codename); 43 44 $this->deleteTable(); 45 } 46 47 public function deleteEvents() 48 { 49 $this->load->model('setting/event'); 50 51 $this->model_setting_event->deleteEventByCode($this->codename); 52 } 53 54 public function getTimeByCodename($codename) 55 { 56 $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "d_validator WHERE codename = '" . $this->db->escape($codename) . "'"); 57 58 return $query->row; 59 } 60 61 public function insertTime($data) 62 { 63 return $this->db->query("INSERT INTO " . DB_PREFIX . "d_validator SET 64 codename = '" . $this->db->escape($data['codename']) . "', 65 date_show = '" . $this->db->escape($data['date_show']) . "', 66 date_created = '" . $this->db->escape($data['date_created']) . "'"); 67 } 68 69 public function updateTimeByCodename($codename, $data) 70 { 71 $this->db->query("UPDATE " . DB_PREFIX . "d_validator SET 72 `date_show` = '" . $this->db->escape($data['date_show']) . "', 73 `date_created` = '" . $this->db->escape($data['date_created']) . "' 74 WHERE codename = '" . $this->db->escape($codename) . "'"); 75 } 76 77 public function createTable() 78 { 79 $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "d_validator` ( 80 `validator_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, 81 `codename` varchar(191) NOT NULL, 82 `date_show` datetime NOT NULL, 83 `date_created` datetime DEFAULT NULL 84 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"); 85 } 86 87 public function deleteTable() 88 { 89 $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "d_validator`"); 90 } 91 92 public function uninstallDatabase() 93 { 94 $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "d_validator`"); 95 } 96 97 public function isInstalledTable() 98 { 99 return $this->db->query("SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA='" . $this->db->escape(DB_DATABASE) . "' AND TABLE_NAME='" . DB_PREFIX . "d_validator'")->num_rows > 0; 100 } 101 102 public function isFillEventsTable() 103 { 104 $query = $this->db->query("SELECT COUNT(*) FROM `" . DB_PREFIX . "event` WHERE code = '" . $this->codename . "'"); 105 106 return $query->row; 107 } 108 109 public function getGroupId(){ 110 if(VERSION >= '2.0.0.0'){ 111 $user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE user_id = '" . $this->user->getId() . "'"); 112 $user_group_id = (int)$user_query->row['user_group_id']; 113 }else{ 114 $user_group_id = $this->user->getGroupId(); 115 } 116 117 return $user_group_id; 118 } 119 }