Server IP : 66.29.132.124 / Your IP : 3.17.183.187 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/Review/Models/ |
Upload File : |
<?php namespace Modules\Review\Models; use App\BaseModel; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Cache; use Illuminate\Database\Eloquent\SoftDeletes; use Modules\Review\Models\ReviewMeta; class Review extends BaseModel { use SoftDeletes; protected $table = 'bravo_review'; protected $fillable = [ 'object_id', 'object_model', 'title', 'content', 'rate_number', 'author_ip', 'status', 'vendor_id' ]; /** * Get Category * * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function getUserInfo() { return $this->hasOne("Modules\User\Models\User", "id", 'create_user')->withTrashed(); } public static function getDisplayTextScoreByLever($lever) { switch ($lever) { case 5: return __("Excellent"); break; case 4: return __("Very Good"); break; case 3: return __("Average"); break; case 2: return __("Poor"); break; case 1: case 0: return __("Terrible"); break; default: return __("Not rated"); break; } } public function getService() { $allServices = get_bookable_services(); $module = $allServices[$this->object_model]; return $this->hasOne($module, "id", 'object_id'); } public function getReviewMeta() { return ReviewMeta::where("review_id", $this->id)->get(); } public function getReviewMetaPicture() { return ReviewMeta::where("review_id", $this->id)->where('name', 'upload_picture')->first(); } public static function countReviewByStatus($status = false) { $count = parent::query(); if (!empty($status)) { $count->where("status", $status); } return $count->count("id"); } public static function countReviewByServiceID($service_id = false, $user_id = false, $status = false,$service_type = '') { if (empty($service_id)) return false; $count = parent::where("object_id", $service_id); if (!empty($status)) { $count->where("status", $status); } if($service_type){ $count->where('object_model',$service_type); } if (!empty($user_id)) { $count->where("create_user", $user_id); } return $count->count("id"); } public function save(array $options = []) { $check = parent::save($options); // TODO: Change the autogenerated stub if ($check) { Cache::forget("review_" . $this->object_model . "_" . $this->object_id); } return $check; } public function addMeta($key, $val, $multiple = false) { if (is_object($val) or is_array($val)) $val = json_encode($val); if ($multiple) { $reviewMeta = new ReviewMeta([ "object_id" => $this->object_id, "object_model" => $this->object_model, "name" => $key, "val" => $val, 'review_id'=>$this->id ]); return $reviewMeta->save(); } else { $old = ReviewMeta::query()->where([ 'review_id' => $this->id, 'name' => $key ])->first(); if ($old) { $old->val = $val; return $old->save(); } else { $reviewMeta = new ReviewMeta([ "object_id" => $this->object_id, "object_model" => $this->object_model, "name" => $key, "val" => $val, 'review_id'=>$this->id ]); return $reviewMeta->save(); } } } public function author() { return $this->belongsTo("App\User", "create_user", "id")->select(['id','name','first_name','last_name','avatar_id'])->withDefault(); } }