Validation added for Invalid data inserted in 'special_days' field in _DB_PEFIX_htl_room_type_feature_pricing table through webservice API.
This commit is contained in:
@@ -48,7 +48,7 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
'impact_way' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'is_special_days_exists' => array('type' => self::TYPE_INT),
|
||||
'date_selection_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'special_days' => array('type' => self::TYPE_STRING),
|
||||
'special_days' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'impact_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'impact_value' => array('type' => self::TYPE_FLOAT),
|
||||
'active' => array('type' => self::TYPE_INT),
|
||||
@@ -67,6 +67,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'feature_prices',
|
||||
'objectNodeName' => 'feature_price',
|
||||
'objectMethods' => array(
|
||||
'add' => 'addWs',
|
||||
'update' => 'updateWs',
|
||||
),
|
||||
'fields' => array(
|
||||
'id_product' => array(
|
||||
'xlink_resource' => array(
|
||||
@@ -832,4 +836,70 @@ class HotelRoomTypeFeaturePricing extends ObjectModel
|
||||
$this->addGroups($groups);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Webservice :: function will run when feature price added from API
|
||||
public function addWs($autodate = true, $null_values = false)
|
||||
{
|
||||
$postData = trim(file_get_contents('php://input'));
|
||||
libxml_use_internal_errors(true);
|
||||
$xml = simplexml_load_string(utf8_decode($postData));
|
||||
$postFieldsObj = json_decode(json_encode($xml));
|
||||
|
||||
// we will check this also as empty value comes in empty std class
|
||||
$specialDaysArray = (array) $postFieldsObj->feature_price->special_days;
|
||||
|
||||
if (!empty($postFieldsObj->feature_price->special_days)
|
||||
&& $postFieldsObj->feature_price->special_days
|
||||
&& $specialDaysArray
|
||||
) {
|
||||
$weekDays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
||||
$specialDays = json_decode($postFieldsObj->feature_price->special_days, true);
|
||||
if (is_array($specialDays) && $specialDays) {
|
||||
if (count(array_diff($specialDays, $weekDays))) {
|
||||
WebserviceRequest::getInstance()->setError(400, 'Invalid special days. format must match with : ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]', 134);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
WebserviceRequest::getInstance()->setError(400, 'Invalid special days. format must match with : ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]', 134);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->add($autodate, $null_values);
|
||||
}
|
||||
|
||||
// Webservice :: function will run when feature price updated from API
|
||||
public function updateWs($null_values = false)
|
||||
{
|
||||
$postData = trim(file_get_contents('php://input'));
|
||||
libxml_use_internal_errors(true);
|
||||
$xml = simplexml_load_string(utf8_decode($postData));
|
||||
$postFieldsObj = json_decode(json_encode($xml));
|
||||
|
||||
// we will check this also as empty value comes in empty std class
|
||||
$specialDaysArray = (array) $postFieldsObj->feature_price->special_days;
|
||||
|
||||
if (!empty($postFieldsObj->feature_price->special_days)
|
||||
&& $postFieldsObj->feature_price->special_days
|
||||
&& $specialDaysArray
|
||||
) {
|
||||
$weekDays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
||||
$specialDays = json_decode($postFieldsObj->feature_price->special_days, true);
|
||||
if (is_array($specialDays) && $specialDays) {
|
||||
if (count(array_diff($specialDays, $weekDays))) {
|
||||
WebserviceRequest::getInstance()->setError(400, 'Invalid special days. format must match with : ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]', 134);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
WebserviceRequest::getInstance()->setError(400, 'Invalid special days. format must match with : ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]', 134);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->update($null_values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController
|
||||
}
|
||||
}
|
||||
if ($objFeaturePrice->special_days) {
|
||||
$smartyVars['special_days'] = json_decode($objFeaturePrice->special_days, true);
|
||||
$smartyVars['special_days'] = (array)json_decode($objFeaturePrice->special_days);
|
||||
}
|
||||
$smartyVars['objFeaturePrice'] = $objFeaturePrice;
|
||||
$smartyVars['edit'] = 1;
|
||||
|
||||
Reference in New Issue
Block a user