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.     #[ApiProperty(description'Payu secret')]
  197.     #[Groups(['read:' self::class, 'write'])]
  198.     #[ORM\Column(length255nullabletrue)]
  199.     private ?string $payuSecret null;
  200.     #[ApiProperty(description'Payu client id')]
  201.     #[Groups(['read:' self::class, 'write'])]
  202.     #[ORM\Column(length255nullabletrue)]
  203.     private ?string $payuClientId null;
  204.     #[ApiProperty(description'Payu second key')]
  205.     #[Groups(['read:' self::class, 'write'])]
  206.     #[ORM\Column(length255nullabletrue)]
  207.     private ?string $payuSecondKey null;
  208.     #[ApiProperty(description'Payu is sandbox')]
  209.     #[Groups(['read:' self::class, 'write'])]
  210.     #[ORM\Column(options: ['default' => true])]
  211.     private bool $payuSandbox true;
  212.     public function __construct()
  213.     {
  214.         $this->setUuid();
  215.         $this->translations = new ArrayCollection();
  216.         foreach (Language::DEFAULT_SITE as $lang) {
  217.             new ConfigTranslation($this$lang);
  218.         }
  219.         $this->createdAt = new \DateTimeImmutable();
  220.         $this->updatedAt = new \DateTimeImmutable();
  221.     }
  222.     public function getIsMourningVersionActive(): bool
  223.     {
  224.         return $this->isMourningVersionActive;
  225.     }
  226.     public function setIsMourningVersionActive(bool $isMourningVersionActive): self
  227.     {
  228.         $this->isMourningVersionActive $isMourningVersionActive;
  229.         return $this;
  230.     }
  231.     public function getHomeJournalsPerPage(): int
  232.     {
  233.         return $this->homeJournalsPerPage;
  234.     }
  235.     public function setHomeJournalsPerPage(int $homeJournalsPerPage): self
  236.     {
  237.         $this->homeJournalsPerPage $homeJournalsPerPage;
  238.         return $this;
  239.     }
  240.     public function getHomeIsJournalsAlphabeticalAscOrder(): bool
  241.     {
  242.         return $this->homeIsJournalsAlphabeticalAscOrder;
  243.     }
  244.     public function setHomeIsJournalsAlphabeticalAscOrder(bool $homeIsJournalsAlphabeticalAscOrder): self
  245.     {
  246.         $this->homeIsJournalsAlphabeticalAscOrder $homeIsJournalsAlphabeticalAscOrder;
  247.         return $this;
  248.     }
  249.     public function getHomeIsUnpublishedJournalsExcluded(): bool
  250.     {
  251.         return $this->homeIsUnpublishedJournalsExcluded;
  252.     }
  253.     public function setHomeIsUnpublishedJournalsExcluded(bool $homeIsUnpublishedJournalsExcluded): self
  254.     {
  255.         $this->homeIsUnpublishedJournalsExcluded $homeIsUnpublishedJournalsExcluded;
  256.         return $this;
  257.     }
  258.     public function getHomeIsClosedJournalsExcluded(): bool
  259.     {
  260.         return $this->homeIsClosedJournalsExcluded;
  261.     }
  262.     public function setHomeIsClosedJournalsExcluded(bool $homeIsClosedJournalsExcluded): self
  263.     {
  264.         $this->homeIsClosedJournalsExcluded $homeIsClosedJournalsExcluded;
  265.         return $this;
  266.     }
  267.     public function getHomeIsUnscientificJournalsExcluded(): bool
  268.     {
  269.         return $this->homeIsUnscientificJournalsExcluded;
  270.     }
  271.     public function setHomeIsUnscientificJournalsExcluded(bool $homeIsUnscientificJournalsExcluded): self
  272.     {
  273.         $this->homeIsUnscientificJournalsExcluded $homeIsUnscientificJournalsExcluded;
  274.         return $this;
  275.     }
  276.     public function getHomeIsIndustryJournalsExcluded(): bool
  277.     {
  278.         return $this->homeIsIndustryJournalsExcluded;
  279.     }
  280.     public function setHomeIsIndustryJournalsExcluded(bool $homeIsIndustryJournalsExcluded): self
  281.     {
  282.         $this->homeIsIndustryJournalsExcluded $homeIsIndustryJournalsExcluded;
  283.         return $this;
  284.     }
  285.     public function getAlertAIsVisible(): bool
  286.     {
  287.         return $this->alertAIsVisible;
  288.     }
  289.     public function setAlertAIsVisible(bool $alertAIsVisible): self
  290.     {
  291.         $this->alertAIsVisible $alertAIsVisible;
  292.         return $this;
  293.     }
  294.     public function getAlertAType(): AlertType
  295.     {
  296.         return $this->alertAType;
  297.     }
  298.     public function setAlertAType(AlertType $alertAType): self
  299.     {
  300.         $this->alertAType $alertAType;
  301.         return $this;
  302.     }
  303.     public function getAlertAIsTakeOffActive(): bool
  304.     {
  305.         return $this->alertAIsTakeOffActive;
  306.     }
  307.     public function setAlertAIsTakeOffActive(bool $alertAIsTakeOffActive): self
  308.     {
  309.         $this->alertAIsTakeOffActive $alertAIsTakeOffActive;
  310.         return $this;
  311.     }
  312.     public function getAlertATakeOffDateTime(): ?\DateTimeInterface
  313.     {
  314.         return $this->alertATakeOffDateTime;
  315.     }
  316.     public function setAlertATakeOffDateTime(?\DateTimeInterface $alertATakeOffDateTime): self
  317.     {
  318.         $this->alertATakeOffDateTime $alertATakeOffDateTime;
  319.         return $this;
  320.     }
  321.     public function getAlertBIsVisible(): bool
  322.     {
  323.         return $this->alertBIsVisible;
  324.     }
  325.     public function setAlertBIsVisible(bool $alertBIsVisible): self
  326.     {
  327.         $this->alertBIsVisible $alertBIsVisible;
  328.         return $this;
  329.     }
  330.     public function getAlertBType(): AlertType
  331.     {
  332.         return $this->alertBType;
  333.     }
  334.     public function setAlertBType(AlertType $alertBType): self
  335.     {
  336.         $this->alertBType $alertBType;
  337.         return $this;
  338.     }
  339.     public function getAlertBIsTakeOffActive(): bool
  340.     {
  341.         return $this->alertBIsTakeOffActive;
  342.     }
  343.     public function setAlertBIsTakeOffActive(bool $alertBIsTakeOffActive): self
  344.     {
  345.         $this->alertBIsTakeOffActive $alertBIsTakeOffActive;
  346.         return $this;
  347.     }
  348.     public function getAlertBTakeOffDateTime(): ?\DateTimeInterface
  349.     {
  350.         return $this->alertBTakeOffDateTime;
  351.     }
  352.     public function setAlertBTakeOffDateTime(?\DateTimeInterface $alertBTakeOffDateTime): self
  353.     {
  354.         $this->alertBTakeOffDateTime $alertBTakeOffDateTime;
  355.         return $this;
  356.     }
  357.     public function getAlertCIsVisible(): bool
  358.     {
  359.         return $this->alertCIsVisible;
  360.     }
  361.     public function setAlertCIsVisible(bool $alertCIsVisible): self
  362.     {
  363.         $this->alertCIsVisible $alertCIsVisible;
  364.         return $this;
  365.     }
  366.     public function getAlertCType(): AlertType
  367.     {
  368.         return $this->alertCType;
  369.     }
  370.     public function setAlertCType(AlertType $alertCType): self
  371.     {
  372.         $this->alertCType $alertCType;
  373.         return $this;
  374.     }
  375.     public function getAlertCIsTakeOffActive(): bool
  376.     {
  377.         return $this->alertCIsTakeOffActive;
  378.     }
  379.     public function setAlertCIsTakeOffActive(bool $alertCIsTakeOffActive): self
  380.     {
  381.         $this->alertCIsTakeOffActive $alertCIsTakeOffActive;
  382.         return $this;
  383.     }
  384.     public function getAlertCTakeOffDateTime(): ?\DateTimeInterface
  385.     {
  386.         return $this->alertCTakeOffDateTime;
  387.     }
  388.     public function setAlertCTakeOffDateTime(?\DateTimeInterface $alertCTakeOffDateTime): self
  389.     {
  390.         $this->alertCTakeOffDateTime $alertCTakeOffDateTime;
  391.         return $this;
  392.     }
  393.     private function clearAlert(string $type): self
  394.     {
  395.         $isTakeOffActive 'alert' strtoupper($type) . 'IsTakeOffActive';
  396.         $takeOffDateTime 'alert' strtoupper($type) . 'TakeOffDateTime';
  397.         if (
  398.             ! $this->$isTakeOffActive
  399.             || (new \DateTimeImmutable()) < $this->$takeOffDateTime
  400.         ) {
  401.             return $this;
  402.         }
  403.         $isVisible 'alert' strtoupper($type) . 'IsVisible';
  404.         $this->$isVisible false;
  405.         $this->$isTakeOffActive false;
  406.         $this->$takeOffDateTime null;
  407.         return $this;
  408.     }
  409.     public function clearAlerts(): self
  410.     {
  411.         $this
  412.             ->clearAlert('a')
  413.             ->clearAlert('b')
  414.             ->clearAlert('c');
  415.         return $this;
  416.     }
  417.     public function getContactMap(): array
  418.     {
  419.         return count($this->contactMap)
  420.             ? $this->contactMap
  421.             : [
  422.                 'lat' => 50.06195,
  423.                 'lng' => 19.93930,
  424.                 'zoom' => 14
  425.             ];
  426.     }
  427.     public function setContactMap(array $contactMap): self
  428.     {
  429.         $this->contactMap $contactMap;
  430.         return $this;
  431.     }
  432.     public function isContactMapFormatValid(): bool
  433.     {
  434.         $lat $this->contactMap['lat'] ?? null;
  435.         $lng $this->contactMap['lng'] ?? null;
  436.         $zoom $this->contactMap['zoom'] ?? null;
  437.         if (
  438.             ! is_float($lat)
  439.             || ! is_float($lng)
  440.             || ! is_int($zoom)
  441.         ) {
  442.             return false;
  443.         }
  444.         return true;
  445.     }
  446.     public function getLinkFacebook(): ?string
  447.     {
  448.         return $this->linkFacebook;
  449.     }
  450.     public function setLinkFacebook(?string $linkFacebook): self
  451.     {
  452.         $this->linkFacebook $linkFacebook;
  453.         return $this;
  454.     }
  455.     public function getLinkInstagram(): ?string
  456.     {
  457.         return $this->linkInstagram;
  458.     }
  459.     public function setLinkInstagram(?string $linkInstagram): self
  460.     {
  461.         $this->linkInstagram $linkInstagram;
  462.         return $this;
  463.     }
  464.     public function getAdditionalHeadCode(): ?string
  465.     {
  466.         return $this->additionalHeadCode;
  467.     }
  468.     public function setAdditionalHeadCode(?string $additionalHeadCode): self
  469.     {
  470.         $this->additionalHeadCode $additionalHeadCode;
  471.         return $this;
  472.     }
  473.     public function getAdditionalBodyCode(): ?string
  474.     {
  475.         return $this->additionalBodyCode;
  476.     }
  477.     public function setAdditionalBodyCode(?string $additionalBodyCode): self
  478.     {
  479.         $this->additionalBodyCode $additionalBodyCode;
  480.         return $this;
  481.     }
  482.     public function getErrorReportEmail(): ?string
  483.     {
  484.         return $this->errorReportEmail;
  485.     }
  486.     public function setErrorReportEmail(?string $errorReportEmail): self
  487.     {
  488.         $this->errorReportEmail $errorReportEmail;
  489.         return $this;
  490.     }
  491.     public function getPayuSecret(): ?string
  492.     {
  493.         return $this->payuSecret;
  494.     }
  495.     public function setPayuSecret(?string $payuSecret): static
  496.     {
  497.         $this->payuSecret $payuSecret;
  498.         return $this;
  499.     }
  500.     public function getPayuClientId(): ?string
  501.     {
  502.         return $this->payuClientId;
  503.     }
  504.     public function setPayuClientId(?string $payuClientId): static
  505.     {
  506.         $this->payuClientId $payuClientId;
  507.         return $this;
  508.     }
  509.     public function getPayuSecondKey(): ?string
  510.     {
  511.         return $this->payuSecondKey;
  512.     }
  513.     public function setPayuSecondKey(?string $payuSecondKey): static
  514.     {
  515.         $this->payuSecondKey $payuSecondKey;
  516.         return $this;
  517.     }
  518.     public function isPayuSandbox(): bool
  519.     {
  520.         return $this->payuSandbox;
  521.     }
  522.     public function setPayuSandbox(bool $payuSandbox): static
  523.     {
  524.         $this->payuSandbox $payuSandbox;
  525.         return $this;
  526.     }
  527. }