diff options
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Card.php | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/src/Model/Card.php b/src/Model/Card.php index abaa06e..59d2639 100644 --- a/src/Model/Card.php +++ b/src/Model/Card.php @@ -104,24 +104,71 @@ class Card // 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(); - + #->findFirst(fn (CardMeta $item) => $item->key === $key); + ->filter(fn ($item) => $item->key === $key)->first(); return $meta->value ?? 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' + 'SELECT cm.value + FROM Elements\Model\CardMeta cm + WHERE cm.key = :key AND cm.card = :card' ) ->setParameter('key', $key) ->setParameter('card', $this) ->getOneOrNullResult(); - return $result['value'] ?? null; + return $result['value'] ?? null; + } + + /** + * @return CardMeta[] + */ + public function getAllMeta() + { + // TODO: do we need this? + // if meta is already hydrated + if ($this->meta->isInitialized()) { + return $this->meta; + } + + // get directly from db otherwise + $result = DB::$entityManager + ->createQuery( + 'SELECT cm + FROM Elements\Model\CardMeta cm + WHERE cm.card = :card' + ) + ->setParameter('card', $this) + ->getArrayResult(); + + return $result; + } + + /** + * @return Artwork[] + */ + public function getAllArtworks() + { + // TODO: do we need this? + // if artworks are already hydrated + if ($this->artworks->isInitialized()) { + return $this->artworks; + } + + // get directly from db otherwise + $result = DB::$entityManager + ->createQuery( + 'SELECT aw + FROM Elements\Model\Artwork aw + WHERE aw.card = :card' + ) + ->setParameter('card', $this) + ->getArrayResult(); + + return $result; } /** |