PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/www/applications/hotels/models/model.hotels.php

https://github.com/triartdesign/tudestino
PHP | 796 lines | 793 code | 0 blank | 3 comment | 1 complexity | 5e9c0824a98c9501bdabc07e16442674 MD5 | raw file
  1. <?php
  2. /**
  3. * Access from index.php:
  4. */
  5. if(!defined("_access")) {
  6. die("Error: You don't have permission to access here...");
  7. }
  8. class Hotels_Model extends ZP_Model {
  9. private $route;
  10. private $table;
  11. private $primaryKey;
  12. public $ID_Hotel;
  13. public function __construct() {
  14. $this->Db = $this->db();
  15. $helpers = array("alerts", "router", "time", "string");
  16. $this->helper($helpers);
  17. $this->language = whichLanguage();
  18. $this->table = "hotels";
  19. }
  20. public function cpanel($action, $limit = NULL, $order = "Language DESC", $search = NULL, $field = NULL, $trash = FALSE) {
  21. $this->Db->table($this->table);
  22. if($action === "edit" or $action === "save") {
  23. $validation = $this->editOrSave($action);
  24. if($validation) {
  25. return $validation;
  26. }
  27. }
  28. if($action === "all") {
  29. return $this->all($trash, $order, $limit);
  30. } elseif($action === "edit") {
  31. return $this->edit();
  32. } elseif($action === "save") {
  33. return $this->save();
  34. } elseif($action === "search") {
  35. return $this->search($search, $field);
  36. }
  37. }
  38. public function all($trash = FALSE, $order = "Language DESC", $limit = NULL) {
  39. $this->Db->table($this->table);
  40. if(!$trash) {
  41. if(SESSION("ZanUserPrivilege") === _super) {
  42. $data = $this->Db->findBySQL("Situation != 'Deleted'", NULL, $order, $limit);
  43. } else {
  44. $data = $this->Db->findBySQL("ID_User = '". SESSION("ZanUserID") ."' AND Situation != 'Deleted'", NULL, $order, $limit);
  45. }
  46. } else {
  47. if(SESSION("ZanUserPrivilege") === _super) {
  48. $data = $this->Db->findBy("Situation", "Deleted", NULL, $order, $limit);
  49. } else {
  50. $data = $this->Db->findBySQL("ID_User = '". SESSION("ZanUserID") ."' AND Situation = 'Deleted'", NULL, $order, $limit);
  51. }
  52. }
  53. return $data;
  54. }
  55. private function editOrSave($action) {
  56. $validations = $this->validations();
  57. if($validations) {
  58. return $validations;
  59. }
  60. $this->setData();
  61. }
  62. private function validations() {
  63. if(is_null(POST("name"))) {
  64. return getAlert("You need to write a name");
  65. } elseif(is_null(POST("description"))) {
  66. return getAlert("You need to write a description");
  67. } elseif(is_null(POST("address"))) {
  68. return getAlert("You need to write a address");
  69. } elseif(is_null(POST("country"))) {
  70. return getAlert("You need to write a country");
  71. } elseif(is_null(POST("district"))) {
  72. return getAlert("You need to write a district");
  73. } elseif(is_null(POST("town"))) {
  74. return getAlert("You need to write a town");
  75. } elseif(is_null(POST("telephone"))) {
  76. return getAlert("You need to write a telephone");
  77. } elseif(POST("hotels") !== "0") {
  78. if(POST("save") === "save") {
  79. if($this->exists(POST("hotels"), POST("language")) or $this->existsParent(POST("hotels"), POST("language"))) {
  80. return getAlert("This hotel already exists");
  81. }
  82. }
  83. }
  84. return FALSE;
  85. }
  86. private function setData() {
  87. $this->ID_Parent = POST("hotels");
  88. $this->name = POST("name");
  89. $this->description = POST("description");
  90. $this->slug = slug(POST("name", "clean"));
  91. $this->category = POST("category");
  92. $this->email = POST("email");
  93. $this->address = POST("address");
  94. $this->country = POST("country");
  95. $this->district = POST("district");
  96. $this->town = POST("town");
  97. $this->city = POST("city");
  98. $this->zipCode = POST("zip_code");
  99. $this->telephone = POST("telephone");
  100. $this->area = POST("area");
  101. $this->website = POST("website");
  102. $this->latitude = POST("lat");
  103. $this->longitude = POST("lng");
  104. $this->language = POST("language");
  105. $this->author = SESSION("ZanUser");
  106. $this->date1 = now(4);
  107. $this->date2 = now(2);
  108. }
  109. private function setDataInformation() {
  110. $this->roomNumber = POST("room_number");
  111. $this->yearConstruction = POST("year_construction");
  112. $this->yearRemodelation = POST("year_remodelation");
  113. $this->agencyCommision = POST("agency_commision");
  114. $this->inTime = POST("in_time");
  115. $this->outTime = POST("out_time");
  116. $this->maxYearChildren = POST("max_year_children");
  117. $this->minDaysReservation = POST("min_days_reservation");
  118. $this->daysPrevReservation = POST("days_prev_reservation");
  119. $this->daysPrevCancelation = POST("days_prev_cancelation");
  120. $this->airport = POST("airport", "decode", FALSE);
  121. $this->nearCities = POST("near_cities", "decode", FALSE);
  122. $this->cityActivities = POST("city_activities", "decode", FALSE);
  123. $this->hotelActivities = POST("hotel_activities", "decode", FALSE);
  124. $this->hotelNearActivities = POST("hotel_near_activities", "decode", FALSE);
  125. $this->restaurantsBar = POST("restaurants_bar", "decode", FALSE);
  126. $this->roomsInformation = POST("rooms_information", "decode", FALSE);
  127. $this->hotelUbication = POST("hotel_ubication", "decode", FALSE);
  128. $this->ratesInformation = POST("rates_information", "decode", FALSE);
  129. }
  130. private function setDataPolitics() {
  131. $this->cancellationPolicy = POST("cancellation_policy", "decode", FALSE);
  132. $this->noArrivalPolicy = POST("no_arrival_policy", "decode", FALSE);
  133. $this->extraPersonPolicy = POST("extra_person_policy", "decode", FALSE);
  134. $this->childrenPolicy = POST("children_policy", "decode", FALSE);
  135. $this->petsPolicy = POST("pets_policy", "decode", FALSE);
  136. $this->prePolicy = POST("pre_policy", "decode", FALSE);
  137. }
  138. private function setDataContacts() {
  139. $this->contactManager = POST("contact_manager", "decode", FALSE);
  140. $this->contactPrincipal = POST("contact_principal", "decode", FALSE);
  141. $this->contactAccouting = POST("contact_accouting", "decode", FALSE);
  142. $this->contactReservation = POST("contact_reservation", "decode", FALSE);
  143. $this->contactProperty = POST("contact_property", "decode", FALSE);
  144. }
  145. private function save() {
  146. $ID_Hotel = $this->saveHotel();
  147. if($ID_Hotel) {
  148. $insertID = $this->saveInformation($ID_Hotel);
  149. if($insertID) {
  150. $insertID2 = $this->savePolitics($ID_Hotel);
  151. if($insertID2) {
  152. $insertID3 = $this->saveConctacts($ID_Hotel);
  153. if($insertID3) {
  154. return getAlert("The hotel has been saved correctly", "success");
  155. } else {
  156. return getAlert("Insert error");
  157. }
  158. } else {
  159. return getAlert("Insert error");
  160. }
  161. } else {
  162. return getAlert("Insert error");
  163. }
  164. } else {
  165. return getAlert("Insert error");
  166. }
  167. }
  168. private function saveHotel() {
  169. $values = array(
  170. "Name" => $this->name,
  171. "ID_Parent" => $this->ID_Parent,
  172. "Slug" => $this->slug,
  173. "Category" => $this->category,
  174. "Emails_Reservation" => $this->email,
  175. "Address" => $this->address,
  176. "Country" => $this->country,
  177. "District" => $this->district,
  178. "Town" => $this->town,
  179. "City" => $this->city,
  180. "Zip_Code" => $this->zipCode,
  181. "Telephone" => $this->telephone,
  182. "Area" => $this->area,
  183. "Website" => $this->website,
  184. "Latitude" => $this->latitude,
  185. "Longitude" => $this->longitude,
  186. "Author" => $this->author,
  187. "Start_Date" => $this->date1,
  188. "Text_Date" => $this->date2,
  189. "Language" => $this->language
  190. );
  191. return $this->Db->insert($this->table, $values);
  192. }
  193. private function saveInformation($ID_Hotel) {
  194. $this->setDataInformation();
  195. $values = array(
  196. "ID_Hotel" => $ID_Hotel,
  197. "Room_Number" => $this->roomNumber,
  198. "Year_Construction" => $this->yearConstruction,
  199. "Year_Remodelation" => $this->yearRemodelation,
  200. "Agency_Commision" => $this->agencyCommision,
  201. "In_Time" => $this->inTime,
  202. "Out_Time" => $this->outTime,
  203. "Max_Year_Children" => $this->maxYearChildren,
  204. "Min_Days_Reservation" => $this->minDaysReservation,
  205. "Days_Prev_Reservation" => $this->daysPrevReservation,
  206. "Days_Prev_Cancelation" => $this->daysPrevCancelation,
  207. "Airport" => $this->airport,
  208. "Near_Citys" => $this->nearCities,
  209. "City_Activities" => $this->cityActivities,
  210. "Hotel_Activities" => $this->hotelActivities,
  211. "Hotel_Near_Activities" => $this->hotelNearActivities,
  212. "Restaurants_Bar" => $this->restaurantsBar,
  213. "Rooms_Information" => $this->roomsInformation,
  214. "Hotel_Ubication" => $this->hotelUbication,
  215. "Rates_Information" => $this->ratesInformation
  216. );
  217. return $this->Db->insert("hotels_information", $values);
  218. }
  219. private function savePolitics($ID_Hotel) {
  220. $this->setDataPolitics();
  221. $values = array(
  222. "ID_Hotel" => $ID_Hotel,
  223. "Cancellation_Policy" => $this->cancellationPolicy,
  224. "No_Arrival_Policy" => $this->noArrivalPolicy,
  225. "Extra_Person_Policy" => $this->extraPersonPolicy,
  226. "Childrens_Policy" => $this->childrenPolicy,
  227. "Pets_Policy" => $this->petsPolicy,
  228. "Pre_Policy" => $this->prePolicy
  229. );
  230. return $this->Db->insert("hotels_policy", $values);
  231. }
  232. private function saveConctacts($ID_Hotel) {
  233. $this->setDataContacts();
  234. $values = array(
  235. "ID_Hotel" => $ID_Hotel,
  236. "Contact_Manager" => $this->contactManager,
  237. "Contact_Principal" => $this->contactPrincipal,
  238. "Contact_Accounting" => $this->contactAccouting,
  239. "Contact_Reservation" => $this->contactReservation,
  240. "Contact_Property" => $this->contactProperty
  241. );
  242. return $this->Db->insert("hotels_contacts", $values);
  243. }
  244. public function saveRoom() {
  245. $validations = $this->validationRoom();
  246. if($validations) {
  247. return $validations;
  248. }
  249. $values = array(
  250. "Name" => POST("name"),
  251. "Slug" => slug(POST("name", "clean")),
  252. "Bed_Type" => POST("bed_type"),
  253. "Max_Occupation" => POST("max_occupation"),
  254. "Number_Rooms" => POST("number_rooms"),
  255. "Description" => POST("description"),
  256. "Language" => POST("language")
  257. );
  258. $ID_Room = $this->Db->insert("hotels_rooms", $values);
  259. if($ID_Room) {
  260. $this->Db->insert("re_hotels_rooms", array("ID_Room" => $ID_Room, "ID_Hotel" => POST("hotels")));
  261. return getAlert("The Room has been saved correctly", "success");
  262. } else {
  263. return getAlert("Insert error");
  264. }
  265. }
  266. private function validationRoom() {
  267. if(is_null(POST("name"))) {
  268. return getAlert("You need to write a name");
  269. } elseif(is_null(POST("bed_type"))) {
  270. return getAlert("You need to write a bed type");
  271. } elseif(is_null(POST("max_occupation"))) {
  272. return getAlert("You need to write a max ocupation");
  273. } elseif(is_null(POST("number_rooms"))) {
  274. return getAlert("You need to write a number rooms");
  275. } elseif(is_null(POST("description"))) {
  276. return getAlert("You need to write a description");
  277. }
  278. return FALSE;
  279. }
  280. public function saveAmenity() {
  281. if(is_array(POST("amenities"))) {
  282. $this->deleteAmenitiesByHotel(POST("hotels"));
  283. foreach(POST("amenities") as $amenity) {
  284. $this->Db->insert("re_hotels_amenities", array("ID_Amenity" => $amenity, "ID_Hotel" => POST("hotels")));
  285. }
  286. return getAlert("The Amenities have been saved correctly", "success");
  287. }
  288. $validations = $this->validationAmenity();
  289. if($validations) {
  290. return $validations;
  291. }
  292. $values = array(
  293. "Name" => POST("name"),
  294. "Slug" => slug(POST("name", "clean")),
  295. "Image" => $this->image,
  296. "Language" => POST("language")
  297. );
  298. $ID_Amenity = $this->Db->insert("hotels_amenities", $values);
  299. if($ID_Amenity) {
  300. $this->Db->insert("re_hotels_amenities", array("ID_Amenity" => $ID_Amenity, "ID_Hotel" => POST("hotels")));
  301. return getAlert("The Amenity has been saved correctly", "success");
  302. } else {
  303. return getAlert("Insert error");
  304. }
  305. }
  306. private function validationAmenity() {
  307. if(is_null(POST("name"))) {
  308. return getAlert("You need to write a name");
  309. } elseif($this->existsAmenity(slug(POST("name", "clean")), POST("language"))) {
  310. return getAlert("This amenity already exists");
  311. }
  312. $this->Files = $this->core("Files");
  313. $this->image = NULL;
  314. $file = FILES("image");
  315. if($file["name"] !== "") {
  316. $dir = _www . _sh . _lib . _sh . _files . _sh . _images . _sh . "amenities" . _sh;
  317. $this->image = $this->Files->uploadImage($dir, "image", "normal");
  318. if(is_array($this->image) or !$this->image) {
  319. $this->image = NULL;
  320. }
  321. }
  322. return FALSE;
  323. }
  324. public function saveRate() {
  325. $validations = $this->validationRate();
  326. if($validations) {
  327. return $validations;
  328. }
  329. $values = array(
  330. "Start_Date" => strtotime(POST("startdate")),
  331. "End_Date" => strtotime(POST("enddate")),
  332. "Start_Date_Text" => POST("startdate"),
  333. "End_Date_Text" => POST("enddate"),
  334. "Name" => POST("name"),
  335. "Cost" => POST("cost"),
  336. "Language" => POST("language")
  337. );
  338. $ID_Rate = $this->Db->insert("hotels_rates", $values);
  339. if($ID_Rate) {
  340. $this->Db->insert("re_hotels_rates", array("ID_Rate" => $ID_Rate, "ID_Hotel" => POST("hotels")));
  341. return getAlert("The Amenity has been saved correctly", "success");
  342. } else {
  343. return getAlert("Insert error");
  344. }
  345. }
  346. private function validationRate($edit = FALSE) {
  347. if(is_null(POST("startdate"))) {
  348. return getAlert("You need to write a start date");
  349. } elseif(is_null(POST("enddate"))) {
  350. return getAlert("You need to write a end date");
  351. } elseif(is_null(POST("name"))) {
  352. return getAlert("You need to write a name");
  353. } elseif(is_null(POST("cost"))) {
  354. return getAlert("You need to write a cost");
  355. }
  356. if(!$edit) {
  357. if(POST("hotels") == "0") {
  358. return getAlert("You need to select a hotel");
  359. }
  360. }
  361. return FALSE;
  362. }
  363. public function edit() {
  364. $response = $this->editHotel($this->ID_Hotel);
  365. if($response) {
  366. $response = $this->editInformation($this->ID_Hotel);
  367. if($response) {
  368. $response = $this->editPolitics($this->ID_Hotel);
  369. if($response) {
  370. $response = $this->editConctacts($this->ID_Hotel);
  371. if($response) {
  372. return TRUE;
  373. } else {
  374. return getAlert("Edit error");
  375. }
  376. } else {
  377. return getAlert("Edit error");
  378. }
  379. } else {
  380. return getAlert("Edit error");
  381. }
  382. } else {
  383. return getAlert("Edit error");
  384. }
  385. }
  386. private function editHotel($ID_Hotel = 0) {
  387. $values = array(
  388. "Name" => $this->name,
  389. "Slug" => $this->slug,
  390. "Category" => $this->category,
  391. "Emails_Reservation" => $this->email,
  392. "Address" => $this->address,
  393. "Country" => $this->country,
  394. "District" => $this->district,
  395. "Town" => $this->town,
  396. "City" => $this->city,
  397. "Zip_Code" => $this->zipCode,
  398. "Telephone" => $this->telephone,
  399. "Area" => $this->area,
  400. "Website" => $this->website,
  401. "Latitude" => $this->latitude,
  402. "Longitude" => $this->longitude,
  403. "Language" => $this->language
  404. );
  405. return $this->Db->update($this->table, $values, "ID_Hotel = " . $ID_Hotel);
  406. }
  407. private function editInformation($ID_Hotel = 0) {
  408. $this->setDataInformation();
  409. $values = array(
  410. "Room_Number" => $this->roomNumber,
  411. "Year_Construction" => $this->yearConstruction,
  412. "Year_Remodelation" => $this->yearRemodelation,
  413. "Agency_Commision" => $this->agencyCommision,
  414. "In_Time" => $this->inTime,
  415. "Out_Time" => $this->outTime,
  416. "Max_Year_Children" => $this->maxYearChildren,
  417. "Min_Days_Reservation" => $this->minDaysReservation,
  418. "Days_Prev_Reservation" => $this->daysPrevReservation,
  419. "Days_Prev_Cancelation" => $this->daysPrevCancelation,
  420. "Airport" => $this->airport,
  421. "Near_Citys" => $this->nearCities,
  422. "City_Activities" => $this->cityActivities,
  423. "Hotel_Activities" => $this->hotelActivities,
  424. "Hotel_Near_Activities" => $this->hotelNearActivities,
  425. "Restaurants_Bar" => $this->restaurantsBar,
  426. "Rooms_Information" => $this->roomsInformation,
  427. "Hotel_Ubication" => $this->hotelUbication,
  428. "Rates_Information" => $this->ratesInformation
  429. );
  430. return $this->Db->update("hotels_information", $values, "ID_Hotel = " . $ID_Hotel);
  431. }
  432. private function editPolitics($ID_Hotel = 0) {
  433. $this->setDataPolitics();
  434. $values = array(
  435. "Cancellation_Policy" => $this->cancellationPolicy,
  436. "No_Arrival_Policy" => $this->noArrivalPolicy,
  437. "Extra_Person_Policy" => $this->extraPersonPolicy,
  438. "Childrens_Policy" => $this->childrenPolicy,
  439. "Pets_Policy" => $this->petsPolicy,
  440. "Pre_Policy" => $this->prePolicy
  441. );
  442. return $this->Db->update("hotels_policy", $values, "ID_Hotel = " . $ID_Hotel);
  443. }
  444. private function editConctacts($ID_Hotel = 0) {
  445. $this->setDataContacts();
  446. $values = array(
  447. "Contact_Manager" => $this->contactManager,
  448. "Contact_Principal" => $this->contactPrincipal,
  449. "Contact_Accounting" => $this->contactAccouting,
  450. "Contact_Reservation" => $this->contactReservation,
  451. "Contact_Property" => $this->contactProperty
  452. );
  453. return $this->Db->update("hotels_contacts", $values, "ID_Hotel = " . $ID_Hotel);
  454. }
  455. public function editRate($ID) {
  456. $validations = $this->validationRate(TRUE);
  457. if($validations) {
  458. return $validations;
  459. }
  460. $values = array(
  461. "Start_Date" => strtotime(POST("startdate")),
  462. "End_Date" => strtotime(POST("enddate")),
  463. "Start_Date_Text" => POST("startdate"),
  464. "End_Date_Text" => POST("enddate"),
  465. "Name" => POST("name"),
  466. "Cost" => POST("cost"),
  467. "Language" => POST("language")
  468. );
  469. $response = $this->Db->update("hotels_rates", $values, "ID_Rate = $ID");
  470. if($response) {
  471. return getAlert("The rate has been edited correctly", "success");
  472. } else {
  473. return getAlert("Edit error");
  474. }
  475. }
  476. public function editRoom($ID) {
  477. $validations = $this->validationRoom();
  478. if($validations) {
  479. return $validations;
  480. }
  481. $values = array(
  482. "Name" => POST("name"),
  483. "Slug" => slug(POST("name", "clean")),
  484. "Bed_Type" => POST("bed_type"),
  485. "Max_Occupation" => POST("max_occupation"),
  486. "Number_Rooms" => POST("number_rooms"),
  487. "Description" => POST("description"),
  488. "Language" => POST("language")
  489. );
  490. $response = $this->Db->update("hotels_rooms", $values, "ID_Room = $ID");
  491. if($response) {
  492. return getAlert("The room has been edited correctly", "success");
  493. } else {
  494. return getAlert("Edit error");
  495. }
  496. }
  497. public function getHotel($ID) {
  498. $this->Db->table($this->table);
  499. $result = $this->Db->findBy("ID_Hotel",$ID);
  500. if(!$result) {
  501. return false;
  502. }
  503. $data["hotel"] = $result[0];
  504. $data["information"] = $this->getHotelInformation($ID);
  505. $data["contacts"] = $this->getHotelContacts($ID);
  506. $data["policy"] = $this->getHotelPolicy($ID);
  507. return $data;
  508. }
  509. public function getHotelInformation($ID) {
  510. $this->Db->table("hotels_information");
  511. $data = $this->Db->findBy("ID_Hotel",$ID);
  512. return ($data) ? $data[0] : FALSE;
  513. }
  514. public function getHotelContacts($ID) {
  515. $this->Db->table("hotels_contacts");
  516. $data = $this->Db->findBy("ID_Hotel",$ID);
  517. return ($data) ? $data[0] : FALSE;
  518. }
  519. public function getHotelPolicy($ID) {
  520. $this->Db->table("hotels_policy");
  521. $data = $this->Db->findBy("ID_Hotel",$ID);
  522. return ($data) ? $data[0] : FALSE;
  523. }
  524. public function getParents($situation = "Active") {
  525. $this->Db->table($this->table, "ID_Hotel, ID_Parent, Name, Language");
  526. return $this->Db->findBy(array("Situation" => $situation, "ID_Parent" => "0"));
  527. }
  528. public function getBySituation($situation = "Active") {
  529. $this->Db->table($this->table, "ID_Hotel, ID_Parent, Name, Category, Telephone, City, Language");
  530. return $this->Db->findBySQL("Situation = '$situation'", NULL, "Name Desc");
  531. }
  532. public function getByID($ID) {
  533. $this->Db->table($this->table, "ID_Hotel, ID_Parent, Name, Language");
  534. return $this->Db->findBy("ID_Hotel",$ID);
  535. }
  536. public function getAllAmenities($situation = "Active") {
  537. $this->Db->table("hotels_amenities");
  538. return $this->Db->findBySQL("Situation = '$situation'", NULL, "Name Desc");
  539. }
  540. public function getRates($ID) {
  541. $this->Db->table("hotels_rates");
  542. return $this->Db->findBySQL("ID_Rate IN (SELECT ID_Rate FROM muu_re_hotels_rates WHERE ID_Hotel = '$ID')");
  543. }
  544. public function getRooms($ID) {
  545. $this->Db->table("hotels_rooms");
  546. return $this->Db->findBySQL("ID_Room IN (SELECT ID_Room FROM muu_re_hotels_rooms WHERE ID_Hotel = '$ID')");
  547. }
  548. public function getRoom($ID) {
  549. $this->Db->table("hotels_rooms");
  550. return $this->Db->findBy("ID_Room", $ID);
  551. }
  552. public function getAmenitiesByHotel($ID, $array = FALSE) {
  553. $this->Db->table("hotels_amenities", "ID_Amenity");
  554. $data = $this->Db->findBySQL("ID_Amenity IN (SELECT ID_Amenity FROM muu_re_hotels_amenities WHERE ID_Hotel = '$ID')");
  555. if($data) {
  556. if(!$array) {
  557. foreach($data as $record) {
  558. $_data[] = $record["ID_Amenity"];
  559. }
  560. return $_data;
  561. } else {
  562. return $data;
  563. }
  564. } else {
  565. return FALSE;
  566. }
  567. }
  568. public function trash($ID) {
  569. return $this->Db->update("hotels", array("Situation" => "Delete"), "ID_Hotel = $ID");
  570. }
  571. public function delete($ID) {
  572. $this->Db->table("hotels");
  573. return $this->Db->deleteBy("ID_Hotel", $ID, NULL);
  574. }
  575. public function restore($ID) {
  576. return $this->Db->update("hotels", array("Situation" => "Active"), "ID_Hotel = $ID");
  577. }
  578. public function deleteRate($ID) {
  579. $this->Db->table("re_hotels_rates");
  580. $this->Db->deleteBy("ID_Rate", $ID, NULL);
  581. $this->Db->table("hotels_rates");
  582. return $this->Db->deleteBy("ID_Rate", $ID, NULL);
  583. }
  584. public function deleteRoom($ID) {
  585. $this->Db->table("re_hotels_rooms");
  586. $this->Db->deleteBy("ID_Room", $ID, NULL);
  587. $this->Db->table("hotels_room");
  588. return $this->Db->deleteBy("ID_Room", $ID, NULL);
  589. }
  590. public function getRate($ID) {
  591. $this->Db->table("hotels_rates");
  592. return $this->Db->findBy("ID_Rate", $ID);
  593. }
  594. public function slug($slug = NULL) {
  595. $this->Db->table($this->table);
  596. $query = "SELECT muu_hotels.*, muu_hotels_information.* FROM muu_hotels ";
  597. $query .= "LEFT JOIN muu_hotels_information ON muu_hotels.ID_Hotel = muu_hotels_information.ID_Hotel ";
  598. $query .= "LEFT JOIN muu_hotels_contacts ON muu_hotels.ID_Hotel = muu_hotels_contacts.ID_Hotel ";
  599. $query .= "LEFT JOIN muu_hotels_policy ON muu_hotels.ID_Hotel = muu_hotels_policy.ID_Hotel ";
  600. $query .= "WHERE muu_hotels.Slug = '$slug' AND muu_hotels.Situation = 'Active' LIMIT 1";
  601. $data = $this->Db->query($query);
  602. return ($data) ? $data[0] : FALSE;
  603. }
  604. public function ID($ID = NULL) {
  605. $this->Db->table($this->table);
  606. $query = "SELECT muu_hotels.*, muu_hotels_information.* FROM muu_hotels ";
  607. $query .= "LEFT JOIN muu_hotels_information ON muu_hotels.ID_Hotel = muu_hotels_information.ID_Hotel ";
  608. $query .= "LEFT JOIN muu_hotels_contacts ON muu_hotels.ID_Hotel = muu_hotels_contacts.ID_Hotel ";
  609. $query .= "LEFT JOIN muu_hotels_policy ON muu_hotels.ID_Hotel = muu_hotels_policy.ID_Hotel ";
  610. $query .= "WHERE muu_hotels.ID_Hotel = $ID AND muu_hotels.Situation = 'Active'";
  611. $data = $this->Db->query($query);
  612. return ($data) ? $data[0] : FALSE;
  613. }
  614. public function rooms($slug = NUll) {
  615. if(!is_numeric($slug)) {
  616. $ID = $this->getID($slug);
  617. } else {
  618. $ID = $slug;
  619. }
  620. $this->Db->table("re_hotels_rooms", "ID_Room");
  621. $query = "SELECT * FROM muu_hotels_rooms WHERE ID_Room IN ";
  622. $query .= "(SELECT ID_Room FROM muu_re_hotels_rooms WHERE ID_Hotel = $ID)";
  623. return $this->Db->query($query);
  624. }
  625. public function getID($slug = NULL) {
  626. $this->Db->table($this->table, "ID_Hotel");
  627. $data = $this->Db->findBy(array("Slug" => $slug, "Situation" => "Active"));
  628. return ($data) ? $data[0]["ID_Hotel"] : FALSE;
  629. }
  630. private function exists($ID, $language = "Spanish") {
  631. $this->Db->table($this->table, "ID_Hotel");
  632. return $this->Db->findBy(array("ID_Hotel" => $ID, "Language" => $language));
  633. }
  634. private function existsAmenity($slug, $language = "Spanish") {
  635. $this->Db->table("hotels_amenities", "ID_Amenity");
  636. return $this->Db->findBy(array("Slug" => $slug, "Language" => $language));
  637. }
  638. private function existsParent($ID, $language = "Spanish") {
  639. $this->Db->table($this->table, "ID_Hotel");
  640. return $this->Db->findBy(array("ID_Parent" => $ID, "Language" => $language));
  641. }
  642. private function search($search, $field) {
  643. $this->CPanel_Model = $this->model("Cpanel_Model");
  644. return $this->Cpanel_Model->getSearch(getDecode($search), $field, _tLinks);
  645. }
  646. private function deleteAmenitiesByHotel($ID) {
  647. $this->Db->table("re_hotels_amenities");
  648. return $this->Db->deleteBy("ID_Hotel", $ID, NULL);
  649. }
  650. }