src/Entity/Config.php line 50

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Serializer\Annotation\Groups,
  7.     Symfony\Component\Validator\Constraints as Assert;
  8. use ApiPlatform\Metadata\ApiResource,
  9.     ApiPlatform\Metadata\ApiProperty,
  10.     ApiPlatform\Metadata\Get,
  11.     ApiPlatform\Metadata\Put;
  12. use App\Entity\Trait\IdTrait,
  13.     App\Entity\Trait\UuidTrait,
  14.     App\Entity\Trait\TimestampableTrait,
  15.     App\Entity\Trait\TranslatableTrait,
  16.     App\Entity\Interface\TranslatableInterface,
  17.     App\Enum\AlertType,
  18.     App\Enum\Language,
  19.     App\Repository\ConfigRepository;
  20. use App\StateProvider\ConfigProvider;
  21. #[ApiResource(
  22.     description'Config',
  23.     normalizationContext: ['groups' => [
  24.         'read',
  25.         'read:' self::class,
  26.         'read:' self::class . 'Translation'
  27.     ]],
  28.     denormalizationContext: ['groups' => ['write']],
  29.     security'is_granted("' self::class . '")',
  30.     order: ['ord' => 'asc'],
  31.     operations: [
  32.         new Get(
  33.             uriTemplate'/config',
  34.             providerConfigProvider::class
  35.         ),
  36.         new Put(
  37.             uriTemplate'/config',
  38.             providerConfigProvider::class
  39.         ),
  40.     ],
  41.     extraProperties: ['standard_put' => false],
  42. )]
  43. #[ORM\Entity(repositoryClassConfigRepository::class)]
  44. class Config implements TranslatableInterface
  45. {
  46.     use IdTrait,
  47.         UuidTrait,
  48.         TimestampableTrait,
  49.         TranslatableTrait;
  50.     #[ApiProperty(description'Is mourning version active')]
  51.     #[Groups(['read:' self::class, 'write'])]
  52.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  53.     private bool $isMourningVersionActive false;
  54.     #[ApiProperty(description'HOME: journals per page')]
  55.     #[Groups(['read:' self::class, 'write'])]
  56.     #[ORM\Column(typeTypes::INTEGERoptions: ['default' => 16])]
  57.     private int $homeJournalsPerPage 16;
  58.     #[ApiProperty(description'HOME: is journals alphabetical asc order')]
  59.     #[Groups(['read:' self::class, 'write'])]
  60.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  61.     private bool $homeIsJournalsAlphabeticalAscOrder true;
  62.     #[ApiProperty(description'HOME: is unpublished journals excluded')]
  63.     #[Groups(['read:' self::class, 'write'])]
  64.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  65.     private bool $homeIsUnpublishedJournalsExcluded false;
  66.     #[ApiProperty(description'HOME: is closed journals excluded')]
  67.     #[Groups(['read:' self::class, 'write'])]
  68.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  69.     private bool $homeIsClosedJournalsExcluded false;
  70.     #[ApiProperty(description'HOME: is unscientific journals excluded')]
  71.     #[Groups(['read:' self::class, 'write'])]
  72.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  73.     private bool $homeIsUnscientificJournalsExcluded false;
  74.     #[ApiProperty(description'HOME: is industry journals excluded')]
  75.     #[Groups(['read:' self::class, 'write'])]
  76.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  77.     private bool $homeIsIndustryJournalsExcluded false;
  78.     #[ApiProperty(description'Alert A: is visible')]
  79.     #[Groups(['read:' self::class, 'write'])]
  80.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  81.     private bool $alertAIsVisible false;
  82.     #[ApiProperty(description'Alert A: type'writableLinkfalse)]
  83.     #[Groups(['read:' self::class, 'write'])]
  84.     #[ORM\Column(
  85.         typeTypes::STRING,
  86.         enumTypeAlertType::class,
  87.         length255,
  88.         options: ['default' => AlertType::ALERT]
  89.     )]
  90.     private AlertType $alertAType AlertType::ALERT;
  91.     #[ApiProperty(description'Alert A: is take off active')]
  92.     #[Groups(['read:' self::class, 'write'])]
  93.     #[Assert\Expression(
  94.         expression'! value || this.getAlertATakeOffDateTime()',
  95.         message'Take off date time must be set before activating.'
  96.     )]
  97.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  98.     private bool $alertAIsTakeOffActive false;
  99.     #[ApiProperty(description'Alert A: take off date and time')]
  100.     #[Groups(['read:' self::class, 'write'])]
  101.     // #[Assert\GreaterThan('tomorrow')]
  102.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  103.     private ?\DateTimeInterface $alertATakeOffDateTime null;
  104.     #[ApiProperty(description'Alert B: is visible')]
  105.     #[Groups(['read:' self::class, 'write'])]
  106.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  107.     private bool $alertBIsVisible false;
  108.     #[ApiProperty(description'Alert B: type'writableLinkfalse)]
  109.     #[Groups(['read:' self::class, 'write'])]
  110.     #[ORM\Column(
  111.         typeTypes::STRING,
  112.         enumTypeAlertType::class,
  113.         length255,
  114.         options: ['default' => AlertType::ALERT]
  115.     )]
  116.     private AlertType $alertBType AlertType::ALERT;
  117.     #[ApiProperty(description'Alert B: is take off active')]
  118.     #[Groups(['read:' self::class, 'write'])]
  119.     #[Assert\Expression(
  120.         expression'! value || this.getAlertBTakeOffDateTime()',
  121.         message'Take off date time must be set before activating.'
  122.     )]
  123.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  124.     private bool $alertBIsTakeOffActive false;
  125.     #[ApiProperty(description'Alert B: take off date and time')]
  126.     #[Groups(['read:' self::class, 'write'])]
  127.     // #[Assert\GreaterThan('tomorrow')]
  128.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  129.     private ?\DateTimeInterface $alertBTakeOffDateTime null;
  130.     #[ApiProperty(description'Alert C: is visible')]
  131.     #[Groups(['read:' self::class, 'write'])]
  132.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  133.     private bool $alertCIsVisible false;
  134.     #[ApiProperty(description'Alert C: type'writableLinkfalse)]
  135.     #[Groups(['read:' self::class, 'write'])]
  136.     #[ORM\Column(
  137.         typeTypes::STRING,
  138.         enumTypeAlertType::class,
  139.         length255,
  140.         options: ['default' => AlertType::ALERT]
  141.     )]
  142.     private AlertType $alertCType AlertType::ALERT;
  143.     #[ApiProperty(description'Alert C: is take off active')]
  144.     #[Groups(['read:' self::class, 'write'])]
  145.     #[Assert\Expression(
  146.         expression'! value || this.getAlertCTakeOffDateTime()',
  147.         message'Take off date time must be set before activating.'
  148.     )]
  149.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  150.     private bool $alertCIsTakeOffActive false;
  151.     #[ApiProperty(description'Alert C: take off date and time')]
  152.     #[Groups(['read:' self::class, 'write'])]
  153.     // #[Assert\GreaterThan('tomorrow')]
  154.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  155.     private ?\DateTimeInterface $alertCTakeOffDateTime null;
  156.     #[ApiProperty(description'CONTACT: map')]
  157.     #[Groups(['read:' self::class, 'write'])]
  158.     #[Assert\Expression(
  159.         expression'this.isContactMapFormatValid()',
  160.         message'Wrong format. Required: { lat: <float>, lng: <float>, zoom: <int> }'
  161.     )]
  162.     #[Assert\Expression(
  163.         expression'(value["lat"] ?? null) >= -90 && (value["lat"] ?? null) <= 90',
  164.         message'Latitude must be from range -90 to 90.'
  165.     )]
  166.     #[Assert\Expression(
  167.         expression'(value["lng"] ?? null) >= -90 && (value["lng"] ?? null) <= 90',
  168.         message'Longitude must be from range -90 to 90.'
  169.     )]
  170.     #[Assert\Expression(
  171.         expression'(value["zoom"] ?? null) >= 0 && (value["zoom"] ?? null) <= 18',
  172.         message'Zoom must be from range 0 to 18.'
  173.     )]
  174.     #[ORM\Column(typeTypes::JSON)]
  175.     private array $contactMap = [];
  176.     #[ApiProperty(description'Link to facebook')]
  177.     #[Groups(['read:' self::class, 'write'])]
  178.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  179.     private ?string $linkFacebook null;
  180.     #[ApiProperty(description'Link to instagram')]
  181.     #[Groups(['read:' self::class, 'write'])]
  182.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  183.     private ?string $linkInstagram null;
  184.     #[ApiProperty(description'Additional head code')]
  185.     #[Groups(['read:' self::class, 'write'])]
  186.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  187.     private ?string $additionalHeadCode null;
  188.     #[ApiProperty(description'Additional body code')]
  189.     #[Groups(['read:' self::class, 'write'])]
  190.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  191.     private ?string $additionalBodyCode null;
  192.     #[ApiProperty(description'Error report email')]
  193.     #[Groups(['read:' self::class, 'write'])]
  194.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  195.     private ?string $errorReportEmail null;
  196.     public function __construct()
  197.     {
  198.         $this->setUuid();
  199.         $this->translations = new ArrayCollection();
  200.         foreach (Language::DEFAULT_SITE as $lang) {
  201.             new ConfigTranslation($this$lang);
  202.         }
  203.         $this->createdAt = new \DateTimeImmutable();
  204.         $this->updatedAt = new \DateTimeImmutable();
  205.     }
  206.     public function getIsMourningVersionActive(): bool
  207.     {
  208.         return $this->isMourningVersionActive;
  209.     }
  210.     public function setIsMourningVersionActive(bool $isMourningVersionActive): self
  211.     {
  212.         $this->isMourningVersionActive $isMourningVersionActive;
  213.         return $this;
  214.     }
  215.     public function getHomeJournalsPerPage(): int
  216.     {
  217.         return $this->homeJournalsPerPage;
  218.     }
  219.     public function setHomeJournalsPerPage(int $homeJournalsPerPage): self
  220.     {
  221.         $this->homeJournalsPerPage $homeJournalsPerPage;
  222.         return $this;
  223.     }
  224.     public function getHomeIsJournalsAlphabeticalAscOrder(): bool
  225.     {
  226.         return $this->homeIsJournalsAlphabeticalAscOrder;
  227.     }
  228.     public function setHomeIsJournalsAlphabeticalAscOrder(bool $homeIsJournalsAlphabeticalAscOrder): self
  229.     {
  230.         $this->homeIsJournalsAlphabeticalAscOrder $homeIsJournalsAlphabeticalAscOrder;
  231.         return $this;
  232.     }
  233.     public function getHomeIsUnpublishedJournalsExcluded(): bool
  234.     {
  235.         return $this->homeIsUnpublishedJournalsExcluded;
  236.     }
  237.     public function setHomeIsUnpublishedJournalsExcluded(bool $homeIsUnpublishedJournalsExcluded): self
  238.     {
  239.         $this->homeIsUnpublishedJournalsExcluded $homeIsUnpublishedJournalsExcluded;
  240.         return $this;
  241.     }
  242.     public function getHomeIsClosedJournalsExcluded(): bool
  243.     {
  244.         return $this->homeIsClosedJournalsExcluded;
  245.     }
  246.     public function setHomeIsClosedJournalsExcluded(bool $homeIsClosedJournalsExcluded): self
  247.     {
  248.         $this->homeIsClosedJournalsExcluded $homeIsClosedJournalsExcluded;
  249.         return $this;
  250.     }
  251.     public function getHomeIsUnscientificJournalsExcluded(): bool
  252.     {
  253.         return $this->homeIsUnscientificJournalsExcluded;
  254.     }
  255.     public function setHomeIsUnscientificJournalsExcluded(bool $homeIsUnscientificJournalsExcluded): self
  256.     {
  257.         $this->homeIsUnscientificJournalsExcluded $homeIsUnscientificJournalsExcluded;
  258.         return $this;
  259.     }
  260.     public function getHomeIsIndustryJournalsExcluded(): bool
  261.     {
  262.         return $this->homeIsIndustryJournalsExcluded;
  263.     }
  264.     public function setHomeIsIndustryJournalsExcluded(bool $homeIsIndustryJournalsExcluded): self
  265.     {
  266.         $this->homeIsIndustryJournalsExcluded $homeIsIndustryJournalsExcluded;
  267.         return $this;
  268.     }
  269.     public function getAlertAIsVisible(): bool
  270.     {
  271.         return $this->alertAIsVisible;
  272.     }
  273.     public function setAlertAIsVisible(bool $alertAIsVisible): self
  274.     {
  275.         $this->alertAIsVisible $alertAIsVisible;
  276.         return $this;
  277.     }
  278.     public function getAlertAType(): AlertType
  279.     {
  280.         return $this->alertAType;
  281.     }
  282.     public function setAlertAType(AlertType $alertAType): self
  283.     {
  284.         $this->alertAType $alertAType;
  285.         return $this;
  286.     }
  287.     public function getAlertAIsTakeOffActive(): bool
  288.     {
  289.         return $this->alertAIsTakeOffActive;
  290.     }
  291.     public function setAlertAIsTakeOffActive(bool $alertAIsTakeOffActive): self
  292.     {
  293.         $this->alertAIsTakeOffActive $alertAIsTakeOffActive;
  294.         return $this;
  295.     }
  296.     public function getAlertATakeOffDateTime(): ?\DateTimeInterface
  297.     {
  298.         return $this->alertATakeOffDateTime;
  299.     }
  300.     public function setAlertATakeOffDateTime(?\DateTimeInterface $alertATakeOffDateTime): self
  301.     {
  302.         $this->alertATakeOffDateTime $alertATakeOffDateTime;
  303.         return $this;
  304.     }
  305.     public function getAlertBIsVisible(): bool
  306.     {
  307.         return $this->alertBIsVisible;
  308.     }
  309.     public function setAlertBIsVisible(bool $alertBIsVisible): self
  310.     {
  311.         $this->alertBIsVisible $alertBIsVisible;
  312.         return $this;
  313.     }
  314.     public function getAlertBType(): AlertType
  315.     {
  316.         return $this->alertBType;
  317.     }
  318.     public function setAlertBType(AlertType $alertBType): self
  319.     {
  320.         $this->alertBType $alertBType;
  321.         return $this;
  322.     }
  323.     public function getAlertBIsTakeOffActive(): bool
  324.     {
  325.         return $this->alertBIsTakeOffActive;
  326.     }
  327.     public function setAlertBIsTakeOffActive(bool $alertBIsTakeOffActive): self
  328.     {
  329.         $this->alertBIsTakeOffActive $alertBIsTakeOffActive;
  330.         return $this;
  331.     }
  332.     public function getAlertBTakeOffDateTime(): ?\DateTimeInterface
  333.     {
  334.         return $this->alertBTakeOffDateTime;
  335.     }
  336.     public function setAlertBTakeOffDateTime(?\DateTimeInterface $alertBTakeOffDateTime): self
  337.     {
  338.         $this->alertBTakeOffDateTime $alertBTakeOffDateTime;
  339.         return $this;
  340.     }
  341.     public function getAlertCIsVisible(): bool
  342.     {
  343.         return $this->alertCIsVisible;
  344.     }
  345.     public function setAlertCIsVisible(bool $alertCIsVisible): self
  346.     {
  347.         $this->alertCIsVisible $alertCIsVisible;
  348.         return $this;
  349.     }
  350.     public function getAlertCType(): AlertType
  351.     {
  352.         return $this->alertCType;
  353.     }
  354.     public function setAlertCType(AlertType $alertCType): self
  355.     {
  356.         $this->alertCType $alertCType;
  357.         return $this;
  358.     }
  359.     public function getAlertCIsTakeOffActive(): bool
  360.     {
  361.         return $this->alertCIsTakeOffActive;
  362.     }
  363.     public function setAlertCIsTakeOffActive(bool $alertCIsTakeOffActive): self
  364.     {
  365.         $this->alertCIsTakeOffActive $alertCIsTakeOffActive;
  366.         return $this;
  367.     }
  368.     public function getAlertCTakeOffDateTime(): ?\DateTimeInterface
  369.     {
  370.         return $this->alertCTakeOffDateTime;
  371.     }
  372.     public function setAlertCTakeOffDateTime(?\DateTimeInterface $alertCTakeOffDateTime): self
  373.     {
  374.         $this->alertCTakeOffDateTime $alertCTakeOffDateTime;
  375.         return $this;
  376.     }
  377.     private function clearAlert(string $type): self
  378.     {
  379.         $isTakeOffActive 'alert' strtoupper($type) . 'IsTakeOffActive';
  380.         $takeOffDateTime 'alert' strtoupper($type) . 'TakeOffDateTime';
  381.         if (
  382.             ! $this->$isTakeOffActive
  383.             || (new \DateTimeImmutable()) < $this->$takeOffDateTime
  384.         ) {
  385.             return $this;
  386.         }
  387.         $isVisible 'alert' strtoupper($type) . 'IsVisible';
  388.         $this->$isVisible false;
  389.         $this->$isTakeOffActive false;
  390.         $this->$takeOffDateTime null;
  391.         return $this;
  392.     }
  393.     public function clearAlerts(): self
  394.     {
  395.         $this
  396.             ->clearAlert('a')
  397.             ->clearAlert('b')
  398.             ->clearAlert('c');
  399.         return $this;
  400.     }
  401.     public function getContactMap(): array
  402.     {
  403.         return count($this->contactMap)
  404.             ? $this->contactMap
  405.             : [
  406.                 'lat' => 50.06195,
  407.                 'lng' => 19.93930,
  408.                 'zoom' => 14
  409.             ];
  410.     }
  411.     public function setContactMap(array $contactMap): self
  412.     {
  413.         $this->contactMap $contactMap;
  414.         return $this;
  415.     }
  416.     public function isContactMapFormatValid(): bool
  417.     {
  418.         $lat $this->contactMap['lat'] ?? null;
  419.         $lng $this->contactMap['lng'] ?? null;
  420.         $zoom $this->contactMap['zoom'] ?? null;
  421.         if (
  422.             ! is_float($lat)
  423.             || ! is_float($lng)
  424.             || ! is_int($zoom)
  425.         ) {
  426.             return false;
  427.         }
  428.         return true;
  429.     }
  430.     public function getLinkFacebook(): ?string
  431.     {
  432.         return $this->linkFacebook;
  433.     }
  434.     public function setLinkFacebook(?string $linkFacebook): self
  435.     {
  436.         $this->linkFacebook $linkFacebook;
  437.         return $this;
  438.     }
  439.     public function getLinkInstagram(): ?string
  440.     {
  441.         return $this->linkInstagram;
  442.     }
  443.     public function setLinkInstagram(?string $linkInstagram): self
  444.     {
  445.         $this->linkInstagram $linkInstagram;
  446.         return $this;
  447.     }
  448.     public function getAdditionalHeadCode(): ?string
  449.     {
  450.         return $this->additionalHeadCode;
  451.     }
  452.     public function setAdditionalHeadCode(?string $additionalHeadCode): self
  453.     {
  454.         $this->additionalHeadCode $additionalHeadCode;
  455.         return $this;
  456.     }
  457.     public function getAdditionalBodyCode(): ?string
  458.     {
  459.         return $this->additionalBodyCode;
  460.     }
  461.     public function setAdditionalBodyCode(?string $additionalBodyCode): self
  462.     {
  463.         $this->additionalBodyCode $additionalBodyCode;
  464.         return $this;
  465.     }
  466.     public function getErrorReportEmail(): ?string
  467.     {
  468.         return $this->errorReportEmail;
  469.     }
  470.     public function setErrorReportEmail(?string $errorReportEmail): self
  471.     {
  472.         $this->errorReportEmail $errorReportEmail;
  473.         return $this;
  474.     }
  475. }