diff --git a/classes/Customer.php b/classes/Customer.php index 752fd9605..7c4937eca 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -147,6 +147,7 @@ class CustomerCore extends ObjectModel 'fields' => array( 'id_default_group' => array('xlink_resource' => 'groups'), 'id_lang' => array('xlink_resource' => 'languages'), + 'id_country' => array('xlink_resource' => 'countries'), 'newsletter_date_add' => array(), 'ip_registration_newsletter' => array(), 'last_passwd_gen' => array('setter' => null), diff --git a/classes/RoomTypeSellingObject.php b/classes/RoomTypeSellingObject.php index 61b98b6be..3d93ccc6b 100644 --- a/classes/RoomTypeSellingObject.php +++ b/classes/RoomTypeSellingObject.php @@ -37,11 +37,65 @@ class RoomTypeSellingObjectCore extends ObjectModel 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), - 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), - 'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), + 'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), ), ); + protected $webserviceParameters = array( + 'objectsNodeName' => 'room_type_selling_objects', + 'objectNodeName' => 'room_type_selling_object', + 'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'), + 'fields' => array( + 'name' => array('required' => true), + 'plural_name' => array('required' => true), + 'active' => array('required' => false), + ), + ); + + /** + * Webservice: update, refusing to disable a selling object that is in use. + * + * @param bool $nullValues + * + * @return bool + * + * @throws WebserviceException + */ + public function updateWs($nullValues = false) + { + if (!$this->active && $this->id) { + $objOld = new RoomTypeSellingObject((int) $this->id); + if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot disable this selling object because it is currently assigned.'), + array(400, 400) + ); + } + } + + return $this->update($nullValues); + } + + /** + * Webservice: delete, refusing to delete a selling object that is in use. + * + * @return bool + * + * @throws WebserviceException + */ + public function deleteWs() + { + if ($this->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot delete this selling object because it is currently assigned.'), + array(400, 400) + ); + } + + return $this->delete(); + } + public function isUsed() { return (bool) Db::getInstance()->getValue( diff --git a/classes/webservice/WebserviceRequest.php b/classes/webservice/WebserviceRequest.php index ff62a66e5..068f3cae0 100644 --- a/classes/webservice/WebserviceRequest.php +++ b/classes/webservice/WebserviceRequest.php @@ -267,6 +267,7 @@ class WebserviceRequestCore 'contacts' => array('description' => 'Shop contacts','class' => 'Contact'), 'countries' => array('description' => 'The countries','class' => 'Country'), 'currencies' => array('description' => 'The currencies', 'class' => 'Currency'), + 'room_type_selling_objects' => array('description' => 'The room type selling objects', 'class' => 'RoomTypeSellingObject'), 'customers' => array('description' => 'The e-shop\'s customers','class' => 'Customer'), 'customer_threads' => array('description' => 'Customer services threads','class' => 'CustomerThread'), 'customer_messages' => array('description' => 'Customer services messages','class' => 'CustomerMessage'), diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index c32f4679c..5d33d64a9 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -106,6 +106,10 @@ class HotelBranchInformation extends ObjectModel 'required' => true, 'xlink_resource'=> 'countries', ), + 'id_property_type' => array( + 'required' => true, + 'xlink_resource'=> 'hotel_property_types', + ), 'id_state' => array( 'xlink_resource'=> 'states', ), diff --git a/modules/hotelreservationsystem/classes/HotelPropertyType.php b/modules/hotelreservationsystem/classes/HotelPropertyType.php index cbe87d79b..14dde5724 100644 --- a/modules/hotelreservationsystem/classes/HotelPropertyType.php +++ b/modules/hotelreservationsystem/classes/HotelPropertyType.php @@ -36,10 +36,63 @@ class HotelPropertyType extends ObjectModel 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), - 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), ), ); + protected $webserviceParameters = array( + 'objectsNodeName' => 'property_types', + 'objectNodeName' => 'property_type', + 'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'), + 'fields' => array( + 'name' => array('required' => true), + 'active' => array('required' => false), + ), + ); + + /** + * Webservice: update, refusing to disable a property type that is in use. + * + * @param bool $nullValues + * + * @return bool + * + * @throws WebserviceException + */ + public function updateWs($nullValues = false) + { + if (!$this->active && $this->id) { + $objOld = new HotelPropertyType((int) $this->id); + if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot disable this property type because it is currently assigned.'), + array(400, 400) + ); + } + } + + return $this->update($nullValues); + } + + /** + * Webservice: delete, refusing to delete a property type that is in use. + * + * @return bool + * + * @throws WebserviceException + */ + public function deleteWs() + { + if ($this->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot delete this property type because it is currently assigned.'), + array(400, 400) + ); + } + + return $this->delete(); + } + /** * Check if this property type is currently assigned to any property. * diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index 0d2e101c8..3a2e7b773 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -72,6 +72,11 @@ class HotelRoomType extends ObjectModel 'resourceName' => 'hotels', ) ), + 'id_selling_object' => array( + 'xlink_resource' => array( + 'resourceName' => 'room_type_selling_objects', + ) + ), ), 'associations' => array( 'hotel_rooms' => array( diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index f3530c665..ad105af85 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -48,6 +48,7 @@ class HotelReservationSystem extends Module $resources = array( 'hotels' => array('description' => 'Hotel Branch Information','class' => 'HotelBranchInformation'), 'hotel_room_types' => array('description' => 'Hotel room types','class' => 'HotelRoomType'), + 'property_types' => array('description' => 'Hotel property types', 'class' => 'HotelPropertyType'), 'hotel_amenities' => array('description' => 'The hotel amenities', 'class' => 'HotelAmenities'), 'hotel_refund_rules' => array('description' => 'The hotel refund rules','class' => 'HotelOrderRefundRules'), 'hotel_rooms' => array('description' => 'The hotel rooms','class' => 'HotelRoomInformation'),