Exemple #1
0
 public function actionAccept()
 {
     $codeMember = new CodeMember();
     $codeMember->user_id = Yii::$app->request->get('user_id');
     $codeMember->codeBank_code = Yii::$app->request->get('code');
     $codeMember->auth_item_name = Yii::$app->request->get('role');
     $message_id = Yii::$app->request->get('message_id');
     $codeMember->save();
     //Check auth_assignment
     if (Yii::$app->authManager->getAssignment($codeMember->auth_item_name, $codeMember->user_id) == null) {
         $role = Yii::$app->authManager->getRole($codeMember->auth_item_name);
         Yii::$app->authManager->assign($role, $codeMember->user_id);
     }
     $username = $codeMember->user->username;
     $message = Messages::findOne(intval($message_id));
     $message->content = Yii::$app->controller->renderPartial('_accepted_message', ['username' => $username, 'role' => $codeMember->auth_item_name, 'code' => $codeMember->codeBank_code]);
     $message->save();
     Yii::$app->session->setFlash('success', 'You have been added to participate for Hybrizy code: ' . $codeMember->codeBank_code);
     return $this->redirect(['/messages/index']);
 }
 /**
  * Finds the Messages model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Messages the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Messages::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }