* @copyright 2017 Stud.IP Core-Group * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 * * @category Stud.IP * * @property array $id * @property string $field * @property string $range_id * @property string $value * @property int $mkdate * @property int $chdate * @property string $comment * * @property ConfigEntry $entry */ class ConfigValue extends SimpleORMap { const RANGE_STUDIP = 'studip'; /** * Configures this model. * * @param array $config Configuration array */ protected static function configure($config = []) { $config['db_table'] = 'config_values'; $config['belongs_to']['entry'] = [ 'class_name' => \ConfigEntry::class, 'foreign_key' => 'field', ]; $config['registered_callbacks']['after_delete'][] = function (ConfigValue $value) { if (isset($value->entry) && $value->entry->type === 'i18n') { $value->getTypedValue()->removeTranslations(); } }; parent::configure($config); } public function isGlobalRange(): bool { return $this->content['range_id'] === self::RANGE_STUDIP; } public function getConfigObject(): ?\Config { if ($this->isGlobalRange()) { return \Config::get(); } return ($range = $this->getRange()) ? $range->getConfiguration() : null; } public function getRange(): ?\Range { if ($this->isGlobalRange()) { return null; } return \RangeFactory::find($this->content['range_id']); } public function getTypedValue() { $config = $this->getConfigObject(); return $config ? $config->getValue($this->content['field']) : $this->content['value']; } public function getTypedDefaultValue() { return \Config::get()->{$this->content['field']}; } }