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 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/Model/Card.php') 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; -- cgit v1.2.3