diff --git a/migrations/Version20250214100702.php b/migrations/Version20250214100702.php new file mode 100644 index 00000000..4b1d9642 --- /dev/null +++ b/migrations/Version20250214100702.php @@ -0,0 +1,73 @@ +addSql('CREATE TABLE selling_product (selling_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_6F085AF0155A4545 (selling_id), INDEX IDX_6F085AF04584665A (product_id), PRIMARY KEY(selling_id, product_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE selling_product ADD CONSTRAINT FK_6F085AF0155A4545 FOREIGN KEY (selling_id) REFERENCES selling (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE selling_product ADD CONSTRAINT FK_6F085AF04584665A FOREIGN KEY (product_id) REFERENCES product (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE category ADD user_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE category ADD CONSTRAINT FK_64C19C1A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('CREATE INDEX IDX_64C19C1A76ED395 ON category (user_id)'); + $this->addSql('ALTER TABLE expense ADD user_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE expense ADD CONSTRAINT FK_2D3A8DA6A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('CREATE INDEX IDX_2D3A8DA6A76ED395 ON expense (user_id)'); + $this->addSql('ALTER TABLE festival ADD user_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE festival ADD CONSTRAINT FK_57CF789A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('CREATE INDEX IDX_57CF789A76ED395 ON festival (user_id)'); + $this->addSql('ALTER TABLE group_of_products ADD user_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE group_of_products ADD CONSTRAINT FK_2A99B370A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('CREATE INDEX IDX_2A99B370A76ED395 ON group_of_products (user_id)'); + $this->addSql('ALTER TABLE product ADD user_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04ADA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('CREATE INDEX IDX_D34A04ADA76ED395 ON product (user_id)'); + $this->addSql('ALTER TABLE selling DROP products'); + $this->addSql('ALTER TABLE user ADD current_festival_id INT DEFAULT NULL, DROP owner, DROP expenses, DROP current_festival'); + $this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D649343F048E FOREIGN KEY (current_festival_id) REFERENCES festival (id)'); + $this->addSql('CREATE INDEX IDX_8D93D649343F048E ON user (current_festival_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE selling_product DROP FOREIGN KEY FK_6F085AF0155A4545'); + $this->addSql('ALTER TABLE selling_product DROP FOREIGN KEY FK_6F085AF04584665A'); + $this->addSql('DROP TABLE selling_product'); + $this->addSql('ALTER TABLE expense DROP FOREIGN KEY FK_2D3A8DA6A76ED395'); + $this->addSql('DROP INDEX IDX_2D3A8DA6A76ED395 ON expense'); + $this->addSql('ALTER TABLE expense DROP user_id'); + $this->addSql('ALTER TABLE festival DROP FOREIGN KEY FK_57CF789A76ED395'); + $this->addSql('DROP INDEX IDX_57CF789A76ED395 ON festival'); + $this->addSql('ALTER TABLE festival DROP user_id'); + $this->addSql('ALTER TABLE selling ADD products LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\''); + $this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04ADA76ED395'); + $this->addSql('DROP INDEX IDX_D34A04ADA76ED395 ON product'); + $this->addSql('ALTER TABLE product DROP user_id'); + $this->addSql('ALTER TABLE category DROP FOREIGN KEY FK_64C19C1A76ED395'); + $this->addSql('DROP INDEX IDX_64C19C1A76ED395 ON category'); + $this->addSql('ALTER TABLE category DROP user_id'); + $this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D649343F048E'); + $this->addSql('DROP INDEX IDX_8D93D649343F048E ON user'); + $this->addSql('ALTER TABLE user ADD owner LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', ADD expenses LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\', ADD current_festival LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\', DROP current_festival_id'); + $this->addSql('ALTER TABLE group_of_products DROP FOREIGN KEY FK_2A99B370A76ED395'); + $this->addSql('DROP INDEX IDX_2A99B370A76ED395 ON group_of_products'); + $this->addSql('ALTER TABLE group_of_products DROP user_id'); + } +} diff --git a/src/Entity/Category.php b/src/Entity/Category.php index 088add56..1aa31a13 100644 --- a/src/Entity/Category.php +++ b/src/Entity/Category.php @@ -16,6 +16,9 @@ class Category #[ORM\Column(length: 255)] private ?string $name = null; + #[ORM\ManyToOne(inversedBy: 'categories')] + private ?User $user = null; + public function getId(): ?int { return $this->id; @@ -32,4 +35,16 @@ class Category return $this; } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } } diff --git a/src/Entity/Expense.php b/src/Entity/Expense.php index d7d716b7..560a89f2 100644 --- a/src/Entity/Expense.php +++ b/src/Entity/Expense.php @@ -19,6 +19,9 @@ class Expense #[ORM\Column] private ?float $price = null; + #[ORM\ManyToOne(inversedBy: 'expenses')] + private ?User $user = null; + public function getId(): ?int { return $this->id; @@ -47,4 +50,16 @@ class Expense return $this; } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } } diff --git a/src/Entity/Festival.php b/src/Entity/Festival.php index cb63730b..86e3fd41 100644 --- a/src/Entity/Festival.php +++ b/src/Entity/Festival.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\FestivalRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; @@ -23,6 +25,20 @@ class Festival #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $date_end = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: User::class, mappedBy: 'currentFestival')] + private Collection $users; + + #[ORM\ManyToOne(inversedBy: 'festivals')] + private ?User $user = null; + + public function __construct() + { + $this->users = new ArrayCollection(); + } + public function getId(): ?int { return $this->id; @@ -63,4 +79,46 @@ class Festival return $this; } + + /** + * @return Collection + */ + public function getUsers(): Collection + { + return $this->users; + } + + public function addUser(User $user): static + { + if (!$this->users->contains($user)) { + $this->users->add($user); + $user->setCurrentFestival($this); + } + + return $this; + } + + public function removeUser(User $user): static + { + if ($this->users->removeElement($user)) { + // set the owning side to null (unless already changed) + if ($user->getCurrentFestival() === $this) { + $user->setCurrentFestival(null); + } + } + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } } diff --git a/src/Entity/GroupOfProducts.php b/src/Entity/GroupOfProducts.php index 72605b8f..0ba278a7 100644 --- a/src/Entity/GroupOfProducts.php +++ b/src/Entity/GroupOfProducts.php @@ -31,6 +31,9 @@ class GroupOfProducts #[ORM\ManyToMany(targetEntity: Selling::class, inversedBy: 'groupOfProducts')] private Collection $sellings; + #[ORM\ManyToOne(inversedBy: 'groupOfProducts')] + private ?User $user = null; + public function __construct() { $this->products = new ArrayCollection(); @@ -106,4 +109,16 @@ class GroupOfProducts return $this; } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } } diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 9603ce16..3ce16226 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -30,9 +30,19 @@ class Product #[ORM\ManyToMany(targetEntity: GroupOfProducts::class, mappedBy: 'products')] private Collection $groupOfProducts; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Selling::class, mappedBy: 'products')] + private Collection $sellings; + + #[ORM\ManyToOne(inversedBy: 'products')] + private ?User $user = null; + public function __construct() { $this->groupOfProducts = new ArrayCollection(); + $this->sellings = new ArrayCollection(); } public function getId(): ?int @@ -102,4 +112,43 @@ class Product return $this; } + + /** + * @return Collection + */ + public function getSellings(): Collection + { + return $this->sellings; + } + + public function addSelling(Selling $selling): static + { + if (!$this->sellings->contains($selling)) { + $this->sellings->add($selling); + $selling->addProduct($this); + } + + return $this; + } + + public function removeSelling(Selling $selling): static + { + if ($this->sellings->removeElement($selling)) { + $selling->removeProduct($this); + } + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } } diff --git a/src/Entity/Selling.php b/src/Entity/Selling.php index 45ce81e5..46341f5e 100644 --- a/src/Entity/Selling.php +++ b/src/Entity/Selling.php @@ -19,9 +19,6 @@ class Selling #[ORM\Column(length: 255, nullable: true)] private ?string $note = null; - #[ORM\Column(type: Types::OBJECT)] - private ?object $products = null; - #[ORM\Column] private ?float $sum = null; @@ -34,9 +31,16 @@ class Selling #[ORM\ManyToMany(targetEntity: GroupOfProducts::class, mappedBy: 'sellings')] private Collection $groupOfProducts; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Product::class, inversedBy: 'sellings')] + private Collection $products; + public function __construct() { $this->groupOfProducts = new ArrayCollection(); + $this->products = new ArrayCollection(); } public function getId(): ?int @@ -118,4 +122,20 @@ class Selling return $this; } + + public function addProduct(Product $product): static + { + if (!$this->products->contains($product)) { + $this->products->add($product); + } + + return $this; + } + + public function removeProduct(Product $product): static + { + $this->products->removeElement($product); + + return $this; + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index bf0764e8..2bf95170 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -3,6 +3,8 @@ namespace App\Entity; use App\Repository\UserRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; @@ -34,17 +36,50 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column] private ?string $password = null; - #[ORM\Column(type: Types::OBJECT)] - private ?object $owner = null; - - #[ORM\Column(type: Types::OBJECT, nullable: true)] - private ?object $expenses = null; - #[ORM\Column] private bool $isVerified = false; - #[ORM\Column(type: Types::OBJECT, nullable: true)] - private ?object $currentFestival = null; + #[ORM\ManyToOne(inversedBy: 'users')] + private ?Festival $currentFestival = null; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Expense::class, mappedBy: 'user')] + private Collection $expenses; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'user')] + private Collection $products; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: GroupOfProducts::class, mappedBy: 'user')] + private Collection $groupOfProducts; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Festival::class, mappedBy: 'user')] + private Collection $festivals; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Category::class, mappedBy: 'user')] + private Collection $categories; + + public function __construct() + { + $this->expenses = new ArrayCollection(); + $this->products = new ArrayCollection(); + $this->groupOfProducts = new ArrayCollection(); + $this->festivals = new ArrayCollection(); + $this->categories = new ArrayCollection(); + } public function getId(): ?int { @@ -168,4 +203,146 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function addExpense(Expense $expense): static + { + if (!$this->expenses->contains($expense)) { + $this->expenses->add($expense); + $expense->setUser($this); + } + + return $this; + } + + public function removeExpense(Expense $expense): static + { + if ($this->expenses->removeElement($expense)) { + // set the owning side to null (unless already changed) + if ($expense->getUser() === $this) { + $expense->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getProducts(): Collection + { + return $this->products; + } + + public function addProduct(Product $product): static + { + if (!$this->products->contains($product)) { + $this->products->add($product); + $product->setUser($this); + } + + return $this; + } + + public function removeProduct(Product $product): static + { + if ($this->products->removeElement($product)) { + // set the owning side to null (unless already changed) + if ($product->getUser() === $this) { + $product->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getGroupOfProducts(): Collection + { + return $this->groupOfProducts; + } + + public function addGroupOfProduct(GroupOfProducts $groupOfProduct): static + { + if (!$this->groupOfProducts->contains($groupOfProduct)) { + $this->groupOfProducts->add($groupOfProduct); + $groupOfProduct->setUser($this); + } + + return $this; + } + + public function removeGroupOfProduct(GroupOfProducts $groupOfProduct): static + { + if ($this->groupOfProducts->removeElement($groupOfProduct)) { + // set the owning side to null (unless already changed) + if ($groupOfProduct->getUser() === $this) { + $groupOfProduct->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getFestivals(): Collection + { + return $this->festivals; + } + + public function addFestival(Festival $festival): static + { + if (!$this->festivals->contains($festival)) { + $this->festivals->add($festival); + $festival->setUser($this); + } + + return $this; + } + + public function removeFestival(Festival $festival): static + { + if ($this->festivals->removeElement($festival)) { + // set the owning side to null (unless already changed) + if ($festival->getUser() === $this) { + $festival->setUser(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getCategories(): Collection + { + return $this->categories; + } + + public function addCategory(Category $category): static + { + if (!$this->categories->contains($category)) { + $this->categories->add($category); + $category->setUser($this); + } + + return $this; + } + + public function removeCategory(Category $category): static + { + if ($this->categories->removeElement($category)) { + // set the owning side to null (unless already changed) + if ($category->getUser() === $this) { + $category->setUser(null); + } + } + + return $this; + } }