50], [['app_id', 'icon'], 'string', 'max' => 20], [['addons_name'], 'string', 'max' => 100], [['tree'], 'string', 'max' => 300], [['level'], 'default', 'value' => 1], [['title', 'icon'], 'trim'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'title' => '标题', 'app_id' => '应用', 'addons_name' => '插件名称', 'icon' => '图标', 'is_default_show' => '是否默认显示', 'is_addon' => '应用中心', 'sort' => '排序', 'level' => '级别', 'pid' => '上级id', 'tree' => '树', 'addon_centre' => '应用中心', 'status' => '状态', 'created_at' => '创建时间', 'updated_at' => '修改时间', ]; } /** * @param bool $insert * @return bool */ public function beforeSave($insert) { if ($this->is_default_show == StatusEnum::ENABLED) { self::updateAll(['is_default_show' => StatusEnum::DISABLED], ['is_default_show' => StatusEnum::ENABLED, 'app_id' => $this->app_id]); } if ($this->isNewRecord) { !$this->app_id && $this->app_id = Yii::$app->id; !$this->is_addon && $this->is_addon = WhetherEnum::DISABLED; $this->pid == 0 && $this->tree = TreeHelper::defaultTreeKey(); } return parent::beforeSave($insert); } }