diff options
Diffstat (limited to 'src/Model/Card.php')
-rw-r--r-- | src/Model/Card.php | 33 |
1 files changed, 20 insertions, 13 deletions
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; |