From 8572e9ff12a9389b7bd139a252200fafe1fe5fcd Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 29 Jul 2023 16:49:52 +0100 Subject: [PATCH 01/10] mark elephpants as prototypes --- app/Console/Commands/ReadElephpants.php | 3 + app/Elephpant.php | 11 + app/Http/Controllers/ElephpantController.php | 2 +- app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/StatisticsController.php | 1 + app/Queries/RankedUsersQuery.php | 2 + ...add_prototype_flag_to_elephpants_table.php | 32 +++ ..._prototype_elephpants_from_collections.php | 27 +++ resources/data/elephpants.json | 216 ++++++++++++------ .../views/elephpant/_single_box.blade.php | 3 + resources/views/elephpant/index.blade.php | 5 +- resources/views/home.blade.php | 5 +- 12 files changed, 233 insertions(+), 76 deletions(-) create mode 100644 database/migrations/2023_07_29_145607_add_prototype_flag_to_elephpants_table.php create mode 100644 database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php diff --git a/app/Console/Commands/ReadElephpants.php b/app/Console/Commands/ReadElephpants.php index 7ee056d..cdef8ba 100644 --- a/app/Console/Commands/ReadElephpants.php +++ b/app/Console/Commands/ReadElephpants.php @@ -14,6 +14,8 @@ class ReadElephpants extends Command public function handle(): void { + ini_set('memory_limit', '512M'); + $jsonFile = resource_path('data/elephpants.json'); $elephpants = json_decode(file_get_contents($jsonFile))->elephpants; @@ -27,6 +29,7 @@ public function handle(): void 'sponsor' => $elephpant->sponsor, 'year' => (int)$elephpant->year, 'image' => $this->processImage($elephpant), + 'prototype' => $elephpant->prototype ?: 0 ] ); } diff --git a/app/Elephpant.php b/app/Elephpant.php index 6d8f374..25f5660 100644 --- a/app/Elephpant.php +++ b/app/Elephpant.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -14,6 +15,7 @@ class Elephpant extends Model 'sponsor', 'year', 'image', + 'prototype', ]; public function users(): BelongsToMany @@ -22,4 +24,13 @@ public function users(): BelongsToMany ->withPivot('quantity') ->withTimestamps(); } + + protected static function boot() + { + parent::boot(); + + static::addGlobalScope('nonPrototype', function (Builder $builder) { + $builder->where('prototype', 0); + }); + } } diff --git a/app/Http/Controllers/ElephpantController.php b/app/Http/Controllers/ElephpantController.php index 98aff05..4118f3d 100644 --- a/app/Http/Controllers/ElephpantController.php +++ b/app/Http/Controllers/ElephpantController.php @@ -9,7 +9,7 @@ class ElephpantController extends Controller { public function index() { - $elephpants = Elephpant::query()->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); + $elephpants = Elephpant::query()->withoutGlobalScope('nonPrototype')->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); return view('elephpant.index', compact('elephpants')); } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 6aefc4e..07ec8d0 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,7 +8,7 @@ class HomeController extends Controller { public function index() { - $elephpants = Elephpant::query()->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); + $elephpants = Elephpant::query()->withoutGlobalScope('nonPrototype')->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); return view('home', compact('elephpants')); } diff --git a/app/Http/Controllers/StatisticsController.php b/app/Http/Controllers/StatisticsController.php index ba6a634..b478335 100644 --- a/app/Http/Controllers/StatisticsController.php +++ b/app/Http/Controllers/StatisticsController.php @@ -12,6 +12,7 @@ public function index() $elephpants = DB::table('elephpants') ->select(DB::raw('COUNT(elephpant_user.elephpant_id) as nbElephpant, name, description, SUM(elephpant_user.quantity) as totalElephpant')) ->leftJoin('elephpant_user', 'elephpants.id', '=', 'elephpant_user.elephpant_id') + ->where('prototype', 0) ->orderBy('nbElephpant', 'desc') ->orderBy('elephpants.id', 'desc') ->orderBy('totalElephpant', 'desc') diff --git a/app/Queries/RankedUsersQuery.php b/app/Queries/RankedUsersQuery.php index 8bb729b..7f1bf30 100644 --- a/app/Queries/RankedUsersQuery.php +++ b/app/Queries/RankedUsersQuery.php @@ -23,9 +23,11 @@ public function fetchAll(?string $country): Collection $users = $userQuery ->join('elephpant_user', 'users.id', '=', 'elephpant_user.user_id') + ->join('elephpants', 'elephpants.id', '=', 'elephpant_user.elephpant_id') ->select($visibleFields) ->selectRaw('SUM(elephpant_user.quantity) AS elephpants_total') ->selectRaw('COUNT(DISTINCT elephpant_user.elephpant_id) AS elephpants_unique') + ->where('prototype', 0) ->groupBy($visibleFields) ->orderBy('elephpants_unique', 'desc') ->orderBy('elephpants_total', 'desc') diff --git a/database/migrations/2023_07_29_145607_add_prototype_flag_to_elephpants_table.php b/database/migrations/2023_07_29_145607_add_prototype_flag_to_elephpants_table.php new file mode 100644 index 0000000..8a9353b --- /dev/null +++ b/database/migrations/2023_07_29_145607_add_prototype_flag_to_elephpants_table.php @@ -0,0 +1,32 @@ +boolean('prototype')->default(false)->after('image'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('elephpants', function (Blueprint $table) { + $table->dropColumn('prototype'); + }); + } +} diff --git a/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php b/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php new file mode 100644 index 0000000..82582ec --- /dev/null +++ b/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php @@ -0,0 +1,27 @@ +description }}
{{ $elephpant->sponsor }}
{{ $elephpant->year }} + @if ($elephpant->prototype) + • Prototype Only + @endif

