aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/model/extension/openbay/ebay_template.php
blob: b367059ca45195eb0ec37ececb02f6baff127272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class ModelExtensionOpenBayEbayTemplate extends Model {
	public function add($data) {
		$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_template` SET `name` = '" . $this->db->escape($data['name']) . "', `html` = '" . $this->db->escape($data['html']) . "'");
		return $this->db->getLastId();
	}

	public function edit($id, $data) {
		$this->db->query("UPDATE `" . DB_PREFIX . "ebay_template` SET `name` = '" . $this->db->escape($data['name']) . "', `html` = '" . $this->db->escape($data['html']) . "' WHERE `template_id` = '" . (int)$id . "' LIMIT 1");
	}

	public function delete($id) {
		$qry = $this->db->query("DELETE FROM `" . DB_PREFIX . "ebay_template` WHERE `template_id` = '" . (int)$id . "' LIMIT 1");

		if ($qry->countAffected() > 0) {
			return true;
		}else{
			return false;
		}
	}

	public function get($id) {
		$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_template` WHERE `template_id` = '" . (int)$id . "' LIMIT 1");

		if ($qry->num_rows) {
			$row = $qry->row;
			$row['link_edit'] = $this->url->link('extension/openbay/ebay_template/edit&user_token=' . $this->session->data['user_token'] . '&template_id=' . $row['template_id'], true);
			$row['link_delete'] = $this->url->link('extension/openbay/ebay_template/delete&user_token=' . $this->session->data['user_token'] . '&template_id=' . $row['template_id'], true);

			return $row;
		}else{
			return false;
		}
	}

	public function getAll() {
		$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_template`");

		$templates = array();

		if($qry->num_rows) {
			foreach($qry->rows as $row) {
				$row['link_edit'] = $this->url->link('extension/openbay/ebay_template/edit&user_token=' . $this->session->data['user_token'] . '&template_id=' . $row['template_id'], true);
				$row['link_delete'] = $this->url->link('extension/openbay/ebay_template/delete&user_token=' . $this->session->data['user_token'] . '&template_id=' . $row['template_id'], true);
				$templates[] = $row;
			}
		}

		return $templates;
	}
}