From a29b489abf679e23c74c6afb709e15c51ada59cc Mon Sep 17 00:00:00 2001 From: Mark van den Broek Date: Sun, 15 Dec 2024 13:55:51 +0100 Subject: [PATCH] Add art by mca_chef --- app/Models/Inscription.php | 3 +- app/Traits/HasMcaChefArt.php | 62 +++++++++++++++++++++++++++ resources/views/inscription.blade.php | 26 +++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 app/Traits/HasMcaChefArt.php diff --git a/app/Models/Inscription.php b/app/Models/Inscription.php index 353d32e..704cb29 100644 --- a/app/Models/Inscription.php +++ b/app/Models/Inscription.php @@ -4,6 +4,7 @@ use App\Traits\HasBtcLoongArt; use App\Traits\HasJasmineArt; +use App\Traits\HasMcaChefArt; use App\Traits\HasMoodzAnimations; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -15,7 +16,7 @@ class Inscription extends Model { - use HasBtcLoongArt, HasFactory, HasJasmineArt, HasMoodzAnimations, HasSEO; + use HasBtcLoongArt, HasFactory, HasJasmineArt, HasMcaChefArt, HasMoodzAnimations, HasSEO; protected $fillable = [ 'inscription_id', diff --git a/app/Traits/HasMcaChefArt.php b/app/Traits/HasMcaChefArt.php new file mode 100644 index 0000000..cd6a3e7 --- /dev/null +++ b/app/Traits/HasMcaChefArt.php @@ -0,0 +1,62 @@ +id; + } + + private function getMcaChefDirectory(): string + { + return $this->mcaChefDirectory.'PN_'.$this->getInternalCollectionId().'/'; + } + + public function hasMcaChefImages(): bool + { + return $this->getMcaChefFileNames()->isNotEmpty(); + } + + public function getMcaChefFullUrls(): Collection + { + return $this->getMcaChefFileNames()->map( + fn ($path) => $this->cdn_base_url.urlencode($path) + ); + } + + public function getMcaChefFileNames(): Collection + { + if (Cache::has($this->getMcaChefCacheKey())) { + return Cache::get($this->getMcaChefCacheKey()); + } + + try { + $files = collect(Storage::disk('cloudflare')->files($this->getMcaChefDirectory())) + ->filter(function ($file) { + return strtolower( + Storage::disk('cloudflare')->mimeType($file) + ) === 'image/gif'; + }) + ->values(); + + Cache::put($this->getMcaChefCacheKey(), $files, now()->addDay()); + } catch (Exception $e) { + $files = collect([]); + Log::error('Error checking McaChef art for model: '.$this->id.': '.$e->getMessage()); + } + + return $files; + } +} diff --git a/resources/views/inscription.blade.php b/resources/views/inscription.blade.php index dfd4b47..394eb43 100644 --- a/resources/views/inscription.blade.php +++ b/resources/views/inscription.blade.php @@ -162,6 +162,32 @@ class="underline" @endif + @if($inscription->hasMcaChefImages()) +
+
+
+ @foreach($inscription->getMcaChefFullUrls() as $url) + {{ $inscription->name }} art by mca_chef + @endforeach +
+
+

+ art by + @mca_chef +

+
+
+
+ @endif +

Traits