Skip to content
Snippets Groups Projects
Commit 8fe6dabb authored by Camille Simiand's avatar Camille Simiand Committed by Sebastien
Browse files

Add Capsule entity and repository

parent 0dd90477
No related branches found
No related tags found
3 merge requests!43tuleap-83-access-my-capsules,!42Draft: access-my-capsules-conflicts-fixed,!40Draft: Tuleap 83 access my capsules
<?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 Version20211215132322 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 capsule (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, aut_crea VARCHAR(255) NOT NULL, dt_crea DATETIME NOT NULL, aut_maj VARCHAR(255) NOT NULL, dt_maj DATETIME NOT NULL, link VARCHAR(255) NOT NULL, edition_link VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE editeur_capsule (capsule_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_A18592E2714704E9 (capsule_id), INDEX IDX_A18592E2A76ED395 (user_id), PRIMARY KEY(capsule_id, user_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE editeur_capsule ADD CONSTRAINT FK_A18592E2714704E9 FOREIGN KEY (capsule_id) REFERENCES capsule (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE editeur_capsule ADD CONSTRAINT FK_A18592E2A76ED395 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 editeur_capsule DROP FOREIGN KEY FK_A18592E2714704E9');
$this->addSql('DROP TABLE capsule');
$this->addSql('DROP TABLE editeur_capsule');
}
}
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
...@@ -82,6 +84,16 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -82,6 +84,16 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
*/ */
private string $salt; private string $salt;
/**
* @ORM\ManyToMany(targetEntity=Capsule::class, mappedBy="editors")
*/
private $capsules;
public function __construct()
{
$this->capsules = new ArrayCollection();
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
...@@ -212,4 +224,31 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -212,4 +224,31 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
{ {
$this->salt = $salt; $this->salt = $salt;
} }
/**
* @return Collection|Capsule[]
*/
public function getCapsules(): Collection
{
return $this->capsules;
}
public function addCapsule(Capsule $capsule): self
{
if (!$this->capsules->contains($capsule)) {
$this->capsules[] = $capsule;
$capsule->addEditor($this);
}
return $this;
}
public function removeCapsule(Capsule $capsule): self
{
if ($this->capsules->removeElement($capsule)) {
$capsule->removeEditor($this);
}
return $this;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment