function perform($edit) { global $lr_session; if (!$this->can_edit) { error_exit("You do not have permission to edit this game"); } $s = new Spirit(); $home_spirit = $s->as_formbuilder(); $away_spirit = $s->as_formbuilder(); if ($_POST['spirit_home']) { $home_spirit->bulk_set_answers($_POST['spirit_home']); } if ($_POST['spirit_away']) { $away_spirit->bulk_set_answers($_POST['spirit_away']); } $dataInvalid = $this->isDataInvalid($edit); if ($edit['status'] == 'normal') { $dataInvalid .= $home_spirit->answers_invalid(); $dataInvalid .= $away_spirit->answers_invalid(); } if ($dataInvalid) { error_exit($dataInvalid . "<br>Please use your back button to return to the form, fix these errors, and try again"); } // store the old info: $oldgameresults['home_score'] = $this->game->home_score; $oldgameresults['away_score'] = $this->game->away_score; // Now, finalize score. $this->game->set('home_score', $edit['home_score']); $this->game->set('away_score', $edit['away_score']); $this->game->set('status', $edit['status']); $this->game->set('approved_by', $lr_session->attr_get('user_id')); // For a normal game, save spirit entries. if ($edit['status'] == 'normal') { # TODO: don't need to do this unless there are changes. if (!$s->store_spirit_entry($this->game, $this->game->home_id, $lr_session->attr_get('user_id'), $home_spirit->bulk_get_answers())) { error_exit("Error saving spirit entry for " . $this->game->home_name); } if (!$s->store_spirit_entry($this->game, $this->game->away_id, $lr_session->attr_get('user_id'), $away_spirit->bulk_get_answers())) { error_exit("Error saving spirit entry for " . $this->game->away_name); } } switch ($edit['status']) { // for defaults, have to prepare both home and away spirit scores! case 'normal': default: break; } // load the teams in order to be able to save their current rating $home_team = Team::load(array('team_id' => $this->game->home_id)); $away_team = Team::load(array('team_id' => $this->game->away_id)); // only save the current team ratings if we didn't already save them if ($this->game->rating_home == null || $this->game->rating_home == "" && $this->game->rating_away == null || $this->game->rating_away == "") { // save the current snapshot of each team's rating: $this->game->set('rating_home', $home_team->rating); $this->game->set('rating_away', $away_team->rating); } if (!$this->game->save()) { error_exit("Could not successfully save game results"); } return true; }