mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
notification / add email: fix entity Notification
This commit is contained in:
parent
ef9fd80ad5
commit
a8db07a383
@ -110,7 +110,14 @@ class Notification implements TrackUpdateInterface
|
|||||||
* @var array|string[]
|
* @var array|string[]
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
*/
|
*/
|
||||||
public array $adressesEmails = [];
|
private array $addressesEmails = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a list of emails adresses which were added to the notification
|
||||||
|
*
|
||||||
|
* @var array|string[]
|
||||||
|
*/
|
||||||
|
private array $addressesEmailsAdded = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="text", nullable=false)
|
* @ORM\Column(type="text", nullable=false)
|
||||||
@ -126,6 +133,46 @@ class Notification implements TrackUpdateInterface
|
|||||||
$this->accessKey = bin2hex(openssl_random_pseudo_bytes(24));
|
$this->accessKey = bin2hex(openssl_random_pseudo_bytes(24));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|string[]
|
||||||
|
*/
|
||||||
|
public function getAddressesEmails(): array
|
||||||
|
{
|
||||||
|
return $this->addressesEmails;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|string[]
|
||||||
|
*/
|
||||||
|
public function getAddressesEmailsAdded(): array
|
||||||
|
{
|
||||||
|
return $this->addressesEmailsAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccessKey(): string
|
||||||
|
{
|
||||||
|
return $this->accessKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAddressesEmail(string $email)
|
||||||
|
{
|
||||||
|
if (!in_array($email, $this->addressesEmails)) {
|
||||||
|
$this->addressesEmails[] = $email;
|
||||||
|
$this->addressesEmailsAdded[] = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeAddressesEmail(string $email)
|
||||||
|
{
|
||||||
|
if (in_array($email, $this->addressesEmails)) {
|
||||||
|
$this->addressesEmails = array_filter($this->addressesEmails, fn ($e) => $e !== $email);
|
||||||
|
$this->addressesEmailsAdded = array_filter($this->addressesEmailsAdded, fn ($e) => $e !== $email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function addAddressee(User $addressee): self
|
public function addAddressee(User $addressee): self
|
||||||
{
|
{
|
||||||
if (!$this->addressees->contains($addressee)) {
|
if (!$this->addressees->contains($addressee)) {
|
||||||
|
@ -122,4 +122,22 @@ final class NotificationTest extends KernelTestCase
|
|||||||
$this->assertContains($addresseeId, $unreadIds);
|
$this->assertContains($addresseeId, $unreadIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddressesEmail(): void
|
||||||
|
{
|
||||||
|
$notification = new Notification();
|
||||||
|
|
||||||
|
$notification->addAddressesEmail('test');
|
||||||
|
$notification->addAddressesEmail('other');
|
||||||
|
|
||||||
|
$this->assertContains('test', $notification->getAddressesEmails());
|
||||||
|
$this->assertContains('other', $notification->getAddressesEmails());
|
||||||
|
$this->assertContains('test', $notification->getAddressesEmailsAdded());
|
||||||
|
$this->assertContains('other', $notification->getAddressesEmailsAdded());
|
||||||
|
|
||||||
|
$notification->removeAddressesEmail('other');
|
||||||
|
|
||||||
|
$this->assertNotContains('other', $notification->getAddressesEmails());
|
||||||
|
$this->assertNotContains('other', $notification->getAddressesEmailsAdded());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ final class Version20220413154743 extends AbstractMigration
|
|||||||
|
|
||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE chill_main_notification ADD adressesEmails JSON NOT NULL DEFAULT \'[]\';');
|
$this->addSql('ALTER TABLE chill_main_notification ADD addressesEmails JSON NOT NULL DEFAULT \'[]\';');
|
||||||
$this->addSql('ALTER TABLE chill_main_notification ADD accessKey TEXT DEFAULT NULL');
|
$this->addSql('ALTER TABLE chill_main_notification ADD accessKey TEXT DEFAULT NULL');
|
||||||
$this->addSql('WITH randoms AS (select
|
$this->addSql('WITH randoms AS (select
|
||||||
n.id,
|
n.id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user