| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace MGModule\DNSManager2\models\custom\globalsetting;
- use MGModule\DNSManager2 as main;
- /**
- * Log class
- *
- * @Table(name=globalsetting)
- */
- class GlobalSetting extends main\mgLibs\models\orm{
- /**
- * ID field
- *
- * @Column(id)
- * @var int
- */
- public $id;
-
- /**
- *
- * @Column(varchar,uniqueKey=1,isKey=1)
- * @var int
- */
- public $key;
-
- /**
- *
- * @Column(text)
- * @var string
- */
- public $value;
-
- public function __toString() {
- return $this->value;
- }
-
- public function save($data = array()) {
- if(!GlobalSettingEnum::isValidValue($this->key)) {
- throw new \Exception('Invalid Global Setting Key (' . $this->key . ')');
- }
- parent::save($data);
- }
-
- public static function byKey($key) {
- return Repository::factory()->byKey($key)->one();
- }
-
- public static function set($key, $value) {
- if(!$setting = self::byKey($key)) {
- $setting = new GlobalSetting();
- $setting->key = $key;
- }
- $setting->value = is_null($value) || $value === false?'':$value;
- $setting->save();
- return $setting;
- }
- }
|