You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1KB

  1. <?php
  2. namespace Lc\SovBundle\Solver\Setting;
  3. use Lc\SovBundle\Doctrine\EntityInterface;
  4. use Lc\SovBundle\Model\Setting\SettingInterface;
  5. use Lc\SovBundle\Model\Setting\SettingModel;
  6. class SettingSolver
  7. {
  8. public function getSetting(EntityInterface $entity, string $name): ?SettingModel
  9. {
  10. if ($entity->getSettings()) {
  11. foreach ($entity->getSettings() as $setting) {
  12. if ($setting->getName() == $name) {
  13. return $setting;
  14. }
  15. }
  16. }
  17. return null;
  18. }
  19. public function getSettingValue(EntityInterface $entity, string $name)
  20. {
  21. $setting = $this->getSetting($entity, $name);
  22. if($setting) {
  23. return $this->getValue($setting);
  24. }
  25. return null;
  26. }
  27. public function getValue(SettingInterface $setting)
  28. {
  29. if ($setting->getText()) {
  30. return $setting->getText();
  31. } elseif ($setting->getDate()) {
  32. return $setting->getDate();
  33. } elseif ($setting->getFile()) {
  34. return $setting->getFile();
  35. }
  36. return null;
  37. }
  38. }