@@ 159-213 (lines=55) @@ | ||
156 | * @param bool $force |
|
157 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
158 | */ |
|
159 | public function insert(&$hotelcity, $force = false) |
|
160 | { |
|
161 | if (strtolower(get_class($hotelcity)) !== 'martinhotelcity') { |
|
162 | return false; |
|
163 | } |
|
164 | ||
165 | if (!$hotelcity->cleanVars()) { |
|
166 | return false; |
|
167 | } |
|
168 | ||
169 | foreach ($hotelcity->cleanVars as $k => $v) { |
|
170 | ${$k} = $v; |
|
171 | } |
|
172 | ||
173 | if ($hotelcity->isNew()) { |
|
174 | $sql = sprintf("INSERT INTO %s ( |
|
175 | city_id, |
|
176 | city_parentid, |
|
177 | city_name, |
|
178 | city_alias, |
|
179 | city_level |
|
180 | ) VALUES ( |
|
181 | NULL, |
|
182 | %u, |
|
183 | %s, |
|
184 | %s, |
|
185 | %s |
|
186 | )", $this->db->prefix('martin_hotel_city'), $city_parentid, $this->db->quoteString($city_name), $this->db->quoteString($city_alias), $this->db->quoteString($city_level)); |
|
187 | } else { |
|
188 | $sql = sprintf("UPDATE %s SET |
|
189 | city_parentid = %u, |
|
190 | city_name = %s, |
|
191 | city_alias = %s, |
|
192 | city_level = %s |
|
193 | WHERE city_id = %u", $this->db->prefix('martin_hotel_city'), $city_parentid, $this->db->quoteString($city_name), $this->db->quoteString($city_alias), $this->db->quoteString($city_level), $city_id); |
|
194 | } |
|
195 | //echo "<br />" . $sql . "<br />"; |
|
196 | if (false != $force) { |
|
197 | $result = $this->db->queryF($sql); |
|
198 | } else { |
|
199 | $result = $this->db->query($sql); |
|
200 | } |
|
201 | if (!$result) { |
|
202 | $hotelcity->setErrors('The query returned an error. ' . $this->db->error()); |
|
203 | ||
204 | return false; |
|
205 | } |
|
206 | if ($hotelcity->isNew()) { |
|
207 | $hotelcity->assignVar('city_id', $this->db->getInsertId()); |
|
208 | } |
|
209 | ||
210 | $hotelcity->assignVar('city_id', $city_id); |
|
211 | ||
212 | return true; |
|
213 | } |
|
214 | ||
215 | /** |
|
216 | * @删除一个城市 |
@@ 163-217 (lines=55) @@ | ||
160 | * @param bool $force |
|
161 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
162 | */ |
|
163 | public function insert(&$hotelservice, $force = false) |
|
164 | { |
|
165 | if (strtolower(get_class($hotelservice)) !== 'martinhotelservice') { |
|
166 | return false; |
|
167 | } |
|
168 | ||
169 | if (!$hotelservice->cleanVars()) { |
|
170 | return false; |
|
171 | } |
|
172 | ||
173 | foreach ($hotelservice->cleanVars as $k => $v) { |
|
174 | ${$k} = $v; |
|
175 | } |
|
176 | ||
177 | if ($hotelservice->isNew()) { |
|
178 | $sql = sprintf("INSERT INTO %s ( |
|
179 | service_id, |
|
180 | service_type_id, |
|
181 | service_unit, |
|
182 | service_name, |
|
183 | service_instruction |
|
184 | ) VALUES ( |
|
185 | NULL, |
|
186 | %u, |
|
187 | %s, |
|
188 | %s, |
|
189 | %s |
|
190 | )", $this->db->prefix('martin_hotel_service'), $service_type_id, $this->db->quoteString($service_unit), $this->db->quoteString($service_name), $this->db->quoteString($service_instruction)); |
|
191 | } else { |
|
192 | $sql = sprintf("UPDATE %s SET |
|
193 | service_type_id = %u, |
|
194 | service_unit = %s, |
|
195 | service_name = %s, |
|
196 | service_instruction = %s |
|
197 | WHERE service_id = %u", $this->db->prefix('martin_hotel_service'), $service_type_id, $this->db->quoteString($service_unit), $this->db->quoteString($service_name), $this->db->quoteString($service_instruction), $service_id); |
|
198 | } |
|
199 | //echo "<br />" . $sql . "<br />"; |
|
200 | if (false != $force) { |
|
201 | $result = $this->db->queryF($sql); |
|
202 | } else { |
|
203 | $result = $this->db->query($sql); |
|
204 | } |
|
205 | if (!$result) { |
|
206 | $hotelservice->setErrors('The query returned an error. ' . $this->db->error()); |
|
207 | ||
208 | return false; |
|
209 | } |
|
210 | if ($hotelservice->isNew()) { |
|
211 | $hotelservice->assignVar('service_id', $this->db->getInsertId()); |
|
212 | } |
|
213 | ||
214 | $hotelservice->assignVar('service_id', $service_id); |
|
215 | ||
216 | return true; |
|
217 | } |
|
218 | ||
219 | /** |
|
220 | * @删除一个城市 |