diff options
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; + } } |