Skip to content

Commit

Permalink
EV-244: Added user and org. entities
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Jun 29, 2023
1 parent 2d4ec28 commit 5a14746
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 0 deletions.
39 changes: 39 additions & 0 deletions migrations/Version20230629133659.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 Version20230629133659 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 organization (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE organization_user (organization_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_B49AE8D432C8A3DE (organization_id), INDEX IDX_B49AE8D4A76ED395 (user_id), PRIMARY KEY(organization_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, enabled VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE organization_user ADD CONSTRAINT FK_B49AE8D432C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE organization_user ADD CONSTRAINT FK_B49AE8D4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE organization_user DROP FOREIGN KEY FK_B49AE8D432C8A3DE');
$this->addSql('ALTER TABLE organization_user DROP FOREIGN KEY FK_B49AE8D4A76ED395');
$this->addSql('DROP TABLE organization');
$this->addSql('DROP TABLE organization_user');
$this->addSql('DROP TABLE user');
}
}
35 changes: 35 additions & 0 deletions migrations/Version20230629133955.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Version20230629133955 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('ALTER TABLE event ADD organization_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA732C8A3DE FOREIGN KEY (organization_id) REFERENCES organization (id)');
$this->addSql('CREATE INDEX IDX_3BAE0AA732C8A3DE ON event (organization_id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE event DROP FOREIGN KEY FK_3BAE0AA732C8A3DE');
$this->addSql('DROP INDEX IDX_3BAE0AA732C8A3DE ON event');
$this->addSql('ALTER TABLE event DROP organization_id');
}
}
31 changes: 31 additions & 0 deletions migrations/Version20230629134238.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 Version20230629134238 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('ALTER TABLE user ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL, ADD deleted_at DATETIME DEFAULT NULL, ADD created_by VARCHAR(255) DEFAULT NULL, ADD updated_by VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user DROP created_at, DROP updated_at, DROP deleted_at, DROP created_by, DROP updated_by');
}
}
15 changes: 15 additions & 0 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Event
#[ORM\Column]
private bool $public = true;

#[ORM\ManyToOne(inversedBy: 'events')]
private ?Organization $organization = null;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -133,4 +136,16 @@ public function setPublic(bool $public): static

return $this;
}

public function getOrganization(): ?Organization
{
return $this->organization;
}

public function setOrganization(?Organization $organization): static
{
$this->organization = $organization;

return $this;
}
}
140 changes: 140 additions & 0 deletions src/Entity/Organization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Repository\OrganizationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;

#[ORM\Entity(repositoryClass: OrganizationRepository::class)]
#[ApiResource]
class Organization
{
use TimestampableEntity;
use SoftDeleteableEntity;

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $name = null;

#[ORM\Column(length: 255)]
private ?string $mail = null;

#[ORM\Column(length: 255)]
private ?string $url = null;

#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'organizations')]
private Collection $Users;

#[ORM\OneToMany(mappedBy: 'organization', targetEntity: Event::class)]
private Collection $events;

public function __construct()
{
$this->Users = new ArrayCollection();
$this->events = new ArrayCollection();
}

public function getId(): ?int
{
return $this->id;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): static
{
$this->name = $name;

return $this;
}

public function getMail(): ?string
{
return $this->mail;
}

public function setMail(string $mail): static
{
$this->mail = $mail;

return $this;
}

public function getUrl(): ?string
{
return $this->url;
}

public function setUrl(string $url): static
{
$this->url = $url;

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

return $this;
}

public function removeUser(User $user): static
{
$this->Users->removeElement($user);

return $this;
}

/**
* @return Collection<int, Event>
*/
public function getEvents(): Collection
{
return $this->events;
}

public function addEvent(Event $event): static
{
if (!$this->events->contains($event)) {
$this->events->add($event);
$event->setOrganization($this);
}

return $this;
}

public function removeEvent(Event $event): static
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getOrganization() === $this) {
$event->setOrganization(null);
}
}

return $this;
}
}
Loading

0 comments on commit 5a14746

Please sign in to comment.