diff --git a/common/models/User.php b/common/models/User.php index d388f50..47e4bd9 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -226,7 +226,7 @@ { return $this->hasOne(UserPassport::className(), [ 'user_id' => 'id' ]); } - + /** * @return bool * @todo change this @@ -239,4 +239,18 @@ return false; } } + + public function afterSave($insert, $changedAttributes) + { + if ($insert) { + ( new UserData( + [ + 'user_id' => $this->id, + 'name' => $this->username, + ] + ) )->save(false); + ( new UserPassport([ 'user_id' => $this->id ]) )->save(false); + } + parent::afterSave($insert, $changedAttributes); + } } diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index 8fcbe26..652f584 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -26,7 +26,7 @@ public function behaviors() { return [ - 'verbs' => [ + 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'personal' => [ 'post' ], @@ -38,7 +38,7 @@ 'rules' => [ [ 'allow' => true, - 'roles' => ['@'], + 'roles' => [ '@' ], ], ], ], @@ -63,13 +63,13 @@ $userPassport = new UserPassport(); } - $table = IntellectualProperty::find() -// ->where( -// [ -// 'user_id' => \Yii::$app->user->identity->id, -// ] -// ) - ->all(); + $tableQuery = IntellectualProperty::find(); + if (!$user->isAdmin()) { + $tableQuery->joinWith('creativeRoles') + ->where([ 'intellectual_property.user_id' => $user->id ]) + ->orWhere([ 'creative_role.user_id' => $user->id ]); + } + $table = $tableQuery->all(); return $this->render( 'index', @@ -127,12 +127,11 @@ public function actionList() { - $table = IntellectualProperty::find() -// ->where( -// [ -// 'user_id' => \Yii::$app->user->identity->id, -// ] -// ) + $table = IntellectualProperty::find()// ->where( + // [ + // 'user_id' => \Yii::$app->user->identity->id, + // ] + // ) ->all(); return $this->render( 'list', @@ -157,10 +156,14 @@ public function actionNotifications() { - $table = Report::find()->all(); - return $this->render('notifications', [ - 'table' => $table, - ]); + $table = Report::find() + ->all(); + return $this->render( + 'notifications', + [ + 'table' => $table, + ] + ); } public function actionUsers() @@ -320,15 +323,15 @@ ]; } } - + public function actionUpdateRole() { $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - + $role = CreativeRole::findOne($request->get('id')); - + if ($role->load($request->post()) && $role->save()) { return [ 'success' => true, @@ -341,17 +344,17 @@ ]; } } - + public function actionGetRoleForm() { $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - + $model = CreativeRole::findOne($request->post('id')); return [ - 'answer' => $this->renderPartial('_update_form', ['model' => $model]) + 'answer' => $this->renderPartial('_update_form', [ 'model' => $model ]), ]; } diff --git a/frontend/models/CreativeRole.php b/frontend/models/CreativeRole.php index df97526..6f8d332 100755 --- a/frontend/models/CreativeRole.php +++ b/frontend/models/CreativeRole.php @@ -35,6 +35,10 @@ { return [ [ + ['user_id'], + 'required', + ], + [ [ 'intellectual_property_id', 'user_id', diff --git a/frontend/views/cabinet/index.php b/frontend/views/cabinet/index.php index 736299f..5b1201f 100755 --- a/frontend/views/cabinet/index.php +++ b/frontend/views/cabinet/index.php @@ -57,8 +57,8 @@