✨ feat(newsletter): Affiche le nombre de contacts dans la liste et crée la relation.
This commit is contained in:
36
migrations/Version20250801084410.php
Normal file
36
migrations/Version20250801084410.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Version20250801084410 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 contact_line (id SERIAL NOT NULL, list_id INT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, surname VARCHAR(255) DEFAULT NULL, email VARCHAR(255) NOT NULL, uuid UUID NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_F9EB36093DAE168B ON contact_line (list_id)');
|
||||
$this->addSql('COMMENT ON COLUMN contact_line.uuid IS \'(DC2Type:uuid)\'');
|
||||
$this->addSql('ALTER TABLE contact_line ADD CONSTRAINT FK_F9EB36093DAE168B FOREIGN KEY (list_id) REFERENCES contact (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE SCHEMA public');
|
||||
$this->addSql('ALTER TABLE contact_line DROP CONSTRAINT FK_F9EB36093DAE168B');
|
||||
$this->addSql('DROP TABLE contact_line');
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Entity\Newsletter;
|
||||
|
||||
use App\Repository\Newsletter\ContactRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
@@ -20,6 +22,17 @@ class Contact
|
||||
#[ORM\Column(type: 'uuid')]
|
||||
private ?Uuid $uuid = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, ContactLine>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: ContactLine::class, mappedBy: 'list')]
|
||||
private Collection $contactLines;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->contactLines = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -48,4 +61,34 @@ class Contact
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, ContactLine>
|
||||
*/
|
||||
public function getContactLines(): Collection
|
||||
{
|
||||
return $this->contactLines;
|
||||
}
|
||||
|
||||
public function addContactLine(ContactLine $contactLine): static
|
||||
{
|
||||
if (!$this->contactLines->contains($contactLine)) {
|
||||
$this->contactLines->add($contactLine);
|
||||
$contactLine->setList($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeContactLine(ContactLine $contactLine): static
|
||||
{
|
||||
if ($this->contactLines->removeElement($contactLine)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($contactLine->getList() === $this) {
|
||||
$contactLine->setList(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
96
src/Entity/Newsletter/ContactLine.php
Normal file
96
src/Entity/Newsletter/ContactLine.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Newsletter;
|
||||
|
||||
use App\Repository\Newsletter\ContactLineRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ContactLineRepository::class)]
|
||||
class ContactLine
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'contactLines')]
|
||||
private ?Contact $list = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $surname = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(type: 'uuid')]
|
||||
private ?Uuid $uuid = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getList(): ?Contact
|
||||
{
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
public function setList(?Contact $list): static
|
||||
{
|
||||
$this->list = $list;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $na<6E>me): static
|
||||
{
|
||||
$this->name = $na<6E>me;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSurname(): ?string
|
||||
{
|
||||
return $this->surname;
|
||||
}
|
||||
|
||||
public function setSurname(?string $surname): static
|
||||
{
|
||||
$this->surname = $surname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): static
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUuid(): ?Uuid
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
public function setUuid(Uuid $uuid): static
|
||||
{
|
||||
$this->uuid = $uuid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
43
src/Repository/Newsletter/ContactLineRepository.php
Normal file
43
src/Repository/Newsletter/ContactLineRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository\Newsletter;
|
||||
|
||||
use App\Entity\Newsletter\ContactLine;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ContactLine>
|
||||
*/
|
||||
class ContactLineRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ContactLine::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return ContactLine[] Returns an array of ContactLine objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('c.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?ContactLine
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<div class="flex flex-col">
|
||||
<h1 class="font-semibold">{{ list.name }}</h1>
|
||||
<p class="text-xs"><span class="num-2">0</span> Contact</p>
|
||||
<p class="text-xs"><span class="num-2">{{ list.contactLines.count }}</span> Contact</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user