* list only user groups with enabled services in create and edit service forms * feat: add platform membership payment (wip) * WIP * revert mollie api key * remove all option for visibility in services forms * add quit platform membership * remove quit platform feature * fix good route name for payment * fix review * fix review 2
197 lines
4.9 KiB
PHP
197 lines
4.9 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\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
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;
|
|
|
|
/**
|
|
* @var Collection<int, PlatformOffer>
|
|
*/
|
|
#[ORM\OneToMany(mappedBy: 'configuration', targetEntity: PlatformOffer::class, orphanRemoval: true)]
|
|
#[ORM\OrderBy(['price' => 'ASC'])]
|
|
private Collection $offers;
|
|
|
|
/**
|
|
* Associative array to store parameters.
|
|
*
|
|
* @var array<string, array<string,mixed>>
|
|
*/
|
|
#[ORM\Column(type: 'json')]
|
|
private array $configuration = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->offers = new ArrayCollection();
|
|
}
|
|
|
|
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 array<string, bool|string>
|
|
*/
|
|
public function getGlobals(): array
|
|
{
|
|
/** @var array<string, bool|string> $globals */
|
|
$globals = $this->configuration['global'] ?? [];
|
|
|
|
return $globals;
|
|
}
|
|
|
|
public function getPlatformName(): string
|
|
{
|
|
$globals = $this->getGlobals();
|
|
|
|
return (string) ($globals['globalName'] ?? '');
|
|
}
|
|
|
|
public function getServicesEnabled(): bool
|
|
{
|
|
$globals = $this->getGlobals();
|
|
|
|
return (bool) $globals['globalServicesEnabled'];
|
|
}
|
|
|
|
public function getPaidMembership(): bool
|
|
{
|
|
$globals = $this->getGlobals();
|
|
|
|
return (bool) $globals['globalPaidMembership'];
|
|
}
|
|
|
|
/**
|
|
* @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;
|
|
}
|
|
}
|