diff --git a/app/Models/Artwork.php b/app/Models/Artwork.php index a2d4a76..2872ec3 100644 --- a/app/Models/Artwork.php +++ b/app/Models/Artwork.php @@ -27,11 +27,11 @@ public static function getStats() 'artworks.stats', fn() => [ 'lastUpdate' => optional( - self::orderByDesc('updated_at')->first() + self::orderByDesc('updated_at')->first(), )->updated_at, 'count' => self::published()->count(), 'locations' => Location::selectRaw( - 'count(id) as count, borough' + 'count(id) as count, borough', ) ->current() ->whereHas('artworks', function (Builder $query) { @@ -42,7 +42,7 @@ public static function getStats() ->groupBy('district') ->collect() // Turn to Laravel collection ->except(''), // Filter out locations with empty district - ] + ], ); } @@ -65,7 +65,7 @@ public function scopeSelectCurrentLocationDistance($query, $otherArtwork) 'artwork_location', 'artwork_location.artwork_id', '=', - 'artworks.id' + 'artworks.id', ) ->join('locations', function (JoinClause $join) { $join @@ -75,24 +75,24 @@ public function scopeSelectCurrentLocationDistance($query, $otherArtwork) }) ->selectRaw( 'ST_Distance_Sphere(point(?, ?), point(locations.gps_lon, locations.gps_lat)) as distance', - [$otherArtworkLocation->gps_lon, $otherArtworkLocation->gps_lat] + [ + $otherArtworkLocation->gps_lon, + $otherArtworkLocation->gps_lat, + ], ); } // default scope for those artworks that we can actually display public function scopePresentable($query) { - $query - ->published() - ->has('coverPhotoMedia') - ->has('locations'); + $query->published()->has('coverPhotoMedia')->has('locations'); } public function scopeFilteredBySearchRequest($query, Request $request) { $request->whenFilled('boroughs', function ($boroughs) use ($query) { $query->whereHas('locations', function (Builder $query) use ( - $boroughs + $boroughs, ) { $query->current()->whereIn('borough', $boroughs); }); @@ -100,17 +100,17 @@ public function scopeFilteredBySearchRequest($query, Request $request) $request->whenFilled('authors', function ($authorIds) use ($query) { $query->whereHas('authorsAndCoauthors', function ( - Builder $query + Builder $query, ) use ($authorIds) { $query->whereIn('id', $authorIds); }); }); $request->whenFilled('categories', function ($categoryIds) use ( - $query + $query, ) { $query->whereHas('categories', function (Builder $query) use ( - $categoryIds + $categoryIds, ) { $query->whereIn('id', $categoryIds); }); @@ -118,7 +118,7 @@ public function scopeFilteredBySearchRequest($query, Request $request) $request->whenFilled('keywords', function ($keywordIds) use ($query) { $query->whereHas('keywords', function (Builder $query) use ( - $keywordIds + $keywordIds, ) { $query->whereIn('id', $keywordIds); }); @@ -245,7 +245,7 @@ public function coverPhotoMedia() { return $this->hasOneDeepFromRelations( $this->photos(), - (new Photo())->media() + (new Photo())->media(), ) ->orderBy('artwork_photo.order') ->orderBy('media.order_column') @@ -258,8 +258,8 @@ public function defunct(): Attribute fn() => $this->conditions->contains( fn(Condition $condition) => str($condition->name) ->trim() - ->exactly('zničené, odstránené') - ) + ->exactly('zničené, odstránené'), + ), ); } @@ -268,7 +268,7 @@ public function descriptionHtml(): Attribute return Attribute::get( fn() => Str::of($this->description) ->replace("\n", "\n\n") - ->markdown() + ->airtableMarkdown(), ); } @@ -299,8 +299,8 @@ public function photoMediaForCarousel(): Attribute 'url' => $m->getUrl(), 'description' => $photo->description, 'source' => $photo->source, - ] - ) + ], + ), ); }); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3bd8b9e..bf1942d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,6 +5,8 @@ use App\Http\Resources\ArtworkMapPointCollection; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; +use Illuminate\Support\Stringable; class AppServiceProvider extends ServiceProvider { @@ -30,5 +32,17 @@ public function boot() } ArtworkMapPointCollection::withoutWrapping(); + + Str::macro('airtableMarkdown', function ($value) { + return Str::of($value) + ->replaceMatches('/\*\*(\s*)(.*?)(\s*)\*\*/', '$1**$2**$3') + ->replaceMatches('/_(\s*)(.*?)(\s*)_/', '$1_$2_$3') + ->replaceMatches('/~~(\s*)(.*?)(\s*)~~/', '$1~~$2~~$3') + ->markdown(); + }); + + Stringable::macro('airtableMarkdown', function () { + return Str::airtableMarkdown($this->value); + }); } }