<?php
namespace Modules\Hotel\Blocks;
use Modules\Template\Blocks\BaseBlock;
use Modules\Hotel\Models\Hotel;
use Modules\Location\Models\Location;
class ListHotel extends BaseBlock
{
protected $hotelClass;
public function __construct(Hotel $hotelClass)
{
$this->hotelClass = $hotelClass;
}
public function getName()
{
return __('Hotel: List Items');
}
public function getOptions()
{
return [
'settings' => [
[
'id' => 'title',
'type' => 'input',
'inputType' => 'text',
'label' => __('Title'),
'adminLabel'=>true
],
[
'id' => 'desc',
'type' => 'input',
'inputType' => 'text',
'label' => __('Desc'),
'adminLabel'=>true
],
[
'id' => 'number',
'type' => 'input',
'inputType' => 'number',
'label' => __('Number Item'),
"default" => "5",
],
[
'id' => 'style',
'type' => 'radios',
'label' => __('Style'),
'values' => [
[
'value' => 'normal',
'name' => __("Normal")
],
[
'value' => 'carousel',
'name' => __("Slider Carousel")
]
]
],
[
'id' => 'location_id',
'type' => 'select2',
'label' => __('Filter by Location'),
'select2' => [
'ajax' => [
'url' => route('location.admin.getForSelect2'),
'dataType' => 'json'
],
'width' => '100%',
'allowClear' => 'true',
'placeholder' => __('-- Select --')
],
'pre_selected'=>route('location.admin.getForSelect2',['pre_selected'=>1])
],
[
'id' => 'order',
'type' => 'radios',
'label' => __('Order'),
'values' => [
[
'value' => 'id',
'name' => __("Date Create")
],
[
'value' => 'title',
'name' => __("Title")
],
],
],
[
'id' => 'order_by',
'type' => 'radios',
'label' => __('Order By'),
'values' => [
[
'value' => 'asc',
'name' => __("ASC")
],
[
'value' => 'desc',
'name' => __("DESC")
],
],
"selectOptions"=> [
'hideNoneSelectedText' => "true"
]
],
[
'type'=> "checkbox",
'label'=>__("Only featured items?"),
'id'=> "is_featured",
'default'=>true
],
[
'id' => 'custom_ids',
'type' => 'select2',
'label' => __('List by IDs'),
'select2' => [
'ajax' => [
'url' => route('hotel.admin.getForSelect2'),
'dataType' => 'json'
],
'width' => '100%',
'multiple' => "true",
'placeholder' => __('-- Select --')
],
'pre_selected' => route('hotel.admin.getForSelect2', [
'pre_selected' => 1
])
],
],
'category'=>__("Service Hotel")
];
}
public function content($model = [])
{
$list = $this->query($model);
$data = [
'rows' => $list,
'style_list' => $model['style'],
'title' => $model['title'],
'desc' => $model['desc'],
];
return view('Hotel::frontend.blocks.list-hotel.index', $data);
}
public function contentAPI($model = []){
$rows = $this->query($model);
$model['data']= $rows->map(function($row){
return $row->dataForApi();
});
return $model;
}
public function query($model){
$hotelClass = $this->hotelClass->search($model);
$limit = $model['number'] ?? 5;
return $hotelClass->paginate($limit);
}
}