mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\FamilyMembersBundle\Config;
|
|
|
|
use function count;
|
|
|
|
class ConfigRepository
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $familialSituations;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $links;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $professionalSituations;
|
|
|
|
public function __construct($links, $professionnalSituations, $familialSituations)
|
|
{
|
|
$this->links = $links;
|
|
$this->professionalSituations = $professionnalSituations ?? [];
|
|
$this->familialSituations = $familialSituations ?? [];
|
|
}
|
|
|
|
public function getFamilialSituationsLabels()
|
|
{
|
|
return $this->normalizeConfig($this->familialSituations);
|
|
}
|
|
|
|
/**
|
|
* @return array where keys are the link's keys and label the links label
|
|
*/
|
|
public function getLinksLabels()
|
|
{
|
|
return $this->normalizeConfig($this->links);
|
|
}
|
|
|
|
public function getProfessionalSituationsLabels()
|
|
{
|
|
return $this->normalizeConfig($this->professionalSituations);
|
|
}
|
|
|
|
public function hasFamilialSituation(): bool
|
|
{
|
|
return count($this->familialSituations) > 0;
|
|
}
|
|
|
|
public function hasProfessionalSituation(): bool
|
|
{
|
|
return count($this->professionalSituations) > 0;
|
|
}
|
|
|
|
private function normalizeConfig($config)
|
|
{
|
|
$els = [];
|
|
|
|
foreach ($config as $definition) {
|
|
$els[$definition['key']] = $this->normalizeLabel($definition['labels']);
|
|
}
|
|
|
|
return $els;
|
|
}
|
|
|
|
private function normalizeLabel($labels)
|
|
{
|
|
$normalizedLabels = [];
|
|
|
|
foreach ($labels as $labelDefinition) {
|
|
$normalizedLabels[$labelDefinition['lang']] = $labelDefinition['label'];
|
|
}
|
|
|
|
return $normalizedLabels;
|
|
}
|
|
}
|