public function run()
 {
     Eloquent::unguard();
     $user = User::first();
     DB::table('tournaments')->truncate();
     DB::table('players_tournaments')->truncate();
     $tournament = new Tournament(array('user' => $user->id, 'name' => 'Tournois du 26 avril'));
     $tournament->save();
     $tournament2 = new Tournament(array('user' => $user->id, 'name' => 'Tournois du 26 mai'));
     $tournament2->save();
     $it = 0;
     foreach (Player::where('name', '<>', User::GHOST)->get() as $player) {
         $tournament->players()->attach($player->id);
         if ($it % 2 == 0) {
             $tournament2->players()->attach($player->id);
         }
         $it++;
     }
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tournament();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tournament'])) {
         $model->attributes = $_POST['Tournament'];
         $person = Person::model()->findAll();
         foreach ($person as $p) {
             $t[] = $p['id'];
         }
         //arra
         if ($model->save()) {
             for ($i = 0; $i < $model->count; $i++) {
                 $battle = new Battle();
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tournament();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tournament'])) {
         $model->attributes = $_POST['Tournament'];
         if ($model->validate()) {
             // Set up the challonge tournament before we save ours.  if this fails we need to stop
             $challonge_url = str_replace(' ', '_', strtolower($model->name)) . "_" . str_replace('/', '_', $model->date);
             $challone_name = $model->name . " " . $model->date;
             $c = new ChallongeAPI(Yii::app()->params['challonge_api']);
             $params = array("tournament[name]" => $challone_name, "tournament[tournament_type]" => $model->tournament_type, "tournament[url]" => $challonge_url, "tournament[sequential_pairings]" => 'true');
             $tournament = $c->createTournament($params)->tournament;
             if (count($c->errors)) {
                 foreach ($c->errors as $error) {
                     Yii::app()->user->setFlash('error', "Challonge ERROR: " . $error);
                 }
             } else {
                 if (!$tournament) {
                     Yii::app()->user->setFlash('error', "Was not able to create a tournament in the challonge software");
                 } else {
                     $model->challonge_id = $tournament->id;
                     $model->challonge_full_url = $tournament->full_challonge_url;
                     $model->challonge_url = $tournament->url;
                     $model->challonge_image = $tournament->live_image_url;
                     if ($model->save()) {
                         Yii::app()->user->setFlash('success', 'Tournament created');
                         $this->redirect(array('players', 'id' => $model->id));
                     }
                 }
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tournament();
     $catCategory = new Category();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tournament'])) {
         $model->attributes = $_POST['Tournament'];
         /**
          * Default values.
          */
         $model->ACTIVE = 1;
         $model->TYPE = 0;
         $model->START_E = 8;
         if ($model->save()) {
             Yii::app()->user->setFlash('success', '<strong>!Listo</strong> Se ha creado el torneo y puede configurarlo.');
             $this->redirect(array('manage', 'id' => $model->ID));
         }
     }
     $this->render('create', array('model' => $model, 'catCategory' => $catCategory));
 }