Пример #1
0
 function perform($edit, $opponent, $spirit)
 {
     global $lr_session;
     if ($edit['defaulted'] != 'us' && $edit['defaulted'] != 'them') {
         $questions = $this->spirit->as_formbuilder();
         $questions->bulk_set_answers($spirit);
     } else {
         $questions = null;
     }
     $dataInvalid = $this->isDataInvalid($edit, $questions);
     if ($dataInvalid) {
         error_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.');
     }
     if ($edit['defaulted'] != 'us' && $edit['defaulted'] != 'them') {
         // Save the spirit entry if non-default
         if (!$this->spirit->store_spirit_entry($this->game, $opponent->team_id, $lr_session->attr_get('user_id'), $questions->bulk_get_answers())) {
             error_exit("Error saving spirit entry for " . $this->team->team_id);
         }
     }
     if ($edit['field_report']) {
         $fr = new FieldReport();
         $fr->set('field_id', $this->game->fid);
         $fr->set('game_id', $this->game->game_id);
         $fr->set('reporting_user_id', $lr_session->attr_get('user_id'));
         $fr->set('report_text', $edit['field_report']);
         if (!$fr->save()) {
             error_exit('Error saving field report for game ' . $this->game->game_id);
         }
     }
     // Now, we know we haven't finalized the game, so we first
     // save this team's score entry, as there isn't one already.
     if (!$this->game->save_score_entry($this->team->team_id, $lr_session->attr_get('user_id'), $edit['score_for'], $edit['score_against'], $edit['defaulted'], $edit['sotg'])) {
         error_exit("Error saving score entry for " . $this->team->team_id);
     }
     // now, check if the opponent has an entry
     if (!$this->game->get_score_entry($opponent->team_id)) {
         // No, so we just mention that it's been saved and move on
         $this->smarty->assign('have_opponent_entry', false);
     } else {
         $this->smarty->assign('have_opponent_entry', true);
         $this->smarty->assign('finalized', $this->game->finalize());
     }
     return $resultMessage;
 }