diff --git a/resources/views/elephpant/index.blade.php b/resources/views/elephpant/index.blade.php index 47fc690..f39f93f 100644 --- a/resources/views/elephpant/index.blade.php +++ b/resources/views/elephpant/index.blade.php @@ -4,13 +4,16 @@

Species

- Here you can find all existent species. There are a total of {{ count($elephpants) }} species collected.
+ Here you can find all collectable species. There are a total of {{ count($elephpants) }} species collected.
Go to "My Herd" page

+

+ ElePHPants marked as Prototype Only are for reference and cannot be added to your herd or traded with other users as they were never mass produced. +

@foreach($elephpants as $key => $elephpant) @include('elephpant._single_box', compact('elephpant')) diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index e8ada4e..9b52238 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -15,9 +15,12 @@ @endguest
-
+
Total of existent species: {{ count($elephpants) }}
+

+ ElePHPants marked as Prototype Only are for reference and cannot be added to your herd or traded with other users as they were never mass produced. +

@foreach($elephpants as $key => $elephpant) @include('elephpant._single_box', compact('elephpant')) From 95a3ab6eec145c1d936dee1769282db7c21541ce Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 29 Jul 2023 16:51:38 +0100 Subject: [PATCH 02/10] remove memory set --- app/Console/Commands/ReadElephpants.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Console/Commands/ReadElephpants.php b/app/Console/Commands/ReadElephpants.php index cdef8ba..f2c7efe 100644 --- a/app/Console/Commands/ReadElephpants.php +++ b/app/Console/Commands/ReadElephpants.php @@ -14,8 +14,6 @@ class ReadElephpants extends Command public function handle(): void { - ini_set('memory_limit', '512M'); - $jsonFile = resource_path('data/elephpants.json'); $elephpants = json_decode(file_get_contents($jsonFile))->elephpants; From 279e8a51275200f76882439735146a4e15060248 Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 29 Jul 2023 16:57:55 +0100 Subject: [PATCH 03/10] undo word change --- resources/views/elephpant/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/elephpant/index.blade.php b/resources/views/elephpant/index.blade.php index f39f93f..63e81c5 100644 --- a/resources/views/elephpant/index.blade.php +++ b/resources/views/elephpant/index.blade.php @@ -4,7 +4,7 @@

Species

- Here you can find all collectable species. There are a total of {{ count($elephpants) }} species collected.
+ Here you can find all existent species. There are a total of {{ count($elephpants) }} species collected.
Go to "My Herd" page From 3f5b943a53aa27234c87063483df73e7e6658b68 Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 29 Jul 2023 17:40:07 +0100 Subject: [PATCH 04/10] remove unneeded logic --- app/Console/Commands/ReadElephpants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/ReadElephpants.php b/app/Console/Commands/ReadElephpants.php index f2c7efe..4d04bce 100644 --- a/app/Console/Commands/ReadElephpants.php +++ b/app/Console/Commands/ReadElephpants.php @@ -27,7 +27,7 @@ public function handle(): void 'sponsor' => $elephpant->sponsor, 'year' => (int)$elephpant->year, 'image' => $this->processImage($elephpant), - 'prototype' => $elephpant->prototype ?: 0 + 'prototype' => $elephpant->prototype ] ); } From 43f77e72060e6524c8a0a7871969e45cc06541fe Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 29 Jul 2023 18:14:17 +0100 Subject: [PATCH 05/10] add prototype to factory --- database/factories/ElephpantFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/factories/ElephpantFactory.php b/database/factories/ElephpantFactory.php index 9e816a1..c085646 100644 --- a/database/factories/ElephpantFactory.php +++ b/database/factories/ElephpantFactory.php @@ -12,5 +12,6 @@ 'year' => (int)$faker->dateTimeBetween('-12 years', 'now')->format('Y'), 'sponsor' => $faker->company, 'image' => $faker->imageUrl(), + 'prototype' => $faker->boolean(1) ]; }); From b9d83ce2c1db170b74b0720cd11dd621e35a5b28 Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Fri, 4 Aug 2023 01:48:39 +0100 Subject: [PATCH 06/10] update latest elephpants --- resources/data/elephpants.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/data/elephpants.json b/resources/data/elephpants.json index 3763b33..58aea03 100644 --- a/resources/data/elephpants.json +++ b/resources/data/elephpants.json @@ -654,7 +654,8 @@ "description": "ElePHPant for Alumni", "sponsor": "CMGT", "year": 2022, - "image": "73-cmgt.jpeg" + "image": "73-cmgt.jpeg", + "prototype": false }, { "id": 74, @@ -662,7 +663,8 @@ "description": "Laracon US 2023", "sponsor": "Laravel Community", "year": 2023, - "image": "74-aubrey.jpg" + "image": "74-aubrey.jpg", + "prototype": false } ] } From 2671f5e1699aeb4fa02b898cef6e639680c43aa7 Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Sat, 5 Aug 2023 02:17:35 +0100 Subject: [PATCH 07/10] show owners count --- app/Http/Controllers/ElephpantController.php | 7 ++++++- app/Http/Controllers/HomeController.php | 9 +++++++-- resources/views/elephpant/_single_box.blade.php | 6 ++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ElephpantController.php b/app/Http/Controllers/ElephpantController.php index 4118f3d..e33857a 100644 --- a/app/Http/Controllers/ElephpantController.php +++ b/app/Http/Controllers/ElephpantController.php @@ -9,7 +9,12 @@ class ElephpantController extends Controller { public function index() { - $elephpants = Elephpant::query()->withoutGlobalScope('nonPrototype')->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); + $elephpants = Elephpant::query() + ->withCount('users') + ->withoutGlobalScope('nonPrototype') + ->orderBy('year', 'desc') + ->orderBy('id', 'desc') + ->get(); return view('elephpant.index', compact('elephpants')); } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 07ec8d0..69fabab 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,8 +8,13 @@ class HomeController extends Controller { public function index() { - $elephpants = Elephpant::query()->withoutGlobalScope('nonPrototype')->orderBy('year', 'desc')->orderBy('id', 'desc')->get(); - + $elephpants = Elephpant::query() + ->withCount('users') + ->withoutGlobalScope('nonPrototype') + ->orderBy('year', 'desc') + ->orderBy('id', 'desc') + ->get(); + return view('home', compact('elephpants')); } } diff --git a/resources/views/elephpant/_single_box.blade.php b/resources/views/elephpant/_single_box.blade.php index f2587ca..c28bbd7 100644 --- a/resources/views/elephpant/_single_box.blade.php +++ b/resources/views/elephpant/_single_box.blade.php @@ -9,9 +9,11 @@

