shop.balmet.com

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

event.php (2527B)


      1 <?php
      2 /*
      3  *  location: admin/model/extension/d_opencart_patch/event.php
      4  *  
      5  *  This is only a wrapper for basic event model. If you want full controll of events
      6  *  you should go for d_event_manager. You will be able to delete events by ID and more.
      7  */
      8 
      9 class ModelExtensionDOpencartPatchEvent extends Model {
     10 
     11 
     12     public function addEvent($code, $trigger, $action, $status = 1) {
     13         $this->installDatabase();
     14         $this->db->query("INSERT INTO `" . DB_PREFIX . "event` SET `code` = '" . $this->db->escape($code) . "', `trigger` = '" . $this->db->escape($trigger) . "', `action` = '" . $this->db->escape($action) . "', `status` = '" . (int)$status . "', `date_added` = now()");
     15     
     16         return $this->db->getLastId();
     17     }
     18 
     19     public function deleteEvent($code) {
     20         $this->installDatabase();
     21         //if you have several events under one code - they will all be deleted. 
     22         //please use deleteEventById from d_event_manager.
     23         if(VERSION > '2.0.0.0'){
     24             $this->load->model('extension/event');
     25             return $this->model_extension_event->deleteEvent($code);
     26         }else{
     27             $this->db->query("DELETE FROM " . DB_PREFIX . "event WHERE `code` = '" . $this->db->escape($code) . "'");
     28         }
     29         
     30     }
     31 
     32     /**
     33     *   Install Databse for Events in case it is missing. This will not add the functionality of events. 
     34     **/
     35     public function installDatabase(){
     36         
     37         $this->db->query("CREATE TABLE IF NOT EXISTS `".DB_PREFIX."event` (
     38           `event_id` int(11) NOT NULL AUTO_INCREMENT,
     39           `code` varchar(32) NOT NULL,
     40           `trigger` text NOT NULL,
     41           `action` text NOT NULL,
     42           `status` tinyint(1) NOT NULL,
     43           `date_added` datetime NOT NULL,
     44           PRIMARY KEY (`event_id`)
     45         ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;");
     46 
     47 
     48         $result = $this->db->query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".DB_DATABASE."' AND TABLE_NAME = '" . DB_PREFIX . "event' ORDER BY ORDINAL_POSITION")->rows; 
     49         $columns = array();
     50         foreach($result as $column){
     51             $columns[] = $column['COLUMN_NAME'];
     52         }
     53 
     54         if(!in_array('status', $columns)){
     55              $this->db->query("ALTER TABLE `" . DB_PREFIX . "event` ADD status int( 1 ) NOT NULL default '1'");
     56         }
     57 
     58         if(!in_array('date_added', $columns)){
     59              $this->db->query("ALTER TABLE `" . DB_PREFIX . "event` ADD `date_added` datetime NOT NULL");
     60         }
     61 
     62     }
     63 }
     64 ?>