/**
  * Add a player to the match.
  *
  * @param object    Player to add or NULL for a forfeit.
  * @param integer   Position of player in line-up.
  * @return void
  */
 public function addPlayer($Position, $Player, $Handicap = null, $Paid = null)
 {
     parent::addPlayer($Position, $Player, $Handicap, $Paid);
     if (isset($this->players[0]) && isset($this->players[1]) && $this->players[0]->player !== null && $this->players[1]->player !== null) {
         $doubles = my5280::$instance->getDoubles($this->players[0]->player, $this->players[1]->player);
         if (isset($this->players[4])) {
             $this->players[4]->player_id = $doubles->getId();
             $this->players[4]->player = $doubles;
         } else {
             $session = $this->getSession();
             $info = array('id' => null, 'match_id' => $this->getId(), 'position' => 4, 'team_id' => $this->data->home_team, 'player_id' => $doubles->getId(), 'handicap' => round($doubles->getHandicap($this->getDate(), $session->getMaxHandicapGames()), 0), 'paid' => null, 'player' => $doubles);
             $this->players[4] = (object) $info;
             ksort($this->players);
         }
     }
     if (isset($this->players[2]) && isset($this->players[3]) && $this->players[2]->player !== null && $this->players[3]->player !== null) {
         $doubles = my5280::$instance->getDoubles($this->players[2]->player, $this->players[3]->player);
         if (isset($this->players[5])) {
             $this->players[5]->player_id = $doubles->getId();
             $this->players[5]->player = $doubles;
         } else {
             if (!isset($session)) {
                 $session = $this->getSession();
             }
             $this->players[5] = (object) array('id' => null, 'match_id' => $this->getId(), 'position' => 5, 'team_id' => $this->data->away_team, 'player_id' => $doubles->getId(), 'handicap' => round($doubles->getHandicap($this->getDate(), $session->getMaxHandicapGames()), 0), 'paid' => null, 'player' => $doubles);
             ksort($this->players);
         }
     }
 }