Skip to content
Snippets Groups Projects
Select Git revision
  • 72b9c0c443e0e70c940602b3ea23f1969e67a776
  • master default protected
  • v1.5
  • v1.4.7
  • v1.4.6
  • v1.4.5
  • v1.4.4
  • v1.4.3
  • v1.4.2
  • v1.4.1
  • v1.4
  • v1.3
  • v1.2.1
  • v1.2
  • v1.1.2
  • v1.1.1
  • v1.0
17 results

MatrixAccount.php

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConfigValue.php 2.23 KiB
    <?php
    /**
     * ConfigValue.php - model class for table config_value.
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of
     * the License, or (at your option) any later version.
     *
     * @author      Elmar Ludwig <elmar.ludwig@uos.de>
     * @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 ($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']};
        }
    }