<?php
class actionTournamentJoin extends cmsAction {
public function run($tournament_id){
if (!$tournament_id) { cmsCore::error404(); }
$tournament = $this->model->getTournament($tournament_id);
if (!$tournament || $tournament['status'] != tournament::STATUS_PENDING) {
cmsCore::error404();
}
if(cmsUser::get('tournament_id')){
cmsUser::addSessionMessage('Вы уже в команде', 'error');
$this->redirectBack(); -***********Вот код
}
$user = cmsUser::getInstance();
$is_user_in_tournament = $user->is_admin ? false : $is_max;
if ($is_user_in_tournament){
cmsCore::error404();
}
$errors = false;
$form = $this->getForm('join');
$is_submitted = $this->request->has('submit');
$team = $form->parse($this->request, $is_submitted);
$user = cmsUser::getInstance();
if ($is_submitted){
$errors = $form->validate($this, $team);
if (!$errors){
$team['tournament_id'] = $tournament_id;
$team['user_id'] = $user->id;
$this->model->addTeam($team);
$tournament = $this->model->getTournament($tournament_id);
if ($tournament['users_count'] >= $tournament['min_users']){
$this->model->setTournamentStatus($tournament_id, tournament::STATUS_MODERATION);
}
$this->redirectToAction('event', array($tournament_id)); }
if ($errors){
cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
}
}
$template = cmsTemplate::getInstance();
$template->render('form_join', array( 'form' => $form,
'errors' => $errors,
'team' => $team,
'tournament' => $tournament
));
}
}