{{ $elephpant->description }}
{{ $elephpant->sponsor }}
- {{ $elephpant->year }} + {{ $elephpant->year }}
@if ($elephpant->prototype) - • Prototype Only + Prototype Only + @else + {{ $elephpant->users_count }} {{ Str::plural('owner', $elephpant->users_count) }} @endif

From 9cbcebb9df055d7953d28770bdb122b417fb003e Mon Sep 17 00:00:00 2001 From: JonPurvis Date: Tue, 30 Jan 2024 20:08:38 +0000 Subject: [PATCH 08/10] update new elephpants --- resources/data/elephpants.json | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/resources/data/elephpants.json b/resources/data/elephpants.json index 3cb482c..08bb115 100644 --- a/resources/data/elephpants.json +++ b/resources/data/elephpants.json @@ -493,7 +493,7 @@ "sponsor": "Monsieur Biz", "year": 2020, "image": "55-sylius.jpg", - "prototype": true + "prototype": false }, { "id": 56, @@ -663,7 +663,8 @@ "description": "Laracon US 2023", "sponsor": "Laravel Community", "year": 2023, - "image": "74-aubrey.jpg" + "image": "74-aubrey.jpg", + "prototype": false }, { "id": 75, @@ -671,7 +672,8 @@ "description": "PHPClasses", "sponsor": "PHPClasses", "year": 2020, - "image": "75-phpclasses-pink.png" + "image": "75-phpclasses-pink.png", + "prototype": false }, { "id": 76, @@ -679,7 +681,8 @@ "description": "Dyflexis", "sponsor": "Dyflexis", "year": 2023, - "image": "76-dyflexis.jpg" + "image": "76-dyflexis.jpg", + "prototype": false }, { "id": 77, @@ -687,7 +690,8 @@ "description": "PHPStan", "sponsor": "PHPStan", "year": 2024, - "image": "77-phpstan.jpg" + "image": "77-phpstan.jpg", + "prototype": false }, { "id": 78, @@ -695,7 +699,8 @@ "description": "PHP UK", "sponsor": "PHP UK", "year": 2024, - "image": "78-phpuk.jpg" + "image": "78-phpuk.jpg", + "prototype": false } ] } From 602cbde7fd16f236e75eccb5461ac1eea0ecfc79 Mon Sep 17 00:00:00 2001 From: jp Date: Mon, 16 Sep 2024 02:00:52 +0100 Subject: [PATCH 09/10] Update database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php Co-authored-by: Tim Bond --- ...7_29_154546_remove_prototype_elephpants_from_collections.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php b/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php index 82582ec..54c0171 100644 --- a/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php +++ b/database/migrations/2023_07_29_154546_remove_prototype_elephpants_from_collections.php @@ -13,7 +13,7 @@ class RemovePrototypeElephpantsFromCollections extends Migration */ public function up() { - DB::statement('DELETE FROM elephpant_user WHERE elephpant_id IN (52,53,55,62)'); + DB::statement('DELETE FROM elephpant_user WHERE elephpant_id IN (52,53,55,62,77)'); } /** From b11d37aa4b39813c9dbbf12fee8446a27243d021 Mon Sep 17 00:00:00 2001 From: jp Date: Mon, 16 Sep 2024 02:02:58 +0100 Subject: [PATCH 10/10] Update elephpants.json --- resources/data/elephpants.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/data/elephpants.json b/resources/data/elephpants.json index c3ee6aa..09bddb7 100644 --- a/resources/data/elephpants.json +++ b/resources/data/elephpants.json @@ -691,7 +691,7 @@ "sponsor": "PHPStan", "year": 2024, "image": "77-phpstan.jpg", - "prototype": false + "prototype": true }, { "id": 78,