· 8 years ago · Mar 29, 2018, 01:40 PM
1<?php
2
3class Image extends ImageCore {
4 /*
5 * module: centry_ps
6 * date: 2018-03-27 14:59:34
7 * version: 2.0.0
8 */
9 private static $TABLE = "image_centry";
10 /*
11 * module: centry_ps
12 * date: 2018-03-27 14:59:34
13 * version: 2.0.0
14 */
15 public $cover = null;
16 /*
17 * module: centry_ps
18 * date: 2018-03-27 14:59:34
19 * version: 2.0.0
20 */
21 public $content_type = null;
22 /*
23 * module: centry_ps
24 * date: 2018-03-27 14:59:34
25 * version: 2.0.0
26 */
27 public $file_name = null;
28 /*
29 * module: centry_ps
30 * date: 2018-03-27 14:59:34
31 * version: 2.0.0
32 */
33 public $file_size = null;
34 /*
35 * module: centry_ps
36 * date: 2018-03-27 14:59:34
37 * version: 2.0.0
38 */
39 public $created_at = null;
40 /*
41 * module: centry_ps
42 * date: 2018-03-27 14:59:34
43 * version: 2.0.0
44 */
45 public $updated_at = null;
46 /*
47 * module: centry_ps
48 * date: 2018-03-27 14:59:34
49 * version: 2.0.0
50 */
51 public $fingerprint = null;
52 /*
53 * module: centry_ps
54 * date: 2018-03-27 14:59:34
55 * version: 2.0.0
56 */
57 public $url = null;
58 /*
59 * module: centry_ps
60 * date: 2018-03-27 14:59:34
61 * version: 2.0.0
62 */
63 //public $legend = null;
64 /*
65 * module: centry_ps
66 * date: 2018-03-27 14:59:34
67 * version: 2.0.0
68 */
69 public function __construct($id = null, $id_lang = null) {
70 parent::__construct($id, $id_lang);
71 if (isset($id)) {
72 $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
73 $query = new DbQuery();
74 $query->select('*');
75 $query->from(static::$TABLE);
76 $query->where("id_image = '" . $db->escape($this->id) . "'");
77 $row = $db->getRow($query);
78 $this->id_centry = $row["id_centry"];
79 $this->cover = $row["cover"];
80 $this->content_type = $row["content_type"];
81 $this->file_name = $row["file_name"];
82 $this->file_size = $row["file_size"];
83 $this->fingerprint = $row["fingerprint"];
84 $this->created_at = $row["created_at"];
85 $this->updated_at = $row["updated_at"];
86 $this->url = $row["url"];
87 //$this->legend = $row["legend"];
88 }
89 }
90
91 /*
92 * module: centry_ps
93 * date: 2018-03-27 14:59:34
94 * version: 2.0.0
95 */
96 public function save($null_values = false, $auto_date = true) {
97 return parent::save($null_values, $auto_date) &&
98 $this->deleteIdCentry() &&
99 $this->insertIdCentry();
100 }
101
102 /*
103 * module: centry_ps
104 * date: 2018-03-27 14:59:34
105 * version: 2.0.0
106 */
107 public function delete() {
108 return parent::delete() && $this->deleteIdCentry();
109 }
110
111 /*
112 * module: centry_ps
113 * date: 2018-03-27 14:59:34
114 * version: 2.0.0
115 */
116 private function deleteIdCentry() {
117 $sql = "DELETE FROM `" . _DB_PREFIX_ . static::$TABLE
118 . "` WHERE id_image = " . ((int) $this->id);
119 return Db::getInstance()->execute($sql) != false;
120 }
121
122 /*
123 * module: centry_ps
124 * date: 2018-03-27 14:59:34
125 * version: 2.0.0
126 */
127 private function insertIdCentry() {
128 $db = Db::getInstance();
129 $sql = "INSERT INTO `" . _DB_PREFIX_ . static::$TABLE
130 . "` (`id_image`, `id_centry`, `cover`, `content_type`,"
131 . " `file_name`, `file_size`, `fingerprint`, `created_at`,"
132 . " `updated_at`, `url`, `legend`)"
133 . " VALUES (" . ((int) $this->id) . ", '"
134 . $db->escape($this->id_centry) . "', '"
135 . $db->escape($this->cover) . "', '"
136 . $db->escape($this->content_type) . "', '"
137 . $db->escape($this->file_name) . "', '"
138 . $db->escape($this->file_size) . "', '"
139 . $db->escape($this->fingerprint) . "', '"
140 . $db->escape($this->created_at) . "', '"
141 . $db->escape($this->updated_at) . "', '"
142 . $db->escape($this->url) . "', '"
143 . $db->escape($this->legend) . "')";
144 return $db->execute($sql) != false;
145 }
146
147 /*
148 * module: centry_ps
149 * date: 2018-03-27 14:59:34
150 * version: 2.0.0
151 */
152 public static function createTable() {
153 $sql = "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . static::$TABLE . "`(
154 `id_image` INT(11) NOT NULL,
155 `id_centry` VARCHAR(200) NOT NULL,
156 `cover` BOOLEAN NOT NULL,
157 `content_type` VARCHAR(200) NOT NULL,
158 `file_name` VARCHAR(200) NOT NULL,
159 `file_size` VARCHAR(200) NOT NULL,
160 `fingerprint` VARCHAR(200) NOT NULL,
161 `created_at` VARCHAR(200) NOT NULL,
162 `updated_at` VARCHAR(200) NOT NULL,
163 `url` VARCHAR(200) NOT NULL,
164 `legend` VARCHAR(200) NOT NULL
165 )";
166 return Db::getInstance()->execute($sql);
167 }
168
169 /*
170 * module: centry_ps
171 * date: 2018-03-27 14:59:34
172 * version: 2.0.0
173 */
174 public static function dropTable() {
175 $sql = "DROP TABLE IF EXISTS `" . _DB_PREFIX_ . static::$TABLE . "`";
176 return Db::getInstance()->execute($sql);
177 }
178
179 /*
180 * module: centry_ps
181 * date: 2018-03-27 14:59:34
182 * version: 2.0.0
183 */
184 public static function findImageByIdCentry($id_centry) {
185 $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
186 $query = new DbQuery();
187 $query->select('id_image');
188 $query->from(static::$TABLE);
189 $query->where("id_centry = '" . $db->escape($id_centry) . "'");
190 return ($id = $db->getValue($query)) ? new Image($id) : false;
191 }
192}