|
- <?php
-
-
-
- namespace domain\Setting;
-
- use common\components\ActiveRecordCommon;
- use domain\Producer\Producer\Producer;
-
- class Setting extends ActiveRecordCommon
- {
-
-
- public static function tableName()
- {
- return 'setting';
- }
-
-
-
- public function rules()
- {
- return [
- [['name'], 'required'],
- [['id_producer'], 'integer'],
- [['id_producer'], 'exist', 'skipOnError' => true, 'targetClass' => Producer::class, 'targetAttribute' => ['id_producer' => 'id']],
- [['name', 'string', 'text'], 'string'],
- [['name','string'], 'string', 'max' => 255],
- [['date'], 'safe'],
- [['integer'], 'integer'],
- [['float', 'double'], 'number'],
- [['boolean'], 'boolean'],
- [['name'], 'unique'],
- ];
- }
-
-
-
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'id_producer' => 'Producteur',
- 'name' => 'Nom',
- ];
- }
-
- public function getValue()
- {
- $settingDetail = $this->getSettingDetail();
- $type = $settingDetail->getType();
- return $this->$type;
- }
-
- public function getSettingDetail()
- {
- return SettingDefinition::getInstance()->getSettingDetailByName($this->name);
- }
-
- public function getProducer()
- {
- return $this->hasOne(Producer::class, ['id' => 'id_producer']);
- }
-
- public function populateProducer(Producer $producer = null): void
- {
- if($producer) {
- $this->populateFieldObject('id_producer', 'producer', $producer);
- }
- }
- }
|