You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB

7 years ago
<?php
/**
* Created by Error202
* Date: 04.06.2018
*/
namespace core\entities;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use core\behaviors\LanguageBehavior;
7 years ago
/**
* @property string $type
* @property string $section
* @property string $key
* @property integer $active
* @property integer $created_at
* @property integer $updated_at
*/
class Settings extends ActiveRecord
{
3 years ago
public Settings $_form;
public static function tableName(): string
{
return '{{%settings}}';
}
public function attributeLabels()
{
return [
'type' => Yii::t('main', 'Type'),
'section' => Yii::t('main', 'Section'),
'key' => Yii::t('main', 'Key'),
'value' => Yii::t('main', 'Value'),
'active' => Yii::t('main', 'Active'),
'created_at' => Yii::t('main', 'Created At'),
'updated_at' => Yii::t('main', 'Updated At'),
];
}
7 years ago
public static function create($form, $type, $section, $key, $active): self
{
$settings = new static();
$settings->type = $type;
$settings->section = $section;
$settings->key = $key;
$settings->active = $active;
7 years ago
$settings->_form = $form;
return $settings;
}
7 years ago
public function edit($form, $type, $section, $key, $active): void
{
$this->type = $type;
$this->section = $section;
$this->key = $key;
$this->active = $active;
$this->_form = $form;
}
7 years ago
public function behaviors(): array
{
return [
TimestampBehavior::class,
[
'class' => LanguageBehavior::class,
'virtualClassName' => 'SettingsVirtualTranslate',
3 years ago
'translatedLanguages' => Yii::$app->params['translatedLanguages'],
'relativeField' => ['section', 'key'],
'tableName' => '{{%settings_lng}}',
'attributes' => ['value'],
3 years ago
'defaultLanguage' => Yii::$app->params['defaultLanguage'],
],
];
}
}