/**
  * Creates a new GamesPlayers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new GamesPlayers();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 2
0
 public function actionAdd()
 {
     $data = Yii::$app->request->post('data');
     $players = ArrayHelper::getColumn(GamesPlayers::find()->select('player_id')->where(['game_id' => $data['game'], 'team_id' => $data['team']])->asArray()->all(), 'player_id');
     foreach ($data['array'] as $player) {
         if (!in_array($player, $players)) {
             $model = new GamesPlayers();
             $model->game_id = $data['game'];
             $model->team_id = $data['team'];
             $model->player_id = $player;
             $model->save();
         }
     }
 }