diff --git a/src/Controller/UserReleasesController.php b/src/Controller/UserReleasesController.php new file mode 100644 index 0000000..3ea8772 --- /dev/null +++ b/src/Controller/UserReleasesController.php @@ -0,0 +1,28 @@ +getUserListing($user); + return $this->render( + 'user_releases/index.html.twig', + [ + 'username' => $user->getUsername(), + 'releases' => $releases, + ] + ); + } +} diff --git a/src/Entity/Release.php b/src/Entity/Release.php index 0cbe458..28c6c2a 100644 --- a/src/Entity/Release.php +++ b/src/Entity/Release.php @@ -19,6 +19,7 @@ class Release private ?string $title = null; #[ORM\ManyToMany(targetEntity: Artist::class, inversedBy: 'releases')] + #[ORM\OrderBy(['name' => 'ASC'])] private Collection $artists; #[ORM\ManyToOne(inversedBy: 'releases')] diff --git a/src/Entity/User.php b/src/Entity/User.php index 6df7a0e..744d66e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -34,6 +34,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface private ?string $username = null; #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Release::class)] + #[ORM\OrderBy(['title' => 'ASC'])] private Collection $releases; public function __construct() diff --git a/src/Repository/ReleaseRepository.php b/src/Repository/ReleaseRepository.php index b9aa47e..944689b 100644 --- a/src/Repository/ReleaseRepository.php +++ b/src/Repository/ReleaseRepository.php @@ -3,6 +3,7 @@ namespace App\Repository; use App\Entity\Release; +use App\Entity\User; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -20,4 +21,31 @@ class ReleaseRepository extends ServiceEntityRepository { parent::__construct($registry, Release::class); } + + /** + * Return the user release listing as an array of associative arrays. + * + * The listing includes all releases with this user as owner. Items are sorted by the "artist aggregation" name. An + * artist aggregation is the joint names of all artists linked to a release. Within an artist aggregation (which + * most of the time is probably just an artist name), releases are sorted by title (should be by release date). + * + * Included data is: + * - release_id + * - title + * - artists (artist aggregation) + * + * @return array> + */ + public function getUserListing(User $user): array + { + return $this->getEntityManager()->getConnection()->executeQuery(' + SELECT r.id AS release_id, title, string_agg(name, \' & \' ORDER BY name) AS artists + FROM release r + JOIN release_artist ra ON ra.release_id = r.id + JOIN artist a ON a.id = ra.artist_id + GROUP BY r.id + --HAVING COUNT(*) > 1 + ORDER BY artists, title + ')->fetchAllAssociative(); + } } diff --git a/templates/user_releases/index.html.twig b/templates/user_releases/index.html.twig new file mode 100644 index 0000000..b5c2942 --- /dev/null +++ b/templates/user_releases/index.html.twig @@ -0,0 +1,13 @@ +{% extends 'base.html.twig' %} + +{% block title %}{{ username }} releases{% endblock %} + +{% block body %} +

{{ username }} releases

+ + +{% endblock %}