Example #1
0
 /**
  * Switch the current team of the user
  *
  * @param object|array|integer $team
  * @return $this
  * @throws ModelNotFoundException
  * @throws UserNotInTeamException
  */
 public function switchTeam($team)
 {
     if ($team !== 0 && $team !== null) {
         $team = $this->retrieveTeamId($team);
         $teamModel = Config::get('teamwork.team_model');
         $teamObject = (new $teamModel())->find($team);
         if (!$teamObject) {
             $exception = new ModelNotFoundException();
             $exception->setModel($teamModel);
             throw $exception;
         }
         if (!$teamObject->users->contains($this->getKey())) {
             $exception = new UserNotInTeamException();
             $exception->setTeam($teamObject->name);
             throw $exception;
         }
     }
     $this->current_team_id = $team;
     $this->save();
     return $this;
 }
Example #2
0
 /**
  * Switch the current team of the user
  *
  * @param object|array|integer $team
  * @return $this
  * @throws ModelNotFoundException
  * @throws UserNotInTeamException
  */
 public function switchTeam($team)
 {
     if ($team !== 0 && $team !== null) {
         if (is_object($team) && method_exists($team, 'getKey')) {
             $team = $team->getKey();
         }
         if (is_array($team) && isset($team["id"])) {
             $team = $team["id"];
         }
         $teamModel = \Config::get('teamwork.team_model');
         $teamObject = (new $teamModel())->find($team);
         if (!$teamObject) {
             $exception = new ModelNotFoundException();
             $exception->setModel($teamModel);
             throw $exception;
         }
         if (!$teamObject->users->contains($this->getKey())) {
             $exception = new UserNotInTeamException();
             $exception->setTeam($teamObject->name);
             throw $exception;
         }
     }
     $this->current_team_id = $team;
     $this->save();
     return $this;
 }