ebay_profile.php (4067B)
1 <?php 2 class ModelExtensionOpenBayEbayProfile extends Model{ 3 public function add($data) { 4 if ($data['default'] == 1) { 5 $this->clearDefault($data['type']); 6 } 7 8 $this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_profile` SET `name` = '" . $this->db->escape($data['name']) . "', `description` = '" . $this->db->escape($data['description']) . "', `type` = '" . (int)$data['type'] . "', `default` = '" . (int)$data['default'] . "', `data` = '" . $this->db->escape(serialize($data['data'])) . "'"); 9 10 return $this->db->getLastId(); 11 } 12 13 public function edit($id, $data) { 14 if ($data['default'] == 1) { 15 $this->clearDefault($data['type']); 16 } 17 18 $this->db->query("UPDATE `" . DB_PREFIX . "ebay_profile` SET `name` = '" . $this->db->escape($data['name']) . "', `description` = '" . $this->db->escape($data['description']) . "', `data` = '" . $this->db->escape(serialize($data['data'])) . "', `default` = '" . (int)$data['default'] . "' WHERE `ebay_profile_id` = '" . (int)$id . "' LIMIT 1"); 19 } 20 21 public function delete($id) { 22 $this->db->query("DELETE FROM `" . DB_PREFIX . "ebay_profile` WHERE `ebay_profile_id` = '" . (int)$id . "' LIMIT 1"); 23 24 if ($this->db->countAffected() > 0) { 25 return true; 26 } else { 27 return false; 28 } 29 } 30 31 public function get($id) { 32 $qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_profile` WHERE `ebay_profile_id` = '" . (int)$id . "' LIMIT 1"); 33 34 if ($qry->num_rows) { 35 $row = $qry->row; 36 $row['link_edit'] = $this->url->link('extension/openbay/ebay_profile/edit', 'user_token=' . $this->session->data['user_token'] . '&ebay_profile_id=' . $row['ebay_profile_id'], true); 37 $row['link_delete'] = $this->url->link('extension/openbay/ebay_profile/delete', 'user_token=' . $this->session->data['user_token'] . '&ebay_profile_id=' . $row['ebay_profile_id'], true); 38 $row['data'] = unserialize($row['data']); 39 40 return $row; 41 } else { 42 return false; 43 } 44 } 45 46 public function getAll($type = '') { 47 $sql = "SELECT * FROM `" . DB_PREFIX . "ebay_profile`"; 48 49 if ($type !== '') { 50 $sql .= " WHERE `type` = '" . (int)$type . "'"; 51 } 52 53 $qry = $this->db->query($sql); 54 55 if ($qry->num_rows) { 56 $profiles = array(); 57 foreach ($qry->rows as $row) { 58 $row['link_edit'] = $this->url->link('extension/openbay/ebay_profile/edit', 'user_token=' . $this->session->data['user_token'] . '&ebay_profile_id=' . $row['ebay_profile_id'], true); 59 $row['link_delete'] = $this->url->link('extension/openbay/ebay_profile/delete', 'user_token=' . $this->session->data['user_token'] . '&ebay_profile_id=' . $row['ebay_profile_id'], true); 60 $row['data'] = !empty($row['data']) ? unserialize($row['data']) : array(); 61 $profiles[] = $row; 62 } 63 64 return $profiles; 65 } else { 66 return false; 67 } 68 } 69 70 public function getTypes() { 71 $types = array( 72 0 => array( 73 'name' => $this->language->get('text_type_shipping'), 74 'template' => 'extension/openbay/ebay_profile_form_shipping' 75 ), 76 1 => array( 77 'name' => $this->language->get('text_type_returns'), 78 'template' => 'extension/openbay/ebay_profile_form_returns' 79 ), 80 2 => array( 81 'name' => $this->language->get('text_type_template'), 82 'template' => 'extension/openbay/ebay_profile_form_template' 83 ), 84 3 => array( 85 'name' => $this->language->get('text_type_general'), 86 'template' => 'extension/openbay/ebay_profile_form_generic' 87 ) 88 ); 89 90 return $types; 91 } 92 93 public function getDefault($type) { 94 $qry = $this->db->query("SELECT `ebay_profile_id` FROM `" . DB_PREFIX . "ebay_profile` WHERE `type` = '" . (int)$type . "' AND `default` = '1'LIMIT 1"); 95 96 if ($qry->num_rows) { 97 return (int)$qry->row['ebay_profile_id']; 98 } else { 99 return false; 100 } 101 } 102 103 private function clearDefault($type) { 104 $this->db->query("UPDATE `" . DB_PREFIX . "ebay_profile` SET `default` = '0' WHERE `type` = '" . (int)$type . "'"); 105 } 106 }