summaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorJonathan Tschanter <jmtw@tutanota.de>2022-01-22 21:24:24 +0100
committerJonathan Tschanter <jmtw@tutanota.de>2022-01-22 21:24:24 +0100
commit10c86197f1f63e222dfc9e937911e35ab500a208 (patch)
tree388ca37920808a66697385c6d69cf6a76e5aaf7b /src/Model
parent432bba3dee1d9be25b9626ac45115929a6422961 (diff)
Adds edit cards and templates to include
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/Card.php33
-rw-r--r--src/Model/Vote.php8
-rw-r--r--src/Model/VoteCard.php5
3 files changed, 33 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;
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;
+ }
}