/**
  * Called to delete our last scored goal
  * (mostly for goals with middle row players)
  */
 public function deleteGoal()
 {
     $team = Session::get('team');
     if (empty($team)) {
         return array('error' => 'You are not logged in!');
     }
     // check if user is in some match, or his match finished in last 5 minutes
     $match = MatchModel::getActiveMatchForTeam($team->id, true);
     if (empty($match)) {
         return array('error' => 'You are not in match!');
     }
     $match = $match[0];
     // run this as transaction
     return DB::transaction(function () use($match, $team) {
         $forHomeTeam = $match->home_id == $team->id;
         // decrease our score
         MatchModel::deleteGoalOnMatch($match->id, $forHomeTeam);
         // update the teams goals counters, if the game was reopened
         if ($match->home_score == 10 || $match->away_score == 10) {
             $homeTeamWon = $match->home_score == 10;
             // if we try to delete goal if we didn't win
             if ($forHomeTeam != $homeTeamWon) {
                 DB::rollback();
                 return array('error' => 'You can\'t delete goal in lost match!');
             }
             MatchModel::updateTeamGoals($match->home_id, $match->away_id, $match->home_score, $match->away_score, true);
         }
         return array('status' => 'ok');
     });
 }