src/Entity/Config.php line 50
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\Put;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Interface\TranslatableInterface,
App\Enum\AlertType,
App\Enum\Language,
App\Repository\ConfigRepository;
use App\StateProvider\ConfigProvider;
#[ApiResource(
description: 'Config',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation'
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['ord' => 'asc'],
operations: [
new Get(
uriTemplate: '/config',
provider: ConfigProvider::class
),
new Put(
uriTemplate: '/config',
provider: ConfigProvider::class
),
],
extraProperties: ['standard_put' => false],
)]
#[ORM\Entity(repositoryClass: ConfigRepository::class)]
class Config implements TranslatableInterface
{
use IdTrait,
UuidTrait,
TimestampableTrait,
TranslatableTrait;
#[ApiProperty(description: 'Is mourning version active')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $isMourningVersionActive = false;
#[ApiProperty(description: 'HOME: journals per page')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::INTEGER, options: ['default' => 16])]
private int $homeJournalsPerPage = 16;
#[ApiProperty(description: 'HOME: is journals alphabetical asc order')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $homeIsJournalsAlphabeticalAscOrder = true;
#[ApiProperty(description: 'HOME: is unpublished journals excluded')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $homeIsUnpublishedJournalsExcluded = false;
#[ApiProperty(description: 'HOME: is closed journals excluded')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $homeIsClosedJournalsExcluded = false;
#[ApiProperty(description: 'HOME: is unscientific journals excluded')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $homeIsUnscientificJournalsExcluded = false;
#[ApiProperty(description: 'HOME: is industry journals excluded')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $homeIsIndustryJournalsExcluded = false;
#[ApiProperty(description: 'Alert A: is visible')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertAIsVisible = false;
#[ApiProperty(description: 'Alert A: type', writableLink: false)]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(
type: Types::STRING,
enumType: AlertType::class,
length: 255,
options: ['default' => AlertType::ALERT]
)]
private AlertType $alertAType = AlertType::ALERT;
#[ApiProperty(description: 'Alert A: is take off active')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Expression(
expression: '! value || this.getAlertATakeOffDateTime()',
message: 'Take off date time must be set before activating.'
)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertAIsTakeOffActive = false;
#[ApiProperty(description: 'Alert A: take off date and time')]
#[Groups(['read:' . self::class, 'write'])]
// #[Assert\GreaterThan('tomorrow')]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $alertATakeOffDateTime = null;
#[ApiProperty(description: 'Alert B: is visible')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertBIsVisible = false;
#[ApiProperty(description: 'Alert B: type', writableLink: false)]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(
type: Types::STRING,
enumType: AlertType::class,
length: 255,
options: ['default' => AlertType::ALERT]
)]
private AlertType $alertBType = AlertType::ALERT;
#[ApiProperty(description: 'Alert B: is take off active')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Expression(
expression: '! value || this.getAlertBTakeOffDateTime()',
message: 'Take off date time must be set before activating.'
)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertBIsTakeOffActive = false;
#[ApiProperty(description: 'Alert B: take off date and time')]
#[Groups(['read:' . self::class, 'write'])]
// #[Assert\GreaterThan('tomorrow')]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $alertBTakeOffDateTime = null;
#[ApiProperty(description: 'Alert C: is visible')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertCIsVisible = false;
#[ApiProperty(description: 'Alert C: type', writableLink: false)]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(
type: Types::STRING,
enumType: AlertType::class,
length: 255,
options: ['default' => AlertType::ALERT]
)]
private AlertType $alertCType = AlertType::ALERT;
#[ApiProperty(description: 'Alert C: is take off active')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Expression(
expression: '! value || this.getAlertCTakeOffDateTime()',
message: 'Take off date time must be set before activating.'
)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $alertCIsTakeOffActive = false;
#[ApiProperty(description: 'Alert C: take off date and time')]
#[Groups(['read:' . self::class, 'write'])]
// #[Assert\GreaterThan('tomorrow')]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $alertCTakeOffDateTime = null;
#[ApiProperty(description: 'CONTACT: map')]
#[Groups(['read:' . self::class, 'write'])]
#[Assert\Expression(
expression: 'this.isContactMapFormatValid()',
message: 'Wrong format. Required: { lat: <float>, lng: <float>, zoom: <int> }'
)]
#[Assert\Expression(
expression: '(value["lat"] ?? null) >= -90 && (value["lat"] ?? null) <= 90',
message: 'Latitude must be from range -90 to 90.'
)]
#[Assert\Expression(
expression: '(value["lng"] ?? null) >= -90 && (value["lng"] ?? null) <= 90',
message: 'Longitude must be from range -90 to 90.'
)]
#[Assert\Expression(
expression: '(value["zoom"] ?? null) >= 0 && (value["zoom"] ?? null) <= 18',
message: 'Zoom must be from range 0 to 18.'
)]
#[ORM\Column(type: Types::JSON)]
private array $contactMap = [];
#[ApiProperty(description: 'Link to facebook')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $linkFacebook = null;
#[ApiProperty(description: 'Link to instagram')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $linkInstagram = null;
#[ApiProperty(description: 'Additional head code')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $additionalHeadCode = null;
#[ApiProperty(description: 'Additional body code')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $additionalBodyCode = null;
#[ApiProperty(description: 'Error report email')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $errorReportEmail = null;
public function __construct()
{
$this->setUuid();
$this->translations = new ArrayCollection();
foreach (Language::DEFAULT_SITE as $lang) {
new ConfigTranslation($this, $lang);
}
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getIsMourningVersionActive(): bool
{
return $this->isMourningVersionActive;
}
public function setIsMourningVersionActive(bool $isMourningVersionActive): self
{
$this->isMourningVersionActive = $isMourningVersionActive;
return $this;
}
public function getHomeJournalsPerPage(): int
{
return $this->homeJournalsPerPage;
}
public function setHomeJournalsPerPage(int $homeJournalsPerPage): self
{
$this->homeJournalsPerPage = $homeJournalsPerPage;
return $this;
}
public function getHomeIsJournalsAlphabeticalAscOrder(): bool
{
return $this->homeIsJournalsAlphabeticalAscOrder;
}
public function setHomeIsJournalsAlphabeticalAscOrder(bool $homeIsJournalsAlphabeticalAscOrder): self
{
$this->homeIsJournalsAlphabeticalAscOrder = $homeIsJournalsAlphabeticalAscOrder;
return $this;
}
public function getHomeIsUnpublishedJournalsExcluded(): bool
{
return $this->homeIsUnpublishedJournalsExcluded;
}
public function setHomeIsUnpublishedJournalsExcluded(bool $homeIsUnpublishedJournalsExcluded): self
{
$this->homeIsUnpublishedJournalsExcluded = $homeIsUnpublishedJournalsExcluded;
return $this;
}
public function getHomeIsClosedJournalsExcluded(): bool
{
return $this->homeIsClosedJournalsExcluded;
}
public function setHomeIsClosedJournalsExcluded(bool $homeIsClosedJournalsExcluded): self
{
$this->homeIsClosedJournalsExcluded = $homeIsClosedJournalsExcluded;
return $this;
}
public function getHomeIsUnscientificJournalsExcluded(): bool
{
return $this->homeIsUnscientificJournalsExcluded;
}
public function setHomeIsUnscientificJournalsExcluded(bool $homeIsUnscientificJournalsExcluded): self
{
$this->homeIsUnscientificJournalsExcluded = $homeIsUnscientificJournalsExcluded;
return $this;
}
public function getHomeIsIndustryJournalsExcluded(): bool
{
return $this->homeIsIndustryJournalsExcluded;
}
public function setHomeIsIndustryJournalsExcluded(bool $homeIsIndustryJournalsExcluded): self
{
$this->homeIsIndustryJournalsExcluded = $homeIsIndustryJournalsExcluded;
return $this;
}
public function getAlertAIsVisible(): bool
{
return $this->alertAIsVisible;
}
public function setAlertAIsVisible(bool $alertAIsVisible): self
{
$this->alertAIsVisible = $alertAIsVisible;
return $this;
}
public function getAlertAType(): AlertType
{
return $this->alertAType;
}
public function setAlertAType(AlertType $alertAType): self
{
$this->alertAType = $alertAType;
return $this;
}
public function getAlertAIsTakeOffActive(): bool
{
return $this->alertAIsTakeOffActive;
}
public function setAlertAIsTakeOffActive(bool $alertAIsTakeOffActive): self
{
$this->alertAIsTakeOffActive = $alertAIsTakeOffActive;
return $this;
}
public function getAlertATakeOffDateTime(): ?\DateTimeInterface
{
return $this->alertATakeOffDateTime;
}
public function setAlertATakeOffDateTime(?\DateTimeInterface $alertATakeOffDateTime): self
{
$this->alertATakeOffDateTime = $alertATakeOffDateTime;
return $this;
}
public function getAlertBIsVisible(): bool
{
return $this->alertBIsVisible;
}
public function setAlertBIsVisible(bool $alertBIsVisible): self
{
$this->alertBIsVisible = $alertBIsVisible;
return $this;
}
public function getAlertBType(): AlertType
{
return $this->alertBType;
}
public function setAlertBType(AlertType $alertBType): self
{
$this->alertBType = $alertBType;
return $this;
}
public function getAlertBIsTakeOffActive(): bool
{
return $this->alertBIsTakeOffActive;
}
public function setAlertBIsTakeOffActive(bool $alertBIsTakeOffActive): self
{
$this->alertBIsTakeOffActive = $alertBIsTakeOffActive;
return $this;
}
public function getAlertBTakeOffDateTime(): ?\DateTimeInterface
{
return $this->alertBTakeOffDateTime;
}
public function setAlertBTakeOffDateTime(?\DateTimeInterface $alertBTakeOffDateTime): self
{
$this->alertBTakeOffDateTime = $alertBTakeOffDateTime;
return $this;
}
public function getAlertCIsVisible(): bool
{
return $this->alertCIsVisible;
}
public function setAlertCIsVisible(bool $alertCIsVisible): self
{
$this->alertCIsVisible = $alertCIsVisible;
return $this;
}
public function getAlertCType(): AlertType
{
return $this->alertCType;
}
public function setAlertCType(AlertType $alertCType): self
{
$this->alertCType = $alertCType;
return $this;
}
public function getAlertCIsTakeOffActive(): bool
{
return $this->alertCIsTakeOffActive;
}
public function setAlertCIsTakeOffActive(bool $alertCIsTakeOffActive): self
{
$this->alertCIsTakeOffActive = $alertCIsTakeOffActive;
return $this;
}
public function getAlertCTakeOffDateTime(): ?\DateTimeInterface
{
return $this->alertCTakeOffDateTime;
}
public function setAlertCTakeOffDateTime(?\DateTimeInterface $alertCTakeOffDateTime): self
{
$this->alertCTakeOffDateTime = $alertCTakeOffDateTime;
return $this;
}
private function clearAlert(string $type): self
{
$isTakeOffActive = 'alert' . strtoupper($type) . 'IsTakeOffActive';
$takeOffDateTime = 'alert' . strtoupper($type) . 'TakeOffDateTime';
if (
! $this->$isTakeOffActive
|| (new \DateTimeImmutable()) < $this->$takeOffDateTime
) {
return $this;
}
$isVisible = 'alert' . strtoupper($type) . 'IsVisible';
$this->$isVisible = false;
$this->$isTakeOffActive = false;
$this->$takeOffDateTime = null;
return $this;
}
public function clearAlerts(): self
{
$this
->clearAlert('a')
->clearAlert('b')
->clearAlert('c');
return $this;
}
public function getContactMap(): array
{
return count($this->contactMap)
? $this->contactMap
: [
'lat' => 50.06195,
'lng' => 19.93930,
'zoom' => 14
];
}
public function setContactMap(array $contactMap): self
{
$this->contactMap = $contactMap;
return $this;
}
public function isContactMapFormatValid(): bool
{
$lat = $this->contactMap['lat'] ?? null;
$lng = $this->contactMap['lng'] ?? null;
$zoom = $this->contactMap['zoom'] ?? null;
if (
! is_float($lat)
|| ! is_float($lng)
|| ! is_int($zoom)
) {
return false;
}
return true;
}
public function getLinkFacebook(): ?string
{
return $this->linkFacebook;
}
public function setLinkFacebook(?string $linkFacebook): self
{
$this->linkFacebook = $linkFacebook;
return $this;
}
public function getLinkInstagram(): ?string
{
return $this->linkInstagram;
}
public function setLinkInstagram(?string $linkInstagram): self
{
$this->linkInstagram = $linkInstagram;
return $this;
}
public function getAdditionalHeadCode(): ?string
{
return $this->additionalHeadCode;
}
public function setAdditionalHeadCode(?string $additionalHeadCode): self
{
$this->additionalHeadCode = $additionalHeadCode;
return $this;
}
public function getAdditionalBodyCode(): ?string
{
return $this->additionalBodyCode;
}
public function setAdditionalBodyCode(?string $additionalBodyCode): self
{
$this->additionalBodyCode = $additionalBodyCode;
return $this;
}
public function getErrorReportEmail(): ?string
{
return $this->errorReportEmail;
}
public function setErrorReportEmail(?string $errorReportEmail): self
{
$this->errorReportEmail = $errorReportEmail;
return $this;
}
}