Example #1
0
 public function assignMatchCaptain($match_id)
 {
     try {
         $match_players = Match::getAllMatchPlayers($match_id);
         if (count($match_players) == 0) {
             throw new \Exception("No match players for match " . $match_id);
         }
         if (count($match_players) < self::MAX_PLAYERS_PER_MATCH) {
             throw new \Exception("Tienen que estar todos para elegir al capitán");
         }
         $current_cap = Match::getFlaggedPlayers($match_id);
         if (count($current_cap) == 0) {
             $random_player = array_rand($match_players);
             $user_id = $random_player['user_id'];
             Match::flagMatchPlayer($match_id, $user_id);
         } else {
             $user_id = $current_cap[0]["user_id"];
         }
         return $user_id;
     } catch (\Exception $e) {
         throw $e;
     }
 }