From b03f2e6b7dbd25b7d0bebc8238aabd66f9260811 Mon Sep 17 00:00:00 2001 From: Spine Date: Wed, 1 Oct 2025 06:33:30 +0000 Subject: [PATCH] twigify torrent artists sidebar --- app/ArtistRole/TGroup.php | 2 + sections/torrents/details.php | 125 ++++++--------------------- templates/tgroup/artist-sidebar.twig | 52 +++++++++++ tests/phpunit/ArtistTest.php | 12 ++- tests/phpunit/CategoryTest.php | 3 +- tests/phpunit/TGroupTest.php | 2 + 6 files changed, 93 insertions(+), 103 deletions(-) create mode 100644 templates/tgroup/artist-sidebar.twig diff --git a/app/ArtistRole/TGroup.php b/app/ArtistRole/TGroup.php index f841deeca..dc52a407a 100644 --- a/app/ArtistRole/TGroup.php +++ b/app/ArtistRole/TGroup.php @@ -44,11 +44,13 @@ class TGroup extends \Gazelle\ArtistRole { $this->idList[$roleId][] = [ 'id' => $artist['artist_id'], 'aliasid' => $artist['alias_id'], + 'artist' => $this->manager->findByAliasId($artist['alias_id']), 'name' => $artist['name'], ]; $this->roleList[self::MAP[$roleId]][] = [ 'id' => $artist['artist_id'], 'aliasid' => $artist['alias_id'], + 'artist' => $this->manager->findByAliasId($artist['alias_id']), 'name' => $artist['name'], ]; } diff --git a/sections/torrents/details.php b/sections/torrents/details.php index f60b618c5..9a2f8e6b1 100644 --- a/sections/torrents/details.php +++ b/sections/torrents/details.php @@ -18,39 +18,25 @@ $tgroup = $tgMan->findById((int)($_GET['id'] ?? 0)); if (is_null($tgroup)) { Error404::error(); } -$tgroupId = $tgroup->id; -$RevisionID = (int)($_GET['revisionid'] ?? 0); // Comments (must be loaded before View::show_header so that subscriptions and quote notifications are handled properly) -$commentPage = new Comment\Torrent($tgroupId, (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0)); +$commentPage = new Comment\Torrent($tgroup->id, (int)($_GET['page'] ?? 0), (int)($_GET['postid'] ?? 0)); $commentPage->load()->handleSubscription($Viewer); $paginator = new Util\Paginator(TORRENT_COMMENTS_PER_PAGE, $commentPage->pageNum()); $paginator->setAnchor('comments')->setTotal($commentPage->total())->removeParam('postid'); -$artistMan = new Manager\Artist(); -$collageMan = new Manager\Collage(); -$torMan = new Manager\Torrent(); -$reportMan = new Manager\Torrent\Report($torMan); -$requestMan = new Manager\Request(); -$userMan = new Manager\User(); -$vote = new User\Vote($Viewer); -$snatcher = $Viewer->snatch(); - -$isSubscribed = new User\Subscription($Viewer)->isSubscribedComments('torrents', $tgroupId); -$releaseTypes = new ReleaseType()->list(); -$urlStem = new User\Stylesheet($Viewer)->imagePath(); - -$categoryId = $tgroup->categoryId(); -$musicRelease = $tgroup->categoryName() == 'Music'; -$year = $tgroup->year(); -$torrentList = $tgroup->torrentIdList(); -$removed = $torrentList ? [] : $tgroup->deletedMasteringList(); +$collageMan = new Manager\Collage(); +$torMan = new Manager\Torrent(); +$isSubscribed = new User\Subscription($Viewer)->isSubscribedComments('torrents', $tgroup->id); +$urlStem = new User\Stylesheet($Viewer)->imagePath(); +$torrentList = $tgroup->torrentIdList(); +$roleList = $tgroup->artistRole()?->roleList(); $section = [ ['id' => ARTIST_COMPOSER, 'name' => 'composer', 'class' => 'artists_composers', 'role' => 'Composer', 'title' => 'Composers:'], ['id' => ARTIST_DJ, 'name' => 'dj', 'class' => 'artists_dj', 'role' => 'DJ / Compiler', 'title' => 'DJ / Compiler:'], - ['id' => ARTIST_MAIN, 'name' => 'main', 'class' => 'artists_main', 'role' => 'Artist', 'title' => empty($role['conductor']) ? 'Artists:' : 'Performers:'], + ['id' => ARTIST_MAIN, 'name' => 'main', 'class' => 'artists_main', 'role' => 'Artist', 'title' => isset($roleList['conductor']) ? 'Performers:' : 'Artists:'], ['id' => ARTIST_GUEST, 'name' => 'guest', 'class' => 'artists_guest', 'role' => 'Guest', 'title' => 'With:'], ['id' => ARTIST_CONDUCTOR, 'name' => 'conductor', 'class' => 'artists_conductors', 'role' => 'Conductor', 'title' => 'Conducted by:'], ['id' => ARTIST_REMIXER, 'name' => 'remixer', 'class' => 'artists_remix', 'role' => 'Remixer', 'title' => 'Remixed by:'], @@ -61,87 +47,27 @@ $section = [ echo $Twig->render('torrent/detail-header.twig', [ 'is_bookmarked' => new User\Bookmark($Viewer)->isBookmarked($tgroup), 'is_subscribed' => $isSubscribed, - 'revision_id' => $RevisionID, + 'revision_id' => (int)($_GET['revisionid'] ?? 0), 'tgroup' => $tgroup, 'viewer' => $Viewer, ]); -?> -artistRole()->roleList(); -?> -
-
Artists -permitted('torrents_edit')) { ?> - Edit - -
- -
-permitted('torrents_add_artist')) { - usort($section, fn ($x, $y) => $x['id'] <=> $y['id']); -?> -
-
Add artist+
-
-
-
- - - - hasAutocomplete('other') ? ' data-gazelle-autocomplete="true"' : '' ?> /> - -
- -
-
-
-categoryName() == 'Music') { + echo $Twig->render('tgroup/artist-sidebar.twig', [ + 'role' => $roleList, + 'section' => $section, + 'tgroup' => $tgroup, + 'viewer' => $Viewer, + ]); } echo $Twig->render('tgroup/stats.twig', [ 'collage_list' => $collageMan->addToCollageDefault($tgroup, $Viewer), - 'featured' => new Manager\FeaturedAlbum()->findById($tgroupId), - 'tag_undo' => $Cache->get_value("deleted_tags_{$tgroupId}_{$Viewer->id}"), + 'featured' => new Manager\FeaturedAlbum()->findById($tgroup->id), + 'tag_undo' => $Cache->get_value("deleted_tags_{$tgroup->id}_{$Viewer->id}"), 'tgroup' => $tgroup, 'viewer' => $Viewer, - 'vote' => $vote, + 'vote' => new User\Vote($Viewer), ]); ?> @@ -173,10 +99,10 @@ echo $Twig->render('collage/summary.twig', [ deletedMasteringList() as $info) { $mastering = implode('/', [$info['year'], $info['title'], $info['record_label'], $info['catalogue_number'], $info['media']]); ?> - + [] @@ -191,10 +117,10 @@ if (!$torrentList) { } else { echo $Twig->render('torrent/detail-torrentgroup.twig', [ 'is_snatched_grp' => $tgroup->isSnatched(), - 'report_man' => $reportMan, + 'report_man' => new Manager\Torrent\Report($torMan), 'show_extended' => true, 'show_id' => ($_GET['torrentid'] ?? ''), - 'snatcher' => $snatcher, + 'snatcher' => $Viewer->snatch(), 'tgroup' => $tgroup, 'torrent_list' => object_generator($torMan, $torrentList), 'tor_man' => $torMan, @@ -203,11 +129,10 @@ if (!$torrentList) { } ?> disableRequests()) { echo $Twig->render('request/torrent.twig', [ 'bounty' => $Viewer->ordinal()->value('request-bounty-vote'), - 'list' => $requestMan->findByTGroup($tgroup), + 'list' => new Manager\Request()->findByTGroup($tgroup), 'viewer' => $Viewer, ]); } @@ -235,7 +160,7 @@ echo $Twig->render('tgroup/similar.twig', [ 'textarea' => new Util\Textarea('quickpost', '')->setPreviewManual(true), 'url' => $_SERVER['REQUEST_URI'], 'url_stem' => 'comments.php?page=torrents', - 'userMan' => $userMan, + 'userMan' => new Manager\User(), 'viewer' => $Viewer, ]) ?> diff --git a/templates/tgroup/artist-sidebar.twig b/templates/tgroup/artist-sidebar.twig new file mode 100644 index 000000000..efc768d07 --- /dev/null +++ b/templates/tgroup/artist-sidebar.twig @@ -0,0 +1,52 @@ +{% from 'macro/form.twig' import autocomplete %} +
+
Artists +{% if viewer.permitted('torrents_edit') %} + Edit +{% endif %} +
+ +
+{% if viewer.permitted('torrents_add_artist') %} +
+
Add artist+
+
+
+
+ + + + + +
+ +
+
+
+{% endif %} diff --git a/tests/phpunit/ArtistTest.php b/tests/phpunit/ArtistTest.php index ef848f01b..92d7c02a1 100644 --- a/tests/phpunit/ArtistTest.php +++ b/tests/phpunit/ArtistTest.php @@ -296,9 +296,17 @@ class ArtistTest extends TestCase { foreach ($this->tgroupList as $tgroup) { ++$n; $artistRole = $tgroup->flush()->artistRole(); + // cannot use flush() as the aliasId is wiped, replace the object by its id + $actual = $artistRole->idList()[ARTIST_MAIN][0]; + $actual['artist'] = $actual['artist']->id; $this->assertEquals( - [ARTIST_MAIN => [['id' => $new->id, 'name' => $oldName, 'aliasid' => $oldAliasId]]], - $artistRole->idList(), + [ + 'id' => $new->id, + 'aliasid' => $oldAliasId, + 'artist' => $new->id, + 'name' => $oldName, + ], + $actual, "art-merge-ar-$n" ); } diff --git a/tests/phpunit/CategoryTest.php b/tests/phpunit/CategoryTest.php index 6be634f43..6d9de3de5 100644 --- a/tests/phpunit/CategoryTest.php +++ b/tests/phpunit/CategoryTest.php @@ -65,7 +65,8 @@ class CategoryTest extends TestCase { ARTIST_MAIN => [[ 'id' => $artist->id, 'name' => $artist->name(), - 'aliasid' => $artist->aliasId() + 'aliasid' => $artist->aliasId(), + 'artist' => $artist->flush(), ]], ], $new->artistRole()?->idList(), diff --git a/tests/phpunit/TGroupTest.php b/tests/phpunit/TGroupTest.php index 18be934e8..fcbe464de 100644 --- a/tests/phpunit/TGroupTest.php +++ b/tests/phpunit/TGroupTest.php @@ -209,6 +209,7 @@ class TGroupTest extends TestCase { "id" => $artist->id, "aliasid" => $artist->aliasId(), "name" => $artist->name(), + "artist" => $artist->flush(), ]], "with" => [], "remixedBy" => [], @@ -227,6 +228,7 @@ class TGroupTest extends TestCase { "id" => $artist->id, "aliasid" => $artist->aliasId(), "name" => $artist->name(), + "artist" => $artist->flush(), ]], "2" => null, "3" => null,