⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.1
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
work
/
modules
/
Location
/
Blocks
/
Edit File: ListLocations.php
<?php namespace Modules\Location\Blocks; use Modules\Template\Blocks\BaseBlock; use Modules\Location\Models\Location; class ListLocations extends BaseBlock { public function getOptions() { $list_service = []; foreach (get_bookable_services() as $key => $service) { if($key == 'flight') continue; $list_service[] = ['value' => $key, 'name' => ucwords($key) ]; } return [ 'settings' => [ [ 'id' => 'service_type', 'type' => 'checklist', 'listBox' => 'true', 'label' => "<strong>".__('Service Type')."</strong>", 'values' => $list_service, ], [ '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' => 'layout', 'type' => 'radios', 'label' => __('Style'), 'values' => [ [ 'value' => 'style_1', 'name' => __("Style 1") ], [ 'value' => 'style_2', 'name' => __("Style 2") ], [ 'value' => 'style_3', 'name' => __("Style 3") ], [ 'value' => 'style_4', 'name' => __("Style 4") ] ] ], [ 'id' => 'order', 'type' => 'radios', 'label' => __('Order'), 'values' => [ [ 'value' => 'id', 'name' => __("Date Create") ], [ 'value' => 'name', 'name' => __("Title") ], ], ], [ 'id' => 'order_by', 'type' => 'radios', 'label' => __('Order By'), 'values' => [ [ 'value' => 'asc', 'name' => __("ASC") ], [ 'value' => 'desc', 'name' => __("DESC") ], ], ], [ 'id' => 'custom_ids', 'type' => 'select2', 'label' => __('List Location by IDs'), 'select2' => [ 'ajax' => [ 'url' => route('location.admin.getForSelect2'), 'dataType' => 'json' ], 'width' => '100%', 'multiple' => "true", ], 'pre_selected' => route('location.admin.getForSelect2', [ 'pre_selected' => 1 ]) ], [ 'type'=> "checkbox", 'label'=>__("Link to location detail page?"), 'id'=> "to_location_detail", 'default'=>false ] ], 'category'=>__("Location") ]; } public function getName() { return __('List Locations'); } public function content($model = []) { $list = $this->query($model); $data = [ 'rows' => $list, 'title' => $model['title'], 'desc' => $model['desc'] ?? "", 'service_type' => $model['service_type'], 'layout' => !empty($model['layout']) ? $model['layout'] : "style_1", 'to_location_detail'=>$model['to_location_detail'] ?? '' ]; return view('Location::frontend.blocks.list-locations.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){ 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['service_type'])) return collect([]); $model_location = Location::query()->with(['translation']); $model_location->where("status","publish"); if(!empty( $model['custom_ids'] )){ $ids = $model['custom_ids']; $model_location->whereIn("id", $ids); $model_location->orderByRaw('FIELD (id, ' . implode(', ', $ids) . ') ASC'); $limit = count($ids); }else{ $model_location->orderBy($model['order'], $model['order_by']); } return $model_location->limit($limit ?? $model['number'])->get(); } }
Simpan