芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/models/Profile.php
<?php namespace app\models; use Yii; use yii\helpers\Json; /** * This is the model class for table "{{%profile}}". * * @property int $id * @property int $company_id * @property string $name * @property int $is_visible * @property string|null $permissions * @property int|null $sort * @property string|null $created * @property string|null $updated * @property string|null $creator * @property string|null $editor * @property int|null $trash * @property int|null $active * * @property Company $company * @property User[] $users */ class Profile extends \yii\db\ActiveRecord { /** * {@inheritdoc} */ public static function tableName() { return '{{%profile}}'; } /** * {@inheritdoc} */ public function rules() { return [ [[ 'name'], 'required'], [['permissions'], 'string'], [['created', 'updated'], 'safe'], [['name'], 'string', 'max' => 100], [['trash','active'],'integer'] ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => Yii::t('app', 'ID'), 'name' => Yii::t('app', 'Name'), 'is_visible' => Yii::t('app', 'Is Visible'), 'permissions' => Yii::t('app', 'Permissions'), 'sort' => Yii::t('app', 'Sort'), 'created' => Yii::t('app', 'Created'), 'updated' => Yii::t('app', 'Updated'), 'trash' => Yii::t('app', 'Trash'), 'active' => Yii::t('app', 'Active'), ]; } public function beforeSave($insert) { if (!parent::beforeSave($insert)) { return false; } $array = json_decode($this->permissions, true); $filteredArray = array_filter($array, function($item) { return !is_null($item); }); $reindexedArray = array_values($filteredArray); $this->permissions=Json::encode($reindexedArray); return true; } public function afterSave( $insert, $changedAttributes ){ Yii::$app->response->setStatusCode(401); $q='UPDATE {{%user}} SET profile_changes=1 WHERE profile_id='.$this->id; Yii::$app->db->createCommand($q)->execute(); } /** * Gets query for [[Users]]. * * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::class, ['profile_id' => 'id']); } }