updated webservice for hotel images
This commit is contained in:
@@ -120,9 +120,11 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string $type_name Name
|
||||
* @return array Image type definition
|
||||
*/
|
||||
public static function getTypeByName($name)
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'image_type` WHERE `name` like "'.pSQL($name).'"');
|
||||
return Db::getInstance()->getRow(
|
||||
'SELECT `id_image_type`, `width`, `height` FROM `'._DB_PREFIX_.'image_type` WHERE `name` like "'.pSQL($name).'"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
'store_icon' => array(),
|
||||
),
|
||||
'products' => array(),
|
||||
'hotels' => array(),
|
||||
'categories' => array(),
|
||||
'manufacturers' => array(),
|
||||
'suppliers' => array(),
|
||||
@@ -324,6 +325,9 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
case 'room_types':
|
||||
return $this->manageProductImages();
|
||||
break;
|
||||
case 'hotels':
|
||||
return $this->manageHotelImages();
|
||||
break;
|
||||
case 'customizations':
|
||||
return $this->manageCustomizationImages();
|
||||
break;
|
||||
@@ -508,6 +512,17 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
foreach ($ids as $id) {
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.'room_types'.'/'.$id), false);
|
||||
}
|
||||
} else if ($this->imageType == 'hotels') {
|
||||
$ids = array();
|
||||
$objHotelImage = new HotelImage();
|
||||
$images = $objHotelImage->getAllImages();
|
||||
foreach ($images as $image) {
|
||||
$ids[] = $image['id_hotel'];
|
||||
}
|
||||
$ids = array_unique($ids, SORT_NUMERIC);
|
||||
foreach ($ids as $id) {
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.'hotels'.'/'.$id), false);
|
||||
}
|
||||
} else {
|
||||
$nodes = scandir($directory);
|
||||
foreach ($nodes as $node) {
|
||||
@@ -591,6 +606,47 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
$this->wsObject->setOutputEnabled(false);
|
||||
}
|
||||
}
|
||||
} elseif ($this->imageType == 'hotels') {
|
||||
// Get available image ids
|
||||
$available_image_ids = array();
|
||||
$objHotelImage = new HotelImage();
|
||||
|
||||
foreach (Language::getIDs() as $id_lang) {
|
||||
foreach ($objHotelImage->getImagesByHotelId($object_id) as $image) {
|
||||
$available_image_ids[] = $image['id'];
|
||||
}
|
||||
}
|
||||
$available_image_ids = array_unique($available_image_ids, SORT_NUMERIC);
|
||||
|
||||
if ($this->wsObject->urlSegment[3] != '') {
|
||||
if ($this->wsObject->urlSegment[3] == 'bin') {
|
||||
$hotelCoverImage = HotelImage::getCover($object_id);
|
||||
$this->wsObject->urlSegment[3] = $hotelCoverImage['id'];
|
||||
}
|
||||
if (!Validate::isUnsignedId($object_id) || !in_array($this->wsObject->urlSegment[3], $available_image_ids)) {
|
||||
throw new WebserviceException('This image id does not exist', array(57, 400));
|
||||
} else {
|
||||
$image_id = $this->wsObject->urlSegment[3];
|
||||
$path = $object_id;
|
||||
$image_size = $this->wsObject->urlSegment[4];
|
||||
if (file_exists($directory.$path.'/'.$image_id.(strlen($this->wsObject->urlSegment[4]) > 0 ? '-'.$this->wsObject->urlSegment[4] : '').'.jpg')) {
|
||||
$filename = $directory.$path.'/'.$image_id.(strlen($this->wsObject->urlSegment[4]) > 0 ? '-'.$this->wsObject->urlSegment[4] : '').'.jpg';
|
||||
|
||||
$orig_filename = $directory.$path.'/'.$image_id.'.jpg';
|
||||
}
|
||||
}
|
||||
} elseif ($this->wsObject->method == 'GET' || $this->wsObject->method == 'HEAD') {
|
||||
if ($available_image_ids) {
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id'=>$object_id));
|
||||
foreach ($available_image_ids as $available_image_id) {
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('declination', array(), array('id'=>$available_image_id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.'hotels'.'/'.$object_id.'/'.$available_image_id), false);
|
||||
}
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image', array());
|
||||
} else {
|
||||
$this->objOutput->setStatus(404);
|
||||
$this->wsObject->setOutputEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for all other cases
|
||||
@@ -669,6 +725,11 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
$this->manageDeclinatedImages(_PS_PROD_IMG_DIR_);
|
||||
}
|
||||
|
||||
protected function manageHotelImages()
|
||||
{
|
||||
$this->manageDeclinatedImages(_PS_HOTEL_IMG_DIR_);
|
||||
}
|
||||
|
||||
protected function getCustomizations()
|
||||
{
|
||||
$customizations = array();
|
||||
|
||||
@@ -70,7 +70,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
'suffix' => ' px'
|
||||
),
|
||||
'products' => array(
|
||||
'title' => $this->l('Products'),
|
||||
'title' => $this->l('Room Types/Products'),
|
||||
'align' => 'center',
|
||||
'type' => 'bool',
|
||||
'active' => 'products',
|
||||
@@ -91,7 +91,6 @@ class AdminImagesControllerCore extends AdminController
|
||||
'type' => 'bool',
|
||||
'active' => 'hotels',
|
||||
'ajax' => true,
|
||||
'callback' => 'printEntityActiveIcon',
|
||||
'orderby' => false
|
||||
),
|
||||
);
|
||||
@@ -261,7 +260,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Products'),
|
||||
'label' => $this->l('Room Types/Products'),
|
||||
'name' => 'products',
|
||||
'required' => false,
|
||||
'is_bool' => true,
|
||||
@@ -341,9 +340,9 @@ class AdminImagesControllerCore extends AdminController
|
||||
$objImageType->$action = !$objImageType->$action;
|
||||
if ($objImageType->save()) {
|
||||
$response['success'] = true;
|
||||
$response['text'] = $this->l('The status has been updated successfully.');
|
||||
$response['text'] = $this->l('Updated successfully.');
|
||||
} else {
|
||||
$response['text'] = $this->l('An error occurred while updating this status.');
|
||||
$response['text'] = $this->l('An error occurred while updating image type for .'.$action);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,7 +412,7 @@ class AdminImagesControllerCore extends AdminController
|
||||
{
|
||||
$types = array(
|
||||
'categories' => $this->l('Categories'),
|
||||
'products' => $this->l('Room Types'),
|
||||
'products' => $this->l('Room Types/Products'),
|
||||
'hotels' => $this->l('Hotels'),
|
||||
);
|
||||
|
||||
|
||||
@@ -347,8 +347,8 @@ class DashProducts extends Module
|
||||
$img = ImageManager::thumbnail($path_to_image, 'product_mini_'.$product_obj->id.'.'.$this->context->controller->imageType, 45, $this->context->controller->imageType);
|
||||
}
|
||||
|
||||
$objHRT = new HotelRoomType($product_obj->id);
|
||||
$objHotelBranch = new HotelBranchInformation($objHRT->id_hotel, $this->context->language->id);
|
||||
$objHotelRoomType = new HotelRoomType($product_obj->id);
|
||||
$objHotelBranch = new HotelBranchInformation($objHotelRoomType->id_hotel, $this->context->language->id);
|
||||
|
||||
$tr = array();
|
||||
$tr[] = array(
|
||||
|
||||
@@ -26,7 +26,7 @@ class HotelImage extends ObjectModel
|
||||
|
||||
public $image_format = 'jpg';
|
||||
|
||||
protected static $access_rights = 0775;
|
||||
protected static $access_rights = 0755;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'htl_image',
|
||||
|
||||
@@ -280,7 +280,7 @@ class AdminAboutHotelBlockSettingController extends ModuleAdminController
|
||||
} while ((bool)Tools::file_get_contents(
|
||||
$this->context->link->getMediaLink(_MODULE_DIR_.$this->module->name.'/views/img/hotel_interior/'.$tmp_name.'.jpg')
|
||||
));
|
||||
$imageSize = ImageType::getTypeByName(ImageType::getFormatedName('large'));
|
||||
$imageSize = ImageType::getByName(ImageType::getFormatedName('large'));
|
||||
ImageManager::resize(
|
||||
$file['tmp_name'],
|
||||
_PS_MODULE_DIR_.$this->module->name.'/views/img/hotel_interior/'.$tmp_name.'.jpg',
|
||||
|
||||
@@ -317,7 +317,7 @@ class AdminFeaturesModuleSettingController extends ModuleAdminController
|
||||
if (file_exists($imgPath)) {
|
||||
unlink($imgPath);
|
||||
}
|
||||
$imageSize = ImageType::getTypeByName(ImageType::getFormatedName('large'));
|
||||
$imageSize = ImageType::getByName(ImageType::getFormatedName('large'));
|
||||
ImageManager::resize(
|
||||
$file['tmp_name'],
|
||||
$imgPath,
|
||||
|
||||
@@ -295,7 +295,7 @@ class AdminTestimonialsModuleSettingController extends ModuleAdminController
|
||||
if ($_FILES['testimonial_image']['size']) {
|
||||
$testimonial_img_path = _PS_MODULE_DIR_.$this->module->name.'/views/img/hotels_testimonials_img/'.
|
||||
$objTestimonialData->id.'.jpg';
|
||||
$imageSize = ImageType::getTypeByName(ImageType::getFormatedName('small'));
|
||||
$imageSize = ImageType::getByName(ImageType::getFormatedName('small'));
|
||||
ImageManager::resize(
|
||||
$_FILES['testimonial_image']['tmp_name'],
|
||||
$testimonial_img_path,
|
||||
|
||||
Reference in New Issue
Block a user