ebs/src/Entity/Configuration.php
Sarahshr b1e3a5150c Feat/disable services 662 (#671)
* disable button for services

* add button to disable services

* fix account services links

* fixup! fix account services links

---------

Co-authored-by: Sarahshr <sarah@les-tilleuls.coop>
2024-01-16 14:54:49 +01:00

169 lines
4.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Entity;
use App\Doctrine\Behavior\TimestampableEntity;
use App\Enum\ConfigurationType;
use App\Message\Command\Admin\ParametersFormCommand;
use App\Repository\ConfigurationRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ConfigurationRepository::class)]
class Configuration
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(name: 'type', type: 'string', nullable: false, enumType: ConfigurationType::class)]
#[Assert\NotBlank]
protected ConfigurationType $type = ConfigurationType::INSTANCE;
/**
* Associative array to store parameters.
*
* @var array<string, array<string,mixed>>
*/
#[ORM\Column(type: 'json')]
private array $configuration = [];
public function getId(): ?int
{
return $this->id;
}
public function getType(): ConfigurationType
{
return $this->type;
}
public function setType(ConfigurationType $type): self
{
$this->type = $type;
return $this;
}
/**
* @return array<string, array<string,mixed>>
*/
public function getConfiguration(): array
{
return $this->configuration;
}
/**
* @param array<string, array<string,mixed>> $configuration
*/
public function setConfiguration(array $configuration): self
{
$this->configuration = $configuration;
return $this;
}
public static function getInstanceConfiguration(): Configuration
{
return (new self())->setType(ConfigurationType::INSTANCE);
}
/** end of basic getters and setters ------------------------------------------------ */
/**
* @return bool[]
*/
public function getServices(): array
{
/** @var array<string, bool> $services */
$services = $this->configuration['services'] ?? [];
return $services;
}
public function getServicesEnabled(): bool
{
$services = $this->getServices();
return $services['servicesEnabled'];
}
/**
* @return array<string, string>
*/
public function getNotificationsSender(): array
{
/** @var array<string, string> $notificationsSender */
$notificationsSender = $this->configuration['notificationsSender'] ?? [];
return $notificationsSender;
}
public function getNotificationsSenderEmail(): string
{
$notificationsSender = $this->getNotificationsSender();
return $notificationsSender['notificationsSenderEmail'] ?? '';
}
public function getNotificationsSenderName(): string
{
$notificationsSender = $this->getNotificationsSender();
return $notificationsSender['notificationsSenderName'] ?? '';
}
/**
* @return array<mixed>
*/
public function getContactInformations(): array
{
/** @var array<mixed> $contactInfo */
$contactInfo = $this->configuration['contact'] ?? [];
return $contactInfo;
}
public function getContactEnabled(): bool
{
/** @var array<bool> $contactEnabled */
$contactEnabled = $this->getContactInformations();
return $contactEnabled['contactFormEnabled'];
}
public function getContactEmail(): string
{
/** @var array<string> $contactEnabled
*/
$contactEnabled = $this->getContactInformations();
return $contactEnabled['contactFormEmail'];
}
public function isConversationAdminAccessible(): bool
{
/** @var array<bool> $config */
$config = $this->configuration['confidentiality'] ?? [];
return $config['confidentialityConversationAdminAccess'];
}
public function isGroupsCreationForAll(): bool
{
return $this->configuration['groups']['groupsCreationMode'] === ParametersFormCommand::ALL;
}
// for test only
public function setGroupsCreationModeToAdminOnly(): self
{
$this->configuration['groups']['groupsCreationMode'] = ParametersFormCommand::ONLY_ADMIN;
return $this;
}
}