Skip to content

Commit

Permalink
fix ajax top10 for non-music groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine committed Jan 1, 2024
1 parent 73f3c3d commit e54d7f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/API/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
];
}
Expand Down
8 changes: 6 additions & 2 deletions app/TGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion app/TorrentAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e54d7f9

Please sign in to comment.