Server IP : 66.29.132.124 / Your IP : 3.145.64.210 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/modules/Tour/Blocks/ |
Upload File : |
<?php namespace Modules\Tour\Blocks; use Modules\Template\Blocks\BaseBlock; use Modules\Tour\Models\Tour; use Modules\Tour\Models\TourCategory; use Modules\Location\Models\Location; class ListTours extends BaseBlock { function __construct() { $this->setOptions([ 'settings' => [ [ 'id' => 'title', 'type' => 'input', 'inputType' => 'text', 'label' => __('Title') ], [ 'id' => 'desc', 'type' => 'input', 'inputType' => 'text', 'label' => __('Desc') ], [ 'id' => 'number', 'type' => 'input', 'inputType' => 'number', 'label' => __('Number Item') ], [ 'id' => 'style', 'type' => 'radios', 'label' => __('Style'), 'values' => [ [ 'value' => 'normal', 'name' => __("Normal") ], [ 'value' => 'carousel', 'name' => __("Slider Carousel") ], [ 'value' => 'box_shadow', 'name' => __("Box Shadow") ], [ 'value' => 'carousel_simple', 'name' => __("Slider Carousel Simple") ], ] ], [ 'id' => 'category_id', 'type' => 'select2', 'label' => __('Filter by Category'), 'select2' => [ 'ajax' => [ 'url' => route('tour.admin.category.category.getForSelect2'), 'dataType' => 'json' ], 'width' => '100%', 'allowClear' => 'true', 'placeholder' => __('-- Select --') ], 'pre_selected'=>route('tour.admin.category.category.getForSelect2',['pre_selected'=>1]) ], [ '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") ], ] ], [ 'type'=> "checkbox", 'label'=>__("Only featured items?"), 'id'=> "is_featured", 'default'=>true ], [ 'id' => 'custom_ids', 'type' => 'select2', 'label' => __('List by IDs'), 'select2' => [ 'ajax' => [ 'url' => route('tour.admin.getForSelect2'), 'dataType' => 'json' ], 'width' => '100%', 'multiple' => "true", 'placeholder' => __('-- Select --') ], 'pre_selected' => route('tour.admin.getForSelect2', [ 'pre_selected' => 1 ]) ], ], 'category'=>__("Service Tour") ]); } public function getName() { return __('Tour: List Items'); } public function content($model = []) { $list = $this->query($model); $data = [ 'rows' => $list, 'style_list' => $model['style'], 'title' => $model['title'] ?? "", 'desc' => $model['desc'] ?? "", ]; return view('Tour::frontend.blocks.list-tour.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){ $model_Tour = Tour::select("bravo_tours.*")->with(['location','translations','hasWishList']); if(empty($model['order'])) $model['order'] = "id"; if(empty($model['order_by'])) $model['order_by'] = "desc"; if(empty($model['number'])) $model['number'] = 5; if (!empty($model['location_id'])) { $location = Location::where('id', $model['location_id'])->where("status","publish")->first(); if(!empty($location)){ $model_Tour->join('bravo_locations', function ($join) use ($location) { $join->on('bravo_locations.id', '=', 'bravo_tours.location_id') ->where('bravo_locations._lft', '>=', $location->_lft) ->where('bravo_locations._rgt', '<=', $location->_rgt); }); } } if (!empty($model['category_id'])) { $category_ids = [$model['category_id']]; $list_cat = TourCategory::whereIn('id', $category_ids)->where("status","publish")->get(); if(!empty($list_cat)){ $where_left_right = []; $params = []; foreach ($list_cat as $cat){ $where_left_right[] = " ( bravo_tour_category._lft >= ? AND bravo_tour_category._rgt <= ? ) "; $params[] = $cat->_lft; $params[] = $cat->_rgt; } $sql_where_join = " ( ".implode("OR" , $where_left_right)." ) "; $model_Tour ->join('bravo_tour_category', function ($join) use($sql_where_join,$params) { $join->on('bravo_tour_category.id', '=', 'bravo_tours.category_id') ->WhereRaw($sql_where_join,$params); }); } } if(!empty($model['is_featured'])) { $model_Tour->where('bravo_tours.is_featured',1); } if(!empty( $model['custom_ids'] )){ $model_Tour->whereIn("bravo_tours.id",$model['custom_ids']); } $model_Tour->orderBy("bravo_tours.".$model['order'], $model['order_by']); $model_Tour->where("bravo_tours.status", "publish"); $model_Tour->with('location'); $model_Tour->groupBy("bravo_tours.id"); return $model_Tour->limit($model['number'])->get(); } }