選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SettingSolver.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. public function getDefaultValue(EntityInterface $entity, $settingDefault)
  39. {
  40. $valueDefault = null;
  41. if(is_array($settingDefault)) {
  42. if(isset($settingDefault[$entity->getDevAlias()])) {
  43. $valueDefault = $settingDefault[$entity->getDevAlias()];
  44. }
  45. }
  46. else {
  47. $valueDefault = $settingDefault;
  48. }
  49. return $valueDefault;
  50. }
  51. }