From de5d9634aadfed618665c76c14194d3725104bb5 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:59:57 +0000 Subject: [PATCH] Update validation message for street address input, add reviews to Location model, refactor Review model and ReviewSettings, remove Order model extension from Extension model, and handle potential null value in position comparison Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- phpstan-baseline.neon | 14 ++------------ resources/lang/en/default.php | 5 ++--- resources/models/locationsettings.php | 10 ---------- src/Extension.php | 16 +--------------- src/Models/Location.php | 12 ++++++++---- src/Models/Review.php | 2 +- src/Models/ReviewSettings.php | 10 ++++++++++ 7 files changed, 24 insertions(+), 45 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c0d2854..b0acce2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -537,12 +537,7 @@ parameters: - message: "#^Call to an undefined static method Igniter\\\\Local\\\\Models\\\\Location\\:\\:whereIsEnabled\\(\\)\\.$#" - count: 1 - path: src/Models/Location.php - - - - message: "#^Call to an undefined static method static\\(Igniter\\\\Local\\\\Models\\\\Location\\)\\:\\:whereIsEnabled\\(\\)\\.$#" - count: 1 + count: 2 path: src/Models/Location.php - @@ -600,11 +595,6 @@ parameters: count: 1 path: src/Models/Review.php - - - message: "#^Call to an undefined static method Igniter\\\\Local\\\\Models\\\\ReviewSettings\\:\\:get\\(\\)\\.$#" - count: 1 - path: src/Models/Review.php - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\AdminAuth\\:\\:isSuperUser\\(\\)\\.$#" count: 1 @@ -617,7 +607,7 @@ parameters: - message: "#^Call to an undefined static method Igniter\\\\Local\\\\Models\\\\ReviewSettings\\:\\:get\\(\\)\\.$#" - count: 1 + count: 3 path: src/Models/ReviewSettings.php - diff --git a/resources/lang/en/default.php b/resources/lang/en/default.php index e2b91c7..6d7d964 100644 --- a/resources/lang/en/default.php +++ b/resources/lang/en/default.php @@ -2,8 +2,7 @@ return [ 'text_tab_texts' => 'Text', - 'text_info_heading' => 'More info about %s local restaurant', - 'text_gallery_heading' => 'Gallery of %s', + 'text_gallery' => 'Gallery', 'text_find' => 'Find', 'text_order_summary' => 'Find a restaurant near you', @@ -136,7 +135,7 @@ 'alert_no_search_setting' => 'Location Search By setting has not been specified.', 'alert_no_search_query' => 'Please type in a address or postcode to check if we can deliver to you.', 'alert_invalid_search_query' => 'We couldn\'t locate the entered address or postcode, please enter a valid address or postcode.', - 'alert_missing_street_address' => 'Please enter your street address.', + 'alert_missing_street_address' => 'Please enter a valid street address.', 'alert_no_found_restaurant' => 'We do not have any local restaurant near you.', 'alert_location_required' => 'No location found or selected', 'alert_order_type_required' => 'There\'s no active online ordering option for this location', diff --git a/resources/models/locationsettings.php b/resources/models/locationsettings.php index 46e52e0..dda6265 100644 --- a/resources/models/locationsettings.php +++ b/resources/models/locationsettings.php @@ -34,16 +34,6 @@ 'commentAbove' => 'lang:igniter.local::default.help_delivery_areas', ], - 'options[gallery][title]' => [ - 'label' => 'lang:igniter.local::default.label_gallery_title', - 'tab' => 'lang:igniter.local::default.text_tab_gallery', - 'type' => 'text', - ], - 'options[gallery][description]' => [ - 'label' => 'lang:igniter::admin.label_description', - 'tab' => 'lang:igniter.local::default.text_tab_gallery', - 'type' => 'textarea', - ], 'gallery' => [ 'label' => 'lang:igniter.local::default.label_gallery_add_image', 'tab' => 'lang:igniter.local::default.text_tab_gallery', diff --git a/src/Extension.php b/src/Extension.php index d519e80..d290b66 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -7,7 +7,6 @@ use Igniter\Admin\DashboardWidgets\Charts; use Igniter\Admin\Facades\AdminMenu; use Igniter\Cart\Classes\OrderTypes; -use Igniter\Cart\Models\Order; use Igniter\Flame\Geolite\Facades\Geocoder; use Igniter\Flame\Igniter; use Igniter\Local\Classes\Location; @@ -282,28 +281,15 @@ protected function addReviewsRelationship(): void 'reviews' => \Igniter\Local\Models\Review::class, ]); - Order::extend(function ($model) { - $model->relation['morphMany']['review'] = [\Igniter\Local\Models\Review::class]; - }); - Reservation::extend(function ($model) { $model->relation['morphMany']['review'] = [\Igniter\Local\Models\Review::class]; }); - - LocationModel::extend(function ($model) { - $model->relation['hasMany']['reviews'] = [\Igniter\Local\Models\Review::class]; - - $model->addDynamicMethod('reviews_score', function () use ($model) { - return Review::getScoreForLocation($model->getKey()); - }); - $model->queryModifierAddSorts(['reviews_count asc', 'reviews_count desc']); - }); } protected function bindRememberLocationAreaEvents(): void { Event::listen('location.position.updated', function ($location, $position, $oldPosition) { - if ($position->format() === $oldPosition->format()) { + if ($position->format() === $oldPosition?->format()) { return; } diff --git a/src/Models/Location.php b/src/Models/Location.php index 318d59b..2bcdc0f 100644 --- a/src/Models/Location.php +++ b/src/Models/Location.php @@ -74,6 +74,7 @@ class Location extends Model implements LocationInterface public $relation = [ 'hasMany' => [ 'settings' => [\Igniter\Local\Models\LocationSettings::class, 'delete' => true], + 'reviews' => [\Igniter\Local\Models\Review::class], 'working_hours' => [\Igniter\Local\Models\WorkingHour::class, 'delete' => true], ], 'belongsTo' => [ @@ -104,6 +105,7 @@ class Location extends Model implements LocationInterface 'distance asc', 'distance desc', 'location_id asc', 'location_id desc', 'location_name asc', 'location_name desc', + 'reviews_count asc', 'reviews_count desc', ]; protected array $queryModifierSearchableFields = [ @@ -164,14 +166,16 @@ public function hasGallery() public function getGallery() { - $gallery = array_get($this->options, 'gallery'); - $gallery['images'] = $this->getMedia('gallery'); - - return $gallery; + return $this->getMedia('gallery'); } public function defaultableName(): string { return $this->location_name; } + + public function getMorphClass() + { + return 'locations'; + } } diff --git a/src/Models/Review.php b/src/Models/Review.php index e6233e3..9448654 100644 --- a/src/Models/Review.php +++ b/src/Models/Review.php @@ -83,7 +83,7 @@ public static function findBy($saleType, $saleId) public function getRatingOptions() { - return ReviewSettings::get('hints', ReviewSettings::$defaultHints); + return ReviewSettings::getHints(); } // diff --git a/src/Models/ReviewSettings.php b/src/Models/ReviewSettings.php index f60b80c..b483df7 100644 --- a/src/Models/ReviewSettings.php +++ b/src/Models/ReviewSettings.php @@ -26,4 +26,14 @@ public static function allowReviews() { return (bool)self::get('allow_reviews', true); } + + public static function autoApproveReviews() + { + return self::get('approve_reviews', false); + } + + public static function getHints() + { + return collect(self::get('hints', self::$defaultHints))->pluck('value')->all(); + } }