Change property on notification entity to type of NotificationEnum

This commit is contained in:
Julie Lenaerts 2025-06-18 14:03:51 +02:00
parent 33540f58d7
commit bef5dcce14
3 changed files with 44 additions and 19 deletions

View File

@ -14,6 +14,7 @@ namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
@ -24,7 +25,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Index(name: 'chill_main_notification_related_entity_idx', columns: ['relatedentityclass', 'relatedentityid'])] #[ORM\Index(name: 'chill_main_notification_related_entity_idx', columns: ['relatedentityclass', 'relatedentityid'])]
class Notification implements TrackUpdateInterface class Notification implements TrackUpdateInterface
{ {
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false)] #[ORM\Column(type: Types::TEXT, nullable: false)]
private string $accessKey; private string $accessKey;
private array $addedAddresses = []; private array $addedAddresses = [];
@ -41,7 +42,7 @@ class Notification implements TrackUpdateInterface
* *
* @var array|string[] * @var array|string[]
*/ */
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, options: ['default' => '[]', 'jsonb' => true])] #[ORM\Column(type: Types::JSON, options: ['default' => '[]', 'jsonb' => true])]
private array $addressesEmails = []; private array $addressesEmails = [];
/** /**
@ -60,21 +61,21 @@ class Notification implements TrackUpdateInterface
#[ORM\OrderBy(['createdAt' => \Doctrine\Common\Collections\Criteria::ASC])] #[ORM\OrderBy(['createdAt' => \Doctrine\Common\Collections\Criteria::ASC])]
private Collection $comments; private Collection $comments;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $date; private \DateTimeImmutable $date;
#[ORM\Id] #[ORM\Id]
#[ORM\GeneratedValue] #[ORM\GeneratedValue]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] #[ORM\Column(type: Types::INTEGER)]
private ?int $id = null; private ?int $id = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT)] #[ORM\Column(type: Types::TEXT)]
private string $message = ''; private string $message = '';
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] #[ORM\Column(type: Types::STRING, length: 255)]
private string $relatedEntityClass = ''; private string $relatedEntityClass = '';
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] #[ORM\Column(type: Types::INTEGER)]
private int $relatedEntityId; private int $relatedEntityId;
private array $removedAddresses = []; private array $removedAddresses = [];
@ -84,7 +85,7 @@ class Notification implements TrackUpdateInterface
private ?User $sender = null; private ?User $sender = null;
#[Assert\NotBlank(message: 'notification.Title must be defined')] #[Assert\NotBlank(message: 'notification.Title must be defined')]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, options: ['default' => ''])] #[ORM\Column(type: Types::TEXT, options: ['default' => ''])]
private string $title = ''; private string $title = '';
/** /**
@ -94,14 +95,14 @@ class Notification implements TrackUpdateInterface
#[ORM\JoinTable(name: 'chill_main_notification_addresses_unread')] #[ORM\JoinTable(name: 'chill_main_notification_addresses_unread')]
private Collection $unreadBy; private Collection $unreadBy;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $updatedAt = null; private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)] #[ORM\ManyToOne(targetEntity: User::class)]
private ?User $updatedBy = null; private ?User $updatedBy = null;
#[ORM\Column(name: 'flags', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])] #[ORM\Column(name: 'type', type: Types::STRING, nullable: true, enumType: NotificationEnum::class)]
private $flags = []; private NotificationEnum $type;
public function __construct() public function __construct()
{ {
@ -393,15 +394,15 @@ class Notification implements TrackUpdateInterface
return $this; return $this;
} }
public function setFlags(array $flags = []): self public function setType(NotificationEnum $type): self
{ {
$this->flags = $flags; $this->type = $type;
return $this; return $this;
} }
public function getFlags(): array public function getType(): NotificationEnum
{ {
return $this->flags; return $this->type;
} }
} }

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Entity;
enum NotificationEnum: string
{
case REFERRER_ACC_COURSE = 'referrer-acc-course-notif';
case PERSON_MOVE = 'person-move-notif';
case ACC_COURSE_USER = 'acc-course-user-notif';
case PERSON_USER = 'person-user-notif';
case WORKFLOW_TRANS = 'workflow-trans-notif';
case ACC_COURSE_WORK = 'acc-course-work-notif';
case ACC_COURSE_WORK_EVAL = 'acc-course-work-eval-notif';
case ACTIVITY_USER = 'activity-user-notif';
}

View File

@ -7,24 +7,24 @@ namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
final class Version20250610102020 extends AbstractMigration final class Version20250618115938 extends AbstractMigration
{ {
public function getDescription(): string public function getDescription(): string
{ {
return 'Add flags property to '; return 'Add type property to notifications';
} }
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
$this->addSql(<<<'SQL' $this->addSql(<<<'SQL'
ALTER TABLE chill_main_notification ADD flags JSONB DEFAULT '[]' NOT NULL ALTER TABLE chill_main_notification ADD type VARCHAR(255)
SQL); SQL);
} }
public function down(Schema $schema): void public function down(Schema $schema): void
{ {
$this->addSql(<<<'SQL' $this->addSql(<<<'SQL'
ALTER TABLE chill_main_notification DROP flags ALTER TABLE chill_main_notification DROP type
SQL); SQL);
} }
} }