mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
95 lines
2.4 KiB
PHP
95 lines
2.4 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\BudgetBundle\Config;
|
|
|
|
class ConfigRepository
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $charges;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $resources;
|
|
|
|
public function __construct($resources, $charges)
|
|
{
|
|
$this->resources = $resources;
|
|
$this->charges = $charges;
|
|
}
|
|
|
|
public function getChargesKeys(bool $onlyActive = false): array
|
|
{
|
|
return array_map(static function ($element) { return $element['key']; }, $this->getCharges($onlyActive));
|
|
}
|
|
|
|
/**
|
|
* @return array where keys are the resource'key and label the ressource label
|
|
*/
|
|
public function getChargesLabels(bool $onlyActive = false)
|
|
{
|
|
$charges = [];
|
|
|
|
foreach ($this->getCharges($onlyActive) as $definition) {
|
|
$charges[$definition['key']] = $this->normalizeLabel($definition['labels']);
|
|
}
|
|
|
|
return $charges;
|
|
}
|
|
|
|
public function getResourcesKeys(bool $onlyActive = false): array
|
|
{
|
|
return array_map(static function ($element) { return $element['key']; }, $this->getResources($onlyActive));
|
|
}
|
|
|
|
/**
|
|
* @return array where keys are the resource'key and label the ressource label
|
|
*/
|
|
public function getResourcesLabels(bool $onlyActive = false)
|
|
{
|
|
$resources = [];
|
|
|
|
foreach ($this->getResources($onlyActive) as $definition) {
|
|
$resources[$definition['key']] = $this->normalizeLabel($definition['labels']);
|
|
}
|
|
|
|
return $resources;
|
|
}
|
|
|
|
private function getCharges(bool $onlyActive = false): array
|
|
{
|
|
return $onlyActive ?
|
|
array_filter($this->charges, static function ($el) { return $el['active']; })
|
|
: $this->charges;
|
|
}
|
|
|
|
private function getResources(bool $onlyActive = false): array
|
|
{
|
|
return $onlyActive ?
|
|
array_filter($this->resources, static function ($el) { return $el['active']; })
|
|
: $this->resources;
|
|
}
|
|
|
|
private function normalizeLabel($labels)
|
|
{
|
|
$normalizedLabels = [];
|
|
|
|
foreach ($labels as $labelDefinition) {
|
|
$normalizedLabels[$labelDefinition['lang']] = $labelDefinition['label'];
|
|
}
|
|
|
|
return $normalizedLabels;
|
|
}
|
|
}
|