1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* $Id: hotelservicetype.php,v 1.42 2007/02/04 15:01:40 malanciault Exp $ |
4
|
|
|
* Module:martin |
5
|
|
|
* Licence: GNU |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
if (!defined("XOOPS_ROOT_PATH")) { |
9
|
|
|
die("XOOPS root path not defined"); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/martin/include/common.php'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class MartinHotelServiceType |
16
|
|
|
*/ |
17
|
|
|
class MartinHotelServiceType extends XoopsObject |
18
|
|
|
{ |
19
|
|
|
public function MartinHotelServiceType() |
20
|
|
|
{ |
21
|
|
|
$this->initVar("service_type_id", XOBJ_DTYPE_INT, null, false); |
22
|
|
|
$this->initVar("service_type_name", XOBJ_DTYPE_TXTBOX, null, true, 255); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return mixed |
27
|
|
|
*/ |
28
|
|
|
public function service_type_id() |
29
|
|
|
{ |
30
|
|
|
return $this->getVar("service_type_id"); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $format |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
|
public function service_type_name($format = 'S') |
38
|
|
|
{ |
39
|
|
|
return $this->getVar("service_type_name", $format); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @method: hotelservicetypeHandler |
45
|
|
|
* @license http://www.blags.org/ |
46
|
|
|
* @created :2010年05月21日 20时40分 |
47
|
|
|
* @copyright 1997-2010 The Martin Group |
48
|
|
|
* @author Martin <[email protected]> |
49
|
|
|
* */ |
50
|
|
|
class MartinHotelServiceTypeHandler extends XoopsObjectHandler |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* create a new hotel city |
54
|
|
|
* @param bool $isNew flag the new objects as "new"? |
55
|
|
|
* @return object hotelservicetype |
56
|
|
|
*/ |
57
|
|
|
public function &create($isNew = true) |
58
|
|
|
{ |
59
|
|
|
$hotelservicetype = new MartinHotelServiceType(); |
60
|
|
|
if ($isNew) { |
61
|
|
|
$hotelservicetype->setNew(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $hotelservicetype; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* retrieve a hotel city |
69
|
|
|
* |
70
|
|
|
* @param int $id hotelservicetypeid of the hotelservicetype |
71
|
|
|
* @return mixed reference to the {@link hotelservicetype} object, FALSE if failed |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function &get($id) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
if ((int)($id) <= 0) { |
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$criteria = new CriteriaCompo(new Criteria('service_type_id', $id)); |
80
|
|
|
$criteria->setLimit(1); |
81
|
|
|
$obj_array = $this->getObjects($criteria); |
82
|
|
|
if (count($obj_array) != 1) { |
83
|
|
|
$obj =& $this->create(); |
84
|
|
|
|
85
|
|
|
return $obj; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $obj_array[0]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @得到列表 |
93
|
|
|
* @method: |
94
|
|
|
* @license http://www.blags.org/ |
95
|
|
|
* @created :2010年05月23日 14时59分 |
96
|
|
|
* @copyright 1997-2010 The Martin Group |
97
|
|
|
* @author Martin <[email protected]> |
98
|
|
|
* @param int $limit |
99
|
|
|
* @param int $start |
100
|
|
|
* @param string $sort |
101
|
|
|
* @param string $order |
102
|
|
|
* @param bool $id_as_key |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function &getHotelServiceTypes($limit = 0, $start = 0, $sort = 'service_type_id', $order = 'ASC', $id_as_key = true) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$criteria = new CriteriaCompo(); |
108
|
|
|
|
109
|
|
|
$criteria->setSort($sort); |
110
|
|
|
$criteria->setOrder($order); |
111
|
|
|
|
112
|
|
|
$criteria->setStart($start); |
113
|
|
|
$criteria->setLimit($limit); |
114
|
|
|
|
115
|
|
|
return $this->getObjects($criteria, $id_as_key); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* insert a new hotelservicetype in the database |
120
|
|
|
* |
121
|
|
|
* @param object $hotelservicetype reference to the {@link hotelservicetype} object |
122
|
|
|
* @param bool $force |
123
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
124
|
|
|
*/ |
125
|
|
|
public function insert(&$hotelservicetype, $force = false) |
126
|
|
|
{ |
127
|
|
|
if (strtolower(get_class($hotelservicetype)) !== 'martinhotelservicetype') { |
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (!$hotelservicetype->cleanVars()) { |
132
|
|
|
return false; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
foreach ($hotelservicetype->cleanVars as $k => $v) { |
136
|
|
|
${$k} = $v; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
View Code Duplication |
if ($hotelservicetype->isNew()) { |
|
|
|
|
140
|
|
|
$sql = sprintf("INSERT INTO %s ( |
141
|
|
|
service_type_id, |
142
|
|
|
service_type_name |
143
|
|
|
) VALUES ( |
144
|
|
|
NULL, |
145
|
|
|
%s |
146
|
|
|
)", $this->db->prefix('martin_hotel_service_type'), $this->db->quoteString($service_type_name)); |
|
|
|
|
147
|
|
|
} else { |
148
|
|
|
$sql = sprintf("UPDATE %s SET |
149
|
|
|
service_type_name = %s |
150
|
|
|
WHERE service_type_id = %u", $this->db->prefix('martin_hotel_service_type'), $this->db->quoteString($service_type_name), $service_type_id); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
//echo $sql;exit; |
153
|
|
|
if (false != $force) { |
|
|
|
|
154
|
|
|
$result = $this->db->queryF($sql); |
155
|
|
|
} else { |
156
|
|
|
$result = $this->db->query($sql); |
157
|
|
|
} |
158
|
|
|
if (!$result) { |
159
|
|
|
$hotelservicetype->setErrors('The query returned an error. ' . $this->db->error()); |
160
|
|
|
|
161
|
|
|
return false; |
162
|
|
|
} |
163
|
|
|
if ($hotelservicetype->isNew()) { |
164
|
|
|
$hotelservicetype->assignVar('service_type_id', $this->db->getInsertId()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$hotelservicetype->assignVar('service_type_id', $service_id); |
|
|
|
|
168
|
|
|
|
169
|
|
|
return true; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @删除一个城市 |
174
|
|
|
* @method:delete(service_id) |
175
|
|
|
* @license http://www.blags.org/ |
176
|
|
|
* @created :2010年05月21日 20时40分 |
177
|
|
|
* @copyright 1997-2010 The Martin Group |
178
|
|
|
* @author Martin <[email protected]> |
179
|
|
|
* @param object $hotelservicetype |
180
|
|
|
* @param bool $force |
181
|
|
|
* @return bool|void |
182
|
|
|
*/ |
183
|
|
View Code Duplication |
public function delete(&$hotelservicetype, $force = false) |
|
|
|
|
184
|
|
|
{ |
185
|
|
|
if (strtolower(get_class($hotelservicetype)) !== 'martinhotelservicetype') { |
186
|
|
|
return false; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$sql = "DELETE FROM " . $this->db->prefix("martin_hotel_service_type") . " WHERE service_type_id = " . $hotelservicetype->service_type_id(); |
190
|
|
|
|
191
|
|
|
if (false != $force) { |
|
|
|
|
192
|
|
|
$result = $this->db->queryF($sql); |
193
|
|
|
} else { |
194
|
|
|
$result = $this->db->query($sql); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if (!$result) { |
198
|
|
|
return false; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
return true; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* delete hotel cities matching a set of conditions |
206
|
|
|
* |
207
|
|
|
* @param object $criteria {@link CriteriaElement} |
|
|
|
|
208
|
|
|
* @return bool FALSE if deletion failed |
209
|
|
|
*/ |
210
|
|
View Code Duplication |
public function deleteAll($criteria = null) |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$sql = 'DELETE FROM ' . $this->db->prefix('martin_hotel_service_type'); |
213
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
214
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
215
|
|
|
} |
216
|
|
|
if (!$result = $this->db->query($sql)) { |
217
|
|
|
return false; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return true; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* count hotel cities matching a condition |
225
|
|
|
* |
226
|
|
|
* @param object $criteria {@link CriteriaElement} to match |
|
|
|
|
227
|
|
|
* @return int count of categories |
228
|
|
|
*/ |
229
|
|
View Code Duplication |
public function getCount($criteria = null) |
|
|
|
|
230
|
|
|
{ |
231
|
|
|
$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('martin_hotel_service_type'); |
232
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
233
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
234
|
|
|
} |
235
|
|
|
$result = $this->db->query($sql); |
236
|
|
|
if (!$result) { |
237
|
|
|
return 0; |
238
|
|
|
} |
239
|
|
|
list($count) = $this->db->fetchRow($result); |
240
|
|
|
|
241
|
|
|
return $count; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @得到城市 |
246
|
|
|
* @license http://www.blags.org/ |
247
|
|
|
* @created :2010年05月21日 20时40分 |
248
|
|
|
* @copyright 1997-2010 The Martin Group |
249
|
|
|
* @author Martin <[email protected]> |
250
|
|
|
* @param null $criteria |
251
|
|
|
* @param bool $id_as_key |
252
|
|
|
* @return array |
253
|
|
|
*/ |
254
|
|
View Code Duplication |
public function &getObjects($criteria = null, $id_as_key = false) |
|
|
|
|
255
|
|
|
{ |
256
|
|
|
$ret = array(); |
257
|
|
|
$limit = $start = 0; |
258
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('martin_hotel_service_type'); |
259
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
|
|
|
260
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
261
|
|
|
if ($criteria->getSort() != '') { |
262
|
|
|
$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
263
|
|
|
} |
264
|
|
|
$limit = $criteria->getLimit(); |
265
|
|
|
$start = $criteria->getStart(); |
266
|
|
|
} |
267
|
|
|
//echo "<br />" . $sql . "<br />"; |
268
|
|
|
$result = $this->db->query($sql, $limit, $start); |
269
|
|
|
|
270
|
|
|
if (!$result) { |
271
|
|
|
return $ret; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
$theObjects = array(); |
275
|
|
|
|
276
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
277
|
|
|
$hotelservicetype = new MartinHotelServiceType(); |
278
|
|
|
$hotelservicetype->assignVars($myrow); |
279
|
|
|
$theObjects[$myrow['service_type_id']] =& $hotelservicetype; |
280
|
|
|
//var_dump($hotelservicetype); |
281
|
|
|
unset($hotelservicetype); |
282
|
|
|
} |
283
|
|
|
//var_dump($theObjects); |
284
|
|
|
|
285
|
|
|
foreach ($theObjects as $theObject) { |
286
|
|
|
if (!$id_as_key) { |
287
|
|
|
$ret[] =& $theObject; |
288
|
|
|
} else { |
289
|
|
|
$ret[$theObject->service_type_id()] =& $theObject; |
290
|
|
|
} |
291
|
|
|
unset($theObject); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
return $ret; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @得到类别列表 |
299
|
|
|
* @license http://www.blags.org/ |
300
|
|
|
* @created :2010年05月30日 20时48分 |
301
|
|
|
* @copyright 1997-2010 The Martin Group |
302
|
|
|
* @author Martin <[email protected]> |
303
|
|
|
* */ |
304
|
|
View Code Duplication |
public function GetList() |
|
|
|
|
305
|
|
|
{ |
306
|
|
|
$sql = "SELECT * FROM " . $this->db->prefix("martin_hotel_service_type"); |
307
|
|
|
$result = $this->db->query($sql); |
308
|
|
|
$rows = array(); |
309
|
|
|
while ($row = $this->db->fetchArray($result)) { |
310
|
|
|
$rows[$row['service_type_id']] = $row['service_type_name']; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
return $rows; |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.