Skip to content
Snippets Groups Projects
Commit d19378f7 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Trait et Interface HasMails

parent 2bf2c282
No related branches found
No related tags found
No related merge requests found
Pipeline #30234 passed
<?php
namespace UnicaenMail\Entity;
use UnicaenMail\Entity\Db\Mail;
use UnicaenRenderer\Entity\Db\Template;
interface HasMailsInterface
{
public function getMails(): array;
public function hasMail(Mail $mail): bool;
public function addMail(Mail $mail): void;
public function removeMail(Mail $mail): void;
public function hasMailWithTemplateCode(string|Template $template): bool;
}
\ No newline at end of file
<?php
namespace UnicaenMail\Entity;
use Doctrine\Common\Collections\Collection;
use UnicaenMail\Entity\Db\Mail;
use UnicaenRenderer\Entity\Db\Template;
trait HasMailsTrait
{
protected Collection $mails;
/** @return Mail[] */
public function getMails(): array
{
return $this->mails->toArray();
}
public function hasMail(Mail $mail): bool
{
return $this->mails->contains($mail);
}
public function addMail(Mail $mail): void
{
if (!$this->hasMail($mail)) { $this->mails->add($mail); }
}
public function removeMail(Mail $mail): void
{
$this->removeMail($mail);
}
public function hasMailWithTemplateCode(string|Template $template): bool
{
$code = ($template instanceof Template)?$template->generateTag():$template;
/** @var Mail $mail */
foreach ($this->mails as $mail) {
$motsClefs = explode("||",$mail->getMotsClefs());
if (in_array($code, $motsClefs)) return true;
}
return false;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment