Exemple #1
0
 public function getTeamListByUser($userid)
 {
     $teamlist = TeamMember::find()->where(['user_id' => $userid])->all();
     $teamid = [];
     foreach ($teamlist as $team) {
         $teamid[] = $team->team_id;
     }
     return $teamid;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TeamMember::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'team_id' => $this->team_id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
Exemple #3
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();
     }
 }