/**
  * Creates a new TeamMember model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new TeamMember();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
0
 public function addTeam()
 {
     $addlist = [];
     $dellist = [];
     $teamlist = TeamMember::find()->where(['user_id' => $this->id])->all();
     foreach ($teamlist as $oldteam) {
         $flag = 0;
         foreach ($this->team as $i) {
             if ($oldteam->team_id == $i) {
                 $flag = 1;
             }
         }
         if ($flag == 0) {
             $dellist[] = $oldteam->team_id;
         }
     }
     foreach ($this->team as $newindex) {
         $flag = 0;
         foreach ($teamlist as $oldteam) {
             if ($oldteam->team_id == $newindex) {
                 $flag = 1;
             }
         }
         if ($flag == 0) {
             $addlist[] = $newindex;
         }
     }
     foreach ($addlist as $addindex) {
         $newteam = new TeamMember(['team_id' => $addindex, 'user_id' => $this->id]);
         $newteam->save();
     }
     foreach ($dellist as $delindex) {
         $deltarget = TeamMember::getObjectById($delindex, $this->id);
         $deltarget->delete();
     }
 }