summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Model/Card.php8
-rw-r--r--src/Model/CardMeta.php10
-rw-r--r--src/Model/Category.php61
3 files changed, 79 insertions, 0 deletions
diff --git a/src/Model/Card.php b/src/Model/Card.php
index 9707e16..abaa06e 100644
--- a/src/Model/Card.php
+++ b/src/Model/Card.php
@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
+use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\PersistentCollection;
use Elements\DB;
@@ -49,6 +50,12 @@ class Card
*/
public Collection|ArrayCollection|PersistentCollection $votes;
+ #[ManyToMany(targetEntity: Category::class, inversedBy: 'cards')]
+ /**
+ * @ManyToMany(targetEntity="Category", inversedBy="cards", cascade={"persist"})
+ */
+ public Collection|ArrayCollection|PersistentCollection $categories;
+
/**
* Card constructor.
*/
@@ -57,6 +64,7 @@ class Card
$this->meta = new ArrayCollection();
$this->artworks = new ArrayCollection();
$this->votes = new ArrayCollection();
+ $this->categories = new ArrayCollection();
}
/**
diff --git a/src/Model/CardMeta.php b/src/Model/CardMeta.php
index 2ec0da9..9e0f544 100644
--- a/src/Model/CardMeta.php
+++ b/src/Model/CardMeta.php
@@ -2,12 +2,15 @@
namespace Elements\Model;
+use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
+use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
+use Doctrine\ORM\PersistentCollection;
#[Entity]
#[Table(name: 'card_meta')]
@@ -45,6 +48,12 @@ class CardMeta
*/
public Card $card;
+ #[ManyToMany(targetEntity: Category::class, inversedBy: 'meta')]
+ /**
+ * @ManyToMany(targetEntity="Category", inversedBy="meta", cascade={"persist"})
+ */
+ public Collection|ArrayCollection|PersistentCollection $categories;
+
/**
* CardMeta constructor.
*/
@@ -52,6 +61,7 @@ class CardMeta
{
$this->key = $key;
$this->value = $value;
+ $this->categories = new ArrayCollection();
}
}
diff --git a/src/Model/Category.php b/src/Model/Category.php
new file mode 100644
index 0000000..84d12a3
--- /dev/null
+++ b/src/Model/Category.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Elements\Model;
+
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\DBAL\Schema\Column;
+use Doctrine\DBAL\Schema\Table;
+use Doctrine\ORM\Mapping\Entity;
+use Doctrine\ORM\Mapping\GeneratedValue;
+use Doctrine\ORM\Mapping\Id;
+use Doctrine\ORM\Mapping\ManyToMany;
+use Doctrine\ORM\Mapping\ManyToOne;
+use Doctrine\ORM\PersistentCollection;
+
+#[Entity]
+#[Table(name: 'categories')]
+/**
+ * @Entity
+ * @Table(name="categories")
+ */
+class Category
+{
+ #[Id]
+ #[Column(type: 'integer')]
+ #[GeneratedValue]
+ /**
+ * @Id
+ * @Column(type="integer")
+ * @GeneratedValue
+ */
+ public int $id;
+
+ #[Column(type: 'string')]
+ /**
+ * @Column(type="string")
+ */
+ public string $name;
+
+ #[ManyToMany(targetEntity: Card::class, mappedBy: 'categories')]
+ /**
+ * @ManyToMany(targetEntity="Card", mappedBy="categories", cascade={"persist"})
+ */
+ public Collection|ArrayCollection|PersistentCollection $cards;
+
+ #[ManyToMany(targetEntity: CardMeta::class, mappedBy: 'categories')]
+ /**
+ * @ManyToMany(targetEntity="CardMeta", mappedBy="categories", cascade={"persist"})
+ */
+ public Collection|ArrayCollection|PersistentCollection $meta;
+
+ /**
+ * Category constructor.
+ */
+ public function __construct(string $name)
+ {
+ $this->name = $name;
+ $this->cards = new ArrayCollection();
+ $this->meta = new ArrayCollection();
+ }
+}
+