From 10c86197f1f63e222dfc9e937911e35ab500a208 Mon Sep 17 00:00:00 2001 From: Jonathan Tschanter Date: Sat, 22 Jan 2022 21:24:24 +0100 Subject: Adds edit cards and templates to include --- src/Model/Card.php | 33 ++++++++++++++++++++------------- src/Model/Vote.php | 8 ++++++++ src/Model/VoteCard.php | 5 +++++ 3 files changed, 33 insertions(+), 13 deletions(-) (limited to 'src/Model') diff --git a/src/Model/Card.php b/src/Model/Card.php index 59d2639..934fc2d 100644 --- a/src/Model/Card.php +++ b/src/Model/Card.php @@ -99,28 +99,35 @@ class Card * * @return string */ - public function getMeta(string $key): ?string + public function getMetaValue(string $key): ?string + { + return $this->getMeta($key)->value ?? null; + } + + /** + * @param string $key + * + * @return CardMeta + */ + public function getMeta(string $key): ?CardMeta { // if meta is already hydrated if ($this->meta->isInitialized()) { $meta = $this->meta->unwrap() #->findFirst(fn (CardMeta $item) => $item->key === $key); ->filter(fn ($item) => $item->key === $key)->first(); - return $meta->value ?? null; + return $meta ?? null; } // get directly from db otherwise $result = DB::$entityManager - ->createQuery( - 'SELECT cm.value - FROM Elements\Model\CardMeta cm - WHERE cm.key = :key AND cm.card = :card' - ) - ->setParameter('key', $key) - ->setParameter('card', $this) - ->getOneOrNullResult(); + ->getRepository(CardMeta::class) + ->findOneBy([ + 'key' => $key, + 'card' => $this + ]); - return $result['value'] ?? null; + return $result ?? null; } /** @@ -128,7 +135,7 @@ class Card */ public function getAllMeta() { - // TODO: do we need this? + // TODO: change! // if meta is already hydrated if ($this->meta->isInitialized()) { return $this->meta; @@ -152,7 +159,7 @@ class Card */ public function getAllArtworks() { - // TODO: do we need this? + // TODO: change! // if artworks are already hydrated if ($this->artworks->isInitialized()) { return $this->artworks; diff --git a/src/Model/Vote.php b/src/Model/Vote.php index c5415aa..273a7d8 100644 --- a/src/Model/Vote.php +++ b/src/Model/Vote.php @@ -26,5 +26,13 @@ class Vote * @Column(type="integer") */ public int $value; + + /** + * Vote constructor. + */ + public function __contruct(int $value) + { + $this->value = $value; + } } diff --git a/src/Model/VoteCard.php b/src/Model/VoteCard.php index e9b3e60..292789f 100644 --- a/src/Model/VoteCard.php +++ b/src/Model/VoteCard.php @@ -22,5 +22,10 @@ class VoteCard extends Vote * @ManyToOne(targetEntity="Card", inversedBy="votes", cascade={"persist"}) */ public Card $card; + + public function __contruct(int $value) + { + $this->card = $card; + } } -- cgit v1.2.3