Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

47 lines
1.5KB

  1. <?php
  2. namespace common\logic\Setting;
  3. use common\logic\AbstractDefinition;
  4. use common\logic\Setting\SettingDetails\Admin\AdminSettingDefinition;
  5. use common\logic\Setting\SettingDetails\Producer\ProducerSettingDefinition;
  6. class SettingDefinition extends AbstractDefinition
  7. {
  8. public function getEntityFqcn(): string
  9. {
  10. return Setting::class;
  11. }
  12. public function getSettingDetailByName(string $name)
  13. {
  14. $adminSettingDefinition = AdminSettingDefinition::getInstance();
  15. $producerSettingDefinition = ProducerSettingDefinition::getInstance();
  16. $settingDetail = $this->findSettingDetailInArray($name, $adminSettingDefinition->getSettingDetails());
  17. if(!$settingDetail) {
  18. $this->findSettingDetailInArray($name, $producerSettingDefinition->getSettingDetails());
  19. }
  20. if(!$settingDetail) {
  21. throw new \Exception('SettingDetail non trouvé');
  22. }
  23. return $settingDetail;
  24. }
  25. public function findSettingDetailInArray(string $name, array $settingDetailsArray)
  26. {
  27. foreach($settingDetailsArray as $section => $subsectionsArray) {
  28. foreach($subsectionsArray as $subsection => $settingDetailsArray) {
  29. foreach($settingDetailsArray as $settingDetail) {
  30. if($name == $settingDetail->getName()) {
  31. return $settingDetail;
  32. }
  33. }
  34. }
  35. }
  36. return null;
  37. }
  38. }