From e54d7f9f3fb0c2d771f5153a2b145bac2cd1a74c Mon Sep 17 00:00:00 2001 From: Spine Date: Fri, 29 Dec 2023 11:15:19 +0000 Subject: [PATCH] fix ajax top10 for non-music groups --- app/API/Torrent.php | 4 ++-- app/TGroup.php | 8 ++++++-- app/TorrentAbstract.php | 2 +- tests/phpunit/CategoryTest.php | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/API/Torrent.php b/app/API/Torrent.php index cb16c584b..8b0305854 100644 --- a/app/API/Torrent.php +++ b/app/API/Torrent.php @@ -31,7 +31,7 @@ protected function torrent(int $id): array { 'Year' => $tgroup->year(), 'ReleaseTypeID' => $tgroup->releaseType(), 'ReleaseType' => $tgroup->releaseTypeName(), - 'Artists' => $tgroup->artistRole()->idList(), + 'Artists' => $tgroup->artistRole()?->idList(), 'DisplayArtists' => $tgroup->artistName(), 'Media' => $torrent->media(), 'Format' => $torrent->format(), @@ -55,7 +55,7 @@ protected function tgroup(int $id): array { 'Year' => $tgroup->year(), 'ReleaseTypeID' => $tgroup->releaseType(), 'ReleaseType' => $tgroup->releaseTypeName(), - 'Artists' => $tgroup->artistRole()->idList(), + 'Artists' => $tgroup->artistRole()?->idList(), 'DisplayArtists' => $tgroup->artistName(), ]; } diff --git a/app/TGroup.php b/app/TGroup.php index c0af73592..f754d4f45 100644 --- a/app/TGroup.php +++ b/app/TGroup.php @@ -294,8 +294,8 @@ protected function fetchIsSnatched(): bool { ); } - public function artistName(): string { - return $this->artistRole()->text(); + public function artistName(): ?string { + return $this->artistRole()?->text(); } public function artistRole(): ?ArtistRole\TGroup { @@ -308,6 +308,10 @@ public function artistRole(): ?ArtistRole\TGroup { return $this->artistRole; } + public function hasArtistRole(): bool { + return $this->artistRole() instanceof ArtistRole\TGroup; + } + public function catalogueNumber(): ?string { return $this->info()['CatalogueNumber']; } diff --git a/app/TorrentAbstract.php b/app/TorrentAbstract.php index 260da3ebd..56b073bb8 100644 --- a/app/TorrentAbstract.php +++ b/app/TorrentAbstract.php @@ -49,7 +49,7 @@ public function fullLink(): string { public function name(): string { $tgroup = $this->group(); - return $tgroup->categoryName() === 'Music' + return $tgroup->hasArtistRole() ? $tgroup->artistName() . " – " . $tgroup->name() : $tgroup->name(); } diff --git a/tests/phpunit/CategoryTest.php b/tests/phpunit/CategoryTest.php index 1c2d8a10d..433697181 100644 --- a/tests/phpunit/CategoryTest.php +++ b/tests/phpunit/CategoryTest.php @@ -29,6 +29,7 @@ public function testChangeCategory(): void { name: 'phpunit category change ' . randomString(6), user: $user, ); + $this->assertFalse($tgroup->hasArtistRole(), 'tgroup-cat-non-music'); $torrentList = array_map(fn($info) => Helper::makeTorrentEBook( tgroup: $tgroup, @@ -56,6 +57,7 @@ public function testChangeCategory(): void { user: $user, ); $this->assertInstanceOf(Gazelle\TGroup::class, $new, 'cat-change-to-music'); + $this->assertTrue($new->hasArtistRole(), 'tgroup-cat-is-music'); $artist = (new Gazelle\Manager\Artist)->findByName($artistName); $this->assertEquals($artistName, $artist->name(), 'cat-new-artist'); $this->assertEquals(