Skip to content

Commit

Permalink
Update validation message for street address input, add reviews to Lo…
Browse files Browse the repository at this point in the history
…cation 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 <[email protected]>
  • Loading branch information
sampoyigi committed Feb 28, 2024
1 parent 5621997 commit de5d963
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 45 deletions.
14 changes: 2 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

-
Expand Down Expand Up @@ -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
Expand All @@ -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

-
Expand Down
5 changes: 2 additions & 3 deletions resources/lang/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 0 additions & 10 deletions resources/models/locationsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 1 addition & 15 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 8 additions & 4 deletions src/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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';
}
}
2 changes: 1 addition & 1 deletion src/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function findBy($saleType, $saleId)

public function getRatingOptions()
{
return ReviewSettings::get('hints', ReviewSettings::$defaultHints);
return ReviewSettings::getHints();
}

//
Expand Down
10 changes: 10 additions & 0 deletions src/Models/ReviewSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit de5d963

Please sign in to comment.