diff options
author | Daniel Weipert <code@drogueronin.de> | 2022-01-14 18:21:36 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2022-01-14 18:21:36 +0100 |
commit | 4cacc94240944ff316104bfd1b5e8e00fad14517 (patch) | |
tree | 2559dc3aa121d70bd645ff0a2fe56e1ae0695daa /src/Model/Card.php | |
parent | 9c0893cb65df986b9edf0f48a6d4d2d65f27b8ef (diff) |
Add Artworks, Votes and better routing
Diffstat (limited to 'src/Model/Card.php')
-rw-r--r-- | src/Model/Card.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Model/Card.php b/src/Model/Card.php index ab421ab..9707e16 100644 --- a/src/Model/Card.php +++ b/src/Model/Card.php @@ -37,12 +37,26 @@ class Card */ public Collection|ArrayCollection|PersistentCollection $meta; + #[OneToMany(targetEntity: Artwork::class, mappedBy: 'card')] + /** + * @OneToMany(targetEntity="Artwork", mappedBy="card") + */ + public Collection|ArrayCollection|PersistentCollection $artworks; + + #[OneToMany(targetEntity: VoteCard::class, mappedBy: 'card')] + /** + * @OneToMany(targetEntity="VoteCard", mappedBy="card") + */ + public Collection|ArrayCollection|PersistentCollection $votes; + /** * Card constructor. */ public function __construct() { $this->meta = new ArrayCollection(); + $this->artworks = new ArrayCollection(); + $this->votes = new ArrayCollection(); } /** @@ -55,6 +69,24 @@ class Card } /** + * @param Artwork $artwork + */ + public function addArtwork(Artwork $artwork) + { + $artwork->card = $this; + $this->artworks[] = $artwork; + } + + /** + * @param VoteCard $vote + */ + public function addVote(VoteCard $vote) + { + $vote->card = $this; + $this->votes[] = $vote; + } + + /** * @param string $key * * @return string @@ -83,5 +115,22 @@ class Card return $result['value'] ?? null; } + + /** + * @return int + */ + public function getVotesTotal(): int + { + $result = DB::$entityManager + ->createQuery( + 'SELECT sum(v.value) as total + FROM Elements\Model\VoteCard v + WHERE v.card = :card' + ) + ->setParameter('card', $this) + ->getOneOrNullResult(); + + return $result['total'] ?? 0; + } } |