tabKey = $key; } return str_replace('.', '-', $this->tabKey); } /** * Формирование имени для сохранения настроек * @param integer $fieldID ID поля * @return string */ public function configName($fieldID) { if (isset($this->sysAdmin[$fieldID])) { return $this->sysAdmin[$fieldID]; } do { if (! isset($this->fields[$fieldID])) { break; } $f = $this->fields[$fieldID]; if (! isset($this->tabs[ $f['tab'] ])) { break; } $name = []; $name[] = ( $this->controller->hasParentTheme() ? $this->controller->getParentTheme()->getName() : $this->controller->getName() ); $name[] = 'page'; $name[] = $this->name(); $tab = $this->tabs[ $f['tab'] ]; if (! $tab['hidden']) { $name[] = $tab['name']; } /** @var Input $field */ $field = $f['field']; $name[] = $field->name(); return join('.', $name); } while (false); return ''; } /** * Получение сохраненных данных из конфига * @param integer $fieldID ID поля * @param mixed $default значение по умолчанию * @param mixed $opts * @return mixed */ public function config($fieldID, $default = '', $opts = []) { if (empty($this->name)) { return $default; } $name = $this->configName($fieldID); if (empty($name)) { bff::log('Wrong config name ' . __CLASS__ . '::' . __FUNCTION__); return $default; } $data = config::sysAdmin($name, $default); $field = $this->field($fieldID); $clean = $field->clean(); if (($clean == TYPE_ARRAY || $clean >= TYPE_ARRAY_BOOL) && is_string($data)) { $data = json_decode($data, true); } return $data; } /** * Сохранение данных в конфиг * @param integer $fieldID ID поля * @param mixed $save данные * @param boolean $dynamic динамическая настройка */ public function configUpdate($fieldID, $save, $dynamic = false) { if (is_array($save)) { $save = json_encode($save, JSON_UNESCAPED_UNICODE); } $name = $this->configName($fieldID); if (empty($name)) { bff::log('Wrong config name ' . __CLASS__ . '::' . __FUNCTION__); return; } config::save($name, $save); } /** * Получить директорию хранения загруженных файлов и изображений * @return string */ public function folder() { if (empty($this->folder)) { if ((method_exists($this->controller, 'hasParentTheme'))) { if ($this->controller->hasParentTheme()) { /** @var bff\extend\Extension $parent */ $parent = $this->controller->getParentTheme(); if ($parent && method_exists($parent, 'getExtensionId')) { $this->folder = $parent->getExtensionId(); } } } } return parent::folder(); } /** * Get all values in active tab * return array */ public function getActiveTabValues() { $result = []; do { if (! isset($this->tabs[$this->tabActive])) { break; } foreach ($this->fields as $f) { if (($f['tab'] ?? '') != $this->tabActive) { continue; } if (empty($f['field'])) { continue; } /** @var Input $field */ $field = $f['field']; $name = $field->name(); $value = $this->value($name, null, null); if (is_null($value)) { continue; } if (is_array($value)) { if ($field instanceof Images) { # Images if ($field->limit() === 1) { $value = $value[0]['url_o'] ?? ''; } else { $r = []; foreach ($value as $vv) { if (isset($vv['url_o'])) { $r[] = $vv['url_o']; } } $value = $r; } } elseif ($field instanceof Files) { # Files if ($field->limit() === 1) { $value = $value[0]['url'] ?? ''; } else { $r = []; foreach ($value as $vv) { if (isset($vv['url'])) { $r[] = $vv['url']; } } $value = $r; } } } $result[ $this->settingKey($name) ] = $value; } } while (false); return $result; } /** * Extract setting key * @param string $key * @param string $separator * @return string */ protected function settingKey(string $key, string $separator = '/') { if (strpos(trim($key), $separator) > 0) { return explode($separator, $key)[1] ?: trim($key, $separator); } return $key; } }