/**
  * Store match action.
  *
  * @param  Request  $request
  * @return Response
  */
 public function storeMatch(Request $request)
 {
     $this->validate($request, $this->rules(), $this->messages());
     Match::create($request->all());
     $request->session()->flash('message', 'Match created!');
     return redirect()->route('match.list');
 }
 /**
  * Fills matches table
  *
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Match::create([]);
     }
 }
Exemple #3
0
 function dummyData()
 {
     $this->player1 = new Player(['nickname' => 'Stefan']);
     $this->player2 = new Player(['nickname' => 'Fredrik']);
     $this->match = Match::create();
     $this->match->players()->saveMany([$this->player1, $this->player2]);
 }
 /**
  * Spara i DB
  */
 public function store(Request $request)
 {
     $player1 = new Player(['nickname' => $request->input('player1')]);
     $player2 = new Player(['nickname' => $request->input('player2')]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     return redirect('match/' . $match->id);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $matches = [1 => ['id' => 1, 'date' => \Carbon\Carbon::create(2016, 6, 10, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [7, 16]], 2 => ['id' => 2, 'date' => \Carbon\Carbon::create(2016, 6, 11, 15, 0, 0), 'stadium' => 'Felix', 'teams' => [1, 21]], 3 => ['id' => 3, 'date' => \Carbon\Carbon::create(2016, 6, 15, 18, 0, 0), 'stadium' => 'Matmut', 'teams' => [16, 21]], 4 => ['id' => 4, 'date' => \Carbon\Carbon::create(2016, 6, 15, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [7, 1]], 5 => ['id' => 5, 'date' => \Carbon\Carbon::create(2016, 6, 19, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [16, 1]], 6 => ['id' => 6, 'date' => \Carbon\Carbon::create(2016, 6, 19, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [21, 7]], 7 => ['id' => 7, 'date' => \Carbon\Carbon::create(2016, 6, 11, 18, 0, 0), 'stadium' => 'Stade de France', 'teams' => [24, 18]], 8 => ['id' => 8, 'date' => \Carbon\Carbon::create(2016, 6, 11, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [6, 17]], 9 => ['id' => 9, 'date' => \Carbon\Carbon::create(2016, 6, 15, 15, 0, 0), 'stadium' => 'Matmut', 'teams' => [17, 18]], 10 => ['id' => 10, 'date' => \Carbon\Carbon::create(2016, 6, 16, 15, 0, 0), 'stadium' => 'Stade de France', 'teams' => [6, 24]], 11 => ['id' => 11, 'date' => \Carbon\Carbon::create(2016, 6, 20, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [17, 24]], 12 => ['id' => 12, 'date' => \Carbon\Carbon::create(2016, 6, 20, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [18, 6]], 13 => ['id' => 13, 'date' => \Carbon\Carbon::create(2016, 6, 12, 15, 0, 0), 'stadium' => 'Matmut', 'teams' => [23, 13]], 14 => ['id' => 14, 'date' => \Carbon\Carbon::create(2016, 6, 12, 18, 0, 0), 'stadium' => 'Stade de France', 'teams' => [8, 14]], 15 => ['id' => 15, 'date' => \Carbon\Carbon::create(2016, 6, 16, 18, 0, 0), 'stadium' => 'Felix', 'teams' => [14, 13]], 16 => ['id' => 16, 'date' => \Carbon\Carbon::create(2016, 6, 16, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [8, 23]], 17 => ['id' => 17, 'date' => \Carbon\Carbon::create(2016, 6, 21, 18, 0, 0), 'stadium' => 'Stade de France', 'teams' => [14, 23]], 18 => ['id' => 18, 'date' => \Carbon\Carbon::create(2016, 6, 21, 18, 0, 0), 'stadium' => 'Felix', 'teams' => [13, 8]], 19 => ['id' => 19, 'date' => \Carbon\Carbon::create(2016, 6, 12, 15, 0, 0), 'stadium' => 'Matmut', 'teams' => [22, 4]], 20 => ['id' => 20, 'date' => \Carbon\Carbon::create(2016, 6, 13, 15, 0, 0), 'stadium' => 'Stade de France', 'teams' => [19, 5]], 21 => ['id' => 21, 'date' => \Carbon\Carbon::create(2016, 6, 17, 18, 0, 0), 'stadium' => 'Stade de France', 'teams' => [5, 4]], 22 => ['id' => 22, 'date' => \Carbon\Carbon::create(2016, 6, 17, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [19, 22]], 23 => ['id' => 23, 'date' => \Carbon\Carbon::create(2016, 6, 21, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [5, 22]], 24 => ['id' => 24, 'date' => \Carbon\Carbon::create(2016, 6, 21, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [4, 19]], 25 => ['id' => 25, 'date' => \Carbon\Carbon::create(2016, 6, 13, 18, 0, 0), 'stadium' => 'Felix', 'teams' => [11, 20]], 26 => ['id' => 26, 'date' => \Carbon\Carbon::create(2016, 6, 13, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [3, 12]], 27 => ['id' => 27, 'date' => \Carbon\Carbon::create(2016, 6, 17, 15, 0, 0), 'stadium' => 'Stade de France', 'teams' => [12, 20]], 28 => ['id' => 28, 'date' => \Carbon\Carbon::create(2016, 6, 18, 15, 0, 0), 'stadium' => 'Felix', 'teams' => [3, 11]], 29 => ['id' => 29, 'date' => \Carbon\Carbon::create(2016, 6, 22, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [12, 11]], 30 => ['id' => 30, 'date' => \Carbon\Carbon::create(2016, 6, 22, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [20, 3]], 31 => ['id' => 31, 'date' => \Carbon\Carbon::create(2016, 6, 14, 18, 0, 0), 'stadium' => 'Stade de France', 'teams' => [2, 9]], 32 => ['id' => 32, 'date' => \Carbon\Carbon::create(2016, 6, 14, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [15, 10]], 33 => ['id' => 33, 'date' => \Carbon\Carbon::create(2016, 6, 18, 18, 0, 0), 'stadium' => 'Matmut', 'teams' => [10, 9]], 34 => ['id' => 34, 'date' => \Carbon\Carbon::create(2016, 6, 18, 21, 0, 0), 'stadium' => 'Stade de France', 'teams' => [15, 2]], 35 => ['id' => 35, 'date' => \Carbon\Carbon::create(2016, 6, 22, 21, 0, 0), 'stadium' => 'Felix', 'teams' => [10, 2]], 36 => ['id' => 36, 'date' => \Carbon\Carbon::create(2016, 6, 22, 21, 0, 0), 'stadium' => 'Matmut', 'teams' => [9, 15]]];
     foreach ($matches as $match) {
         $m = \App\Match::create(['date' => $match['date'], 'stadium' => $match['stadium']]);
         $m->teams()->attach($match['teams'][0]);
         $m->teams()->attach($match['teams'][1]);
     }
 }
 function test_starts_new_set()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player, $opponent]);
     Event::fire(new App\Events\PlayerScoredPoint($player, true));
     $this->assertEquals(11, $player->points);
     $this->assertEquals(9, $opponent->points);
 }
 public function test_player1_wins_match()
 {
     $player1 = new Player(['points' => 10, 'sets_won' => 1]);
     $player2 = new Player(['points' => 9, 'sets_won' => 1]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $this->assertEquals($player1->id, Match::find($match->id)->won_by);
     $this->assertEquals(2, Player::find($player1->id)->sets_won);
 }
 function test_it_works()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create(['set' => 2]);
     $match->players()->saveMany([$player, $opponent]);
     Event::fire(new App\Events\PlayerWonSet($player));
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals(1, Player::find($player->id)->sets_won);
 }
Exemple #9
0
 public function acceptFreelancer($id)
 {
     $projectId = Auth::user()->projects()->first()->id;
     // If has project has accepted you
     if (Decision::where('project_id', $projectId)->where('freelancer_id', $id)->where('decision', 1)->count() > 0) {
         Match::create(['project_id' => $projectId, 'freelancer_id' => $id]);
         return redirect()->route('dashboard.matches');
     } else {
         Decision::create(['user_id' => Auth::id(), 'project_id' => $projectId, 'freelancer_id' => $id, 'decision' => 1]);
     }
     return redirect()->route('dashboard.find.freelancers');
 }
 function test_it_works()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 11]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player, $opponent]);
     $this->assertEquals(1, $match->currentSet());
     Event::fire(new App\Events\StartNewSet($match));
     $expected = (object) array('Stefan' => 0, 'Fredrik' => 0);
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals($expected, Match::find($match->id)->getScore());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // This validates the information. All I'm doing right now is requiring the first and last name.
     // You can add more if you'd like to. If it fails it will thrown an exception and send back
     // to the that was sent from
     // check out http://laravel.com/docs/5.1/validation#available-validation-rules
     $this->validate($request, ['winning_team' => 'required', 'cups_left' => 'required']);
     // Make sure that the classes are imported on top of the file with the use in front.
     // Player is the class and is used up top by doing. use App\Player;
     Match::create($request->all());
     // redirect helper function to send them after storing in database
     return redirect('matches');
 }
Exemple #12
0
 public function test_player1_wins_first_set_and_player2_scores_takes_lead_in_second_set()
 {
     $player1 = Player::create(['points_set1' => 10]);
     $player2 = Player::create(['points_set1' => 9]);
     $match = Match::create(['set' => 1]);
     $match->players()->saveMany([$player1, $player2]);
     $player1->scored();
     $this->assertEquals(1, $match->set);
     $this->assertEquals(11, $player1->points());
     $this->assertEquals(9, $player2->points());
     $player2->scored();
     $this->assertEquals(2, $match->set);
     $this->assertEquals(0, $player1->points());
     $this->assertEquals(1, $player2->points());
 }
Exemple #13
0
 public function test_player1_wins_set_and_player2_scores_first_in_second_set()
 {
     $player1 = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $player2 = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $expected = (object) array('Stefan' => 11, 'Fredrik' => 9);
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
     $match->startNewSet();
     $match->resetPlayerPoints();
     $expected = (object) array('Stefan' => 0, 'Fredrik' => 0);
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
 }
 /**
  * Insert new Match
  *
  * @param  array  $data
  * @return Participant
  */
 public function create_match(array $data)
 {
     $players = Player::select('player_id', 'first_name', 'last_name', \DB::raw('CONCAT(first_name, " ", last_name) as full_name'))->lists('player_id', 'full_name');
     //check to see if players exist in Players table
     $err = '';
     if (!array_key_exists($data['player1'], $players)) {
         $err .= '  Not in Players table: ' . $data['player1'];
     }
     if (!array_key_exists($data['player2'], $players)) {
         $err .= '  Not in Players table: ' . $data['player2'];
     }
     if ($err == '') {
         $player1_id = $players[$data['player1']];
         $player2_id = $players[$data['player2']];
         $match = \DB::table('matches')->where('tournament_id', '=', $data['tournament_id'])->where('player1_id', '=', $player1_id)->where('player2_id', '=', $player2_id)->first();
         if (is_null($match)) {
             $match = Match::create(['player1_id' => $player1_id, 'player2_id' => $player2_id, 'winner_id' => $player1_id, 'tournament_id' => $data['tournament_id'], 'match_date' => $data['match_date'], 'match_type' => $data['match_type'], 'match_division' => $data['match_division']]);
         }
     }
 }
Exemple #15
0
 public function saveAssociations(Request $request)
 {
     $user = Auth::user();
     $domain_id = $request->input('domain_id');
     $inputs = $request->input('associations');
     $main_concept = Concept::find($inputs[0]['concept_id']);
     // Remove all existing associations for the concept and user
     Association::where('user_id', $user->id)->where('concept_id', $main_concept->id)->delete();
     $associations = array();
     foreach ($inputs as $association) {
         // Adding the entred concepts
         $concept = Concept::create($association['associated_concept']);
         // Adding the associations
         $associations[] = Association::create(['user_id' => $user->id, 'concept_id' => $association['concept_id'], 'weight' => $association['weight'], 'associated_concept_id' => $concept->id]);
         // Adding the appreciations if exists
         if (isset($association['associated_concept']['appreciations']) && isset($association['associated_concept']['appreciations'][0])) {
             Appreciation::create(['user_id' => $user->id, 'concept_id' => $concept->id, 'appreciation' => $association['associated_concept']['appreciations'][0]['appreciation']]);
         }
     }
     // Look if there is an open match
     $match = Match::where('concept_id', $main_concept->id)->where('user_id', '<>', $user->id)->whereNull('opponent_user_id')->get()->first();
     if ($match) {
         // if there is an open match then close it
         $match->opponent_user_id = $user->id;
         $match->save();
     } else {
         // if there is no open match then sorry :(
         // create a match
         if (!Match::where('concept_id', $main_concept->id)->where('user_id', $user->id)->whereNull('opponent_user_id')->get()->first()) {
             // if there is no open match by the same user for the same concept
             Match::create(['user_id' => $user->id, 'concept_id' => $main_concept->id]);
         }
         return Response::json(['flash' => 'No opponent found. your answers will be saved, and you will be notifed when an other player challenges them ;) .', 'nomatch' => true]);
     }
     // there is an open match!
     return Response::json(['match_id' => $match->id]);
 }