/** * Действие для редактирования матча * * @param int $id */ public function action_edit($id = null) { is_null($id) and \Response::redirect_back('admin/competitions/matches'); if (!($match = \Model_Match::find($id, array('related' => array('season', 'team_1', 'team_2', 'matches_events', 'matches_events.event'))))) { \Session::set_flash('error', 'Матч не найден.'); \Response::redirect_back('admin/competitions/matches'); } $val = \Model_Match::validate('edit'); if ($val->run()) { $match->status_id = \Input::post('status_id'); $match->date = strtotime(\Input::post('date')); $match->name = \Input::post('name'); $match->team_1_goals = \Input::post('team_1_goals'); $match->team_2_goals = \Input::post('team_2_goals'); $match->team_1_lineup = \Input::post('team_1_lineup'); $match->team_2_lineup = \Input::post('team_2_lineup'); $match->add_data = \Input::post('add_data'); if ($match->save()) { // Если нужно редактировать турнирную таблицу if (\Input::post('change_table')) { \Model_Table::edit_table($match->season_id, $match->team_1_id, $match->team_2_id, $match->team_1_goals, $match->team_2_goals); } \Session::set_flash('success', 'Данные матча обновлены.'); \Response::redirect_back('admin/competitions/matches/edit/' . $id); } else { Session::set_flash('error', 'Could not update match #' . $id); } } else { if (\Input::method() == 'POST') { $match->status_id = $val->validated('status_id'); $match->date = $val->validated('date'); $match->name = $val->validated('name'); $match->team_1_goals = $val->validated('team_1_goals'); $match->team_2_goals = $val->validated('team_2_goals'); $match->team_1_lineup = $val->validated('team_1_lineup'); $match->team_2_lineup = $val->validated('team_2_lineup'); $match->add_data = $val->validated('add_data'); \Session::set_flash('error', $val->error()); } $this->template->set_global('match', $match, false); $this->template->set_global('events', \Model_Event::get_events_for_select(), false); } $this->template->content = \View::forge('competitions/matches/edit'); }