|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
-
-
- namespace Lc\CaracoleBundle\Definition;
-
-
- abstract class AbstractSettingDefinition
- {
- protected $settings = [];
-
- public function addSettingText(array $params): self
- {
- $params['type'] = 'text';
- $params['field'] = 'text';
- return $this->addSetting($params);
- }
-
- public function addSettingTextarea(array $params): self
- {
- $params['type'] = 'textarea';
- $params['field'] = 'text';
- return $this->addSetting($params);
- }
-
- public function addSettingTextareaAdvanced(array $params): self
- {
- $params['type'] = 'textarea_advanced';
- $params['field'] = 'text';
- return $this->addSetting($params);
- }
-
- public function addSettingDate(array $params): self
- {
- $params['type'] = 'date';
- $params['field'] = 'date';
- return $this->addSetting($params);
- }
-
- public function addSettingTime(array $params): self
- {
- $params['type'] = 'time';
- $params['field'] = 'date';
- return $this->addSetting($params);
- }
-
- public function addSettingFile(array $params): self
- {
- $params['type'] = 'file';
- $params['field'] = 'file';
- return $this->addSetting($params);
- }
-
- public function addSettingImage(array $params): self
- {
- $params['type'] = 'image';
- $params['field'] = 'file';
- return $this->addSetting($params);
- }
-
- public function addSettingSelect(array $params): self
- {
- $params['type'] = 'select';
- $params['field'] = 'text';
- return $this->addSetting($params);
- }
-
- public function addSettingRadio(array $params): self
- {
- $params['type'] = 'radio';
- $params['field'] = 'text';
- return $this->addSetting($params);
- }
-
- public function addSetting($params)
- {
- $name = $params['name'];
- $category = $params['category'];
-
- if (!isset($this->settings[$category])) {
- $this->settings[$category] = [];
- }
-
- $this->settings[$category][$name] = $params;
-
- return $this;
- }
-
- public function getSettings(): array
- {
- return $this->settings;
- }
-
- public function getSettingsByCategory($category)
- {
- $settings = $this->getSettings();
-
- if (isset($settings[$category])) {
- return $settings[$category];
- }
-
- return [];
- }
-
- public function getSettingByName($name): ?array
- {
- $settings = $this->getSettings();
-
- foreach ($settings as $category => $settingsCategory) {
- foreach ($settingsCategory as $nameSetting => $setting) {
- if ($nameSetting == $name) {
- return $setting;
- }
- }
- }
-
- return null;
- }
-
- public function getSettingType($name): ?string
- {
- $setting = $this->getSettingByName($name);
-
- if ($setting) {
- return $setting['type'];
- }
-
- return null;
- }
- }
|