您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractSettingDefinition.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Lc\CaracoleBundle\Definition;
  3. abstract class AbstractSettingDefinition
  4. {
  5. protected $settings = [];
  6. public function addSettingText(array $params): self
  7. {
  8. $params['type'] = 'text';
  9. $params['field'] = 'text';
  10. return $this->addSetting($params);
  11. }
  12. public function addSettingTextarea(array $params): self
  13. {
  14. $params['type'] = 'textarea';
  15. $params['field'] = 'text';
  16. return $this->addSetting($params);
  17. }
  18. public function addSettingTextareaAdvanced(array $params): self
  19. {
  20. $params['type'] = 'textarea_advanced';
  21. $params['field'] = 'text';
  22. return $this->addSetting($params);
  23. }
  24. public function addSettingDate(array $params): self
  25. {
  26. $params['type'] = 'date';
  27. $params['field'] = 'date';
  28. return $this->addSetting($params);
  29. }
  30. public function addSettingTime(array $params): self
  31. {
  32. $params['type'] = 'time';
  33. $params['field'] = 'date';
  34. return $this->addSetting($params);
  35. }
  36. public function addSettingFile(array $params): self
  37. {
  38. $params['type'] = 'file';
  39. $params['field'] = 'file';
  40. return $this->addSetting($params);
  41. }
  42. public function addSettingImage(array $params): self
  43. {
  44. $params['type'] = 'image';
  45. $params['field'] = 'file';
  46. return $this->addSetting($params);
  47. }
  48. public function addSettingSelect(array $params): self
  49. {
  50. $params['type'] = 'select';
  51. $params['field'] = 'text';
  52. return $this->addSetting($params);
  53. }
  54. public function addSettingRadio(array $params): self
  55. {
  56. $params['type'] = 'radio';
  57. $params['field'] = 'text';
  58. return $this->addSetting($params);
  59. }
  60. public function addSetting($params)
  61. {
  62. $name = $params['name'];
  63. $category = $params['category'];
  64. if (!isset($this->settings[$category])) {
  65. $this->settings[$category] = [];
  66. }
  67. $this->settings[$category][$name] = $params;
  68. return $this;
  69. }
  70. public function getSettings(): array
  71. {
  72. return $this->settings;
  73. }
  74. public function getSettingsByCategory($category)
  75. {
  76. $settings = $this->getSettings();
  77. if (isset($settings[$category])) {
  78. return $settings[$category];
  79. }
  80. return [];
  81. }
  82. public function getSettingByName($name): ?array
  83. {
  84. $settings = $this->getSettings();
  85. foreach ($settings as $category => $settingsCategory) {
  86. foreach ($settingsCategory as $nameSetting => $setting) {
  87. if ($nameSetting == $name) {
  88. return $setting;
  89. }
  90. }
  91. }
  92. return null;
  93. }
  94. public function getSettingType($name): ?string
  95. {
  96. $setting = $this->getSettingByName($name);
  97. if ($setting) {
  98. return $setting['type'];
  99. }
  100. return null;
  101. }
  102. }