コード例 #1
0
 public static function sandbox()
 {
     // Testaa koodiasi täällä
     $course = new Course(array('name' => '', 'city' => ''));
     $errors = $course->errors();
     Kint::dump($errors);
     $hole = new Hole(array('hole_num' => 'yksi', 'par' => 'kolme'));
     $errors = $hole->errors();
     Kint::dump($errors);
     echo Course::next_courseid();
 }
コード例 #2
0
ファイル: Hole.php プロジェクト: virtalas/disc-golf-stats
 public static function all()
 {
     $query = DB::connection()->prepare('SELECT * FROM hole');
     $query->execute();
     $rows = $query->fetchAll();
     return Hole::get_holes_from_rows($rows);
 }
コード例 #3
0
ファイル: Score.php プロジェクト: rryanburton/Tsoha-Bootstrap
 private function load_hole()
 {
     $this->hole = Hole::find($this->holeid);
 }
コード例 #4
0
 /**
  * Checks if round is ready to be saved. If not, displays round edit page with information already inputted. If yes, attempts to update selected round and related scores.
  *
  * @param int $id Id of selected round.
  */
 public static function update($id)
 {
     $player = self::get_user_logged_in();
     if (!$player) {
         View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat muokata ratoja.'));
     }
     $params = $_POST;
     $players = Player::all();
     $course = Course::find($params['course']);
     $courses = Course::all();
     $played = $params['played'];
     $round = Round::find($id);
     $holes = Hole::find_by_course($course->id);
     $scores = Score::find_by_round($id);
     $numberOfPlayers = sizeof($scores);
     if ($params['course'] != $params['course_orig']) {
         // If course selection has changed we need to display edit page again with new information.
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         for ($i = 1; $i <= $numberOfPlayers; $i++) {
             $holeScores = array();
             for ($j = 1; $j <= $numberOfHoles; $j++) {
                 $holeScores[] = $params['p' . $i . '_h' . $j];
             }
             $playerScores[] = array('player' => Player::find($params['player_' . $i]), 'holes' => $holeScores);
         }
         View::make('round/edit.html', array('numberOfPlayers' => $numberOfPlayers, 'players' => $players, 'course' => $course, 'holes' => $holes, 'courses' => $courses, 'playerScores' => $playerScores, 'round' => $round, 'scores' => $scores, 'played' => $played));
     } else {
         $attributes = array('courseId' => $params['course'], 'played' => $params['played']);
         $playerScores = array();
         $numberOfHoles = Hole::count_holes($params['course_orig']);
         $round = new Round(array_merge(array("id" => $round->id), $attributes));
         $errors = $round->errors();
         if (count($errors) == 0) {
             $round->update();
             for ($i = 1; $i <= $numberOfPlayers; $i++) {
                 $holeScores = array();
                 $scoreId = $params['score_' . $i];
                 for ($j = 1; $j <= $numberOfHoles; $j++) {
                     $hole = Hole::find_by_course_and_holenumber($params['course_orig'], $j);
                     $holeScores[] = array('throws' => $params['p' . $i . '_h' . $j], 'holeId' => $hole->id, 'holenumber' => $j);
                 }
                 $score = new Score(array('id' => $scoreId, 'playerId' => $params['player_' . $i], 'roundId' => $round->id, 'scores' => $holeScores));
                 $score->update();
             }
             Redirect::to('/round/' . $round->id, array('message' => 'Kierrosta muokattu.'));
         } else {
             View::make('round/new.html', array('errors' => $errors, 'attributes' => $attributes));
         }
     }
 }
コード例 #5
0
ファイル: Course.php プロジェクト: virtalas/disc-golf-stats
 private function load_holes()
 {
     $this->holes = Hole::course_holes($this->courseid);
     $this->number_of_holes = count($this->holes);
 }
コード例 #6
0
ファイル: HoleTest.php プロジェクト: restgames/battleship-php
 /**
  * @test
  * @dataProvider numberToLetterDataProvider
  *
  * @param $expectedNumber
  * @param $letter
  */
 public function givenALetterWhenAskingForItsNumberThenNumberOfThisLetterOrderShouldBeReturned($expectedNumber, $letter)
 {
     $this->assertSame($expectedNumber, Hole::letterToNumber($letter));
 }
コード例 #7
0
ファイル: course.php プロジェクト: neodyymi/Tsoha-Bootstrap
 /**
  * Counts number of holes on course.
  *
  * @return int Returns the number of holes.
  */
 public function holes()
 {
     return Hole::find_by_course($this->id);
 }
コード例 #8
0
 public static function destroy($courseid)
 {
     // Destroy both the course and its holes.
     // Also destroy all games and scores on the course.
     $course = Course::find($courseid);
     $holes = Hole::course_holes($course->courseid);
     $games = Game::course_games($courseid);
     foreach ($games as $game) {
         GameController::destroy_no_redirect($game->gameid);
     }
     foreach ($holes as $hole) {
         $hole->destroy();
     }
     $course->destroy();
     Redirect::to('/course', array('message' => 'Rata ja sen väylät poistettu. Kaikki radan pelit poistettu.'));
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function persistInteractionDetails(Question $question, \stdClass $importData)
 {
     $interaction = new InteractionOpen();
     for ($i = 0, $max = count($importData->holes); $i < $max; ++$i) {
         // temporary limitation
         if ($importData->holes[$i]->type !== 'text/html') {
             throw new \Exception("Import not implemented for MIME type {$importData->holes[$i]->type}");
         }
         $hole = new Hole();
         $hole->setOrdre($i);
         $hole->setInteractionHole($interaction);
         $interaction->addHole($hole);
         $this->om->persist($hole);
     }
     $interaction->setQuestion($question);
     $this->om->persist($interaction);
 }
コード例 #10
0
 /**
  * Attempts to update edited course information and displays the edited course.
  *
  * @param int $id Id of course to be updated.
  */
 public static function update($id)
 {
     $player = self::get_user_logged_in();
     if (!$player) {
         View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat muokata ratoja.'));
     }
     $params = $_POST;
     $params['url'] = self::fix_url($params['url']);
     $params['mapLink'] = self::fix_url($params['mapLink']);
     $attributes = array('name' => $params['name'], 'description' => $params['description'], 'address' => $params['address'], 'mapLink' => $params['mapLink'], 'url' => $params['url'], 'id' => $id);
     $course = new Course($attributes);
     $errors = $course->errors();
     if (count($errors) == 0) {
         $course->update();
         for ($i = 1; $i <= Hole::count_holes($course->id); $i++) {
             $hole = Hole::find_by_course_and_holenumber($course->id, $i);
             $hole->name = $params[$i . '_name'];
             $hole->par = $params[$i . '_par'];
             $hole->update();
         }
         Redirect::to('/course/' . $course->id, array('message' => 'Radan tietoja muutettu.'));
     } else {
         View::make('course/edit.html', array('errors' => $errors, 'attributes' => $attributes));
     }
 }
コード例 #11
0
ファイル: score.php プロジェクト: neodyymi/Tsoha-Bootstrap
 /**
  * Updates score and updates related throws and relations to holes into score_hole table.
  */
 public function update()
 {
     $query = DB::connection()->prepare('UPDATE Score SET roundid = :roundId, playerid = :playerId WHERE id = :id');
     $query->execute(array('roundId' => $this->roundId, 'playerId' => $this->playerId, 'id' => $this->id));
     if ($this->scores) {
         $round = Round::find($this->roundId);
         $numberOfHoles = Hole::count_holes($round->courseId);
         $scores = array_slice($this->scores, 0, $numberOfHoles);
         foreach ($scores as $holeScore) {
             $hole = Hole::find_by_course_and_holenumber($round->courseId, $holeScore['holenumber']);
             $query = DB::connection()->prepare('UPDATE Score_Hole SET throws = :throws WHERE holeid = :holeId AND scoreid = :scoreId');
             $exists = $query->execute(array('throws' => $holeScore['throws'], 'holeId' => $hole->id, 'scoreId' => $this->id));
             if (!$exists) {
                 $query = DB::connection()->prepare('INSERT INTO Score_Hole (holeid, scoreid, throws) VALUES (:holeId, :scoreId, :throws)');
                 $query->execute(array('throws' => $holeScore['throws'], 'holeId' => $holeScore['holeId'], 'scoreId' => $this->id));
             }
         }
     }
     $this->clean();
 }