public function actionMembers($id)
 {
     $project = $this->loadModel('app\\models\\Project', $id);
     $this->view->params['appSettings'] = ['app_name' => $project->title];
     if (!\Yii::$app->user->can('viewProject', ['project' => $project]) || \Yii::$app->user->isGuest) {
         throw new ForbiddenHttpException('Access denied');
     }
     if (\Yii::$app->request->isPost && \Yii::$app->request->post('userId')) {
         foreach (\Yii::$app->request->post('userId') as $userId => $v) {
             $model = new ProjectMember();
             $model->user_id = $userId;
             $model->project_id = $project->id;
             $model->roles = serialize(array_keys(\Yii::$app->request->post('roleId')));
             $model->save();
         }
     }
     $dataProvider = new ActiveDataProvider(['query' => ProjectMember::find()->andWhere(['project_id' => $project->id])]);
     $users = User::find()->where(['NOT IN', 'id', ArrayHelper::getColumn($dataProvider->getModels(), 'user_id')])->andWhere(['status_id' => User::STATUS_ACTIVE])->all();
     return $this->render('members', ['dataProvider' => $dataProvider, 'project' => $project, 'users' => $users]);
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMembers()
 {
     return $this->hasMany(ProjectMember::className(), ['project_id' => 'id']);
 }