up schema with relations between objects

This commit is contained in:
Tykayn 2025-02-14 11:08:34 +01:00 committed by tykayn
parent 1c700917b3
commit 17e7fce7f8
8 changed files with 433 additions and 11 deletions

View File

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250214100702 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<int, User>
*/
#[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<int, User>
*/
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;
}
}

View File

@ -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;
}
}

View File

@ -30,9 +30,19 @@ class Product
#[ORM\ManyToMany(targetEntity: GroupOfProducts::class, mappedBy: 'products')]
private Collection $groupOfProducts;
/**
* @var Collection<int, Selling>
*/
#[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<int, Selling>
*/
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;
}
}

View File

@ -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<int, Product>
*/
#[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;
}
}

View File

@ -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<int, Expense>
*/
#[ORM\OneToMany(targetEntity: Expense::class, mappedBy: 'user')]
private Collection $expenses;
/**
* @var Collection<int, Product>
*/
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'user')]
private Collection $products;
/**
* @var Collection<int, GroupOfProducts>
*/
#[ORM\OneToMany(targetEntity: GroupOfProducts::class, mappedBy: 'user')]
private Collection $groupOfProducts;
/**
* @var Collection<int, Festival>
*/
#[ORM\OneToMany(targetEntity: Festival::class, mappedBy: 'user')]
private Collection $festivals;
/**
* @var Collection<int, Category>
*/
#[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<int, Product>
*/
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<int, GroupOfProducts>
*/
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<int, Festival>
*/
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<int, Category>
*/
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;
}
}