当前位置: 首页>>代码示例>>PHP>>正文


PHP Game::games_players方法代码示例

本文整理汇总了PHP中Game::games_players方法的典型用法代码示例。如果您正苦于以下问题:PHP Game::games_players方法的具体用法?PHP Game::games_players怎么用?PHP Game::games_players使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game的用法示例。


在下文中一共展示了Game::games_players方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: all_game_scores

 public static function all_game_scores($gameid)
 {
     $players = Game::games_players($gameid);
     $player_scores = array();
     foreach ($players as $player) {
         $sql = "SELECT hole.hole_num, hole.par, score.scoreid, score.stroke, score.ob, score.legal FROM score\n                JOIN hole ON score.holeid = hole.holeid\n                WHERE score.gameid = :gameid AND score.playerid = :playerid\n                ORDER BY hole.hole_num ASC";
         $query = DB::connection()->prepare($sql);
         $query->execute(array('gameid' => $gameid, 'playerid' => $player->playerid));
         $rows = $query->fetchAll();
         $scores = array();
         $total_score = 0;
         foreach ($rows as $row) {
             $score = new Score(array('hole_num' => $row['hole_num'], 'hole_par' => $row['par'], 'scoreid' => $row['scoreid'], 'stroke' => $row['stroke'], 'ob' => $row['ob'], 'legal' => $row['legal']));
             $scores[] = $score;
             $total_score += (int) $row['stroke'];
             $total_score += (int) $row['ob'];
         }
         $player_scores['player' . $player->playerid] = $scores;
     }
     // Sort array by total score
     uasort($player_scores, function ($a, $b) {
         $a_total_score = 0;
         foreach ($a as $score) {
             $a_total_score += $score->stroke;
             $a_total_score += $score->ob;
         }
         $b_total_score = 0;
         foreach ($b as $score) {
             $b_total_score += $score->stroke;
             $b_total_score += $score->ob;
         }
         return $a_total_score - $b_total_score;
     });
     return $player_scores;
 }
开发者ID:virtalas,项目名称:disc-golf-stats,代码行数:35,代码来源:Score.php

示例2: all_game_scores

 public static function all_game_scores($gameid)
 {
     $players = Game::games_players($gameid);
     $player_scores = array();
     foreach ($players as $player) {
         $sql = "SELECT * FROM score WHERE gameid = :gameid AND playerid = :playerid";
         $query = DB::connection()->prepare($sql);
         $query->execute(array('gameid' => $gameid, 'playerid' => $player->playerid));
         $rows = $query->fetchAll();
         $scores = array();
         foreach ($rows as $row) {
             $score = new Score(array('scoreid' => $row['scoreid'], 'gameid' => $row['gameid'], 'holeid' => $row['holeid'], 'playerid' => $row['playerid'], 'stroke' => $row['stroke'], 'ob' => $row['ob']));
             $score->prepare();
             $scores[] = $score;
         }
         $player_scores[$player->firstname] = $scores;
     }
     return $player_scores;
 }
开发者ID:rryanburton,项目名称:Tsoha-Bootstrap,代码行数:19,代码来源:Score.php

示例3: update

 public static function update($gameid)
 {
     $attributes = $_POST;
     $rain = isset($_POST['rain']) && $_POST['rain'] ? "1" : "0";
     // checked=1, unchecked=0
     $wet_no_rain = isset($_POST['wet_no_rain']) && $_POST['wet_no_rain'] ? "1" : "0";
     // checked=1, unchecked=0
     $windy = isset($_POST['windy']) && $_POST['windy'] ? "1" : "0";
     // checked=1, unchecked=0
     $variant = isset($_POST['variant']) && $_POST['variant'] ? "1" : "0";
     // checked=1, unchecked=0
     $dark = isset($_POST['dark']) && $_POST['dark'] ? "1" : "0";
     // checked=1, unchecked=0
     $led = isset($_POST['led']) && $_POST['led'] ? "1" : "0";
     // checked=1, unchecked=0
     $snow = isset($_POST['snow']) && $_POST['snow'] ? "1" : "0";
     // checked=1, unchecked=0
     $doubles = isset($_POST['doubles']) && $_POST['doubles'] ? "1" : "0";
     // checked=1, unchecked=0
     $temp = $_POST['temp'] != "" ? $_POST['temp'] : null;
     // temperature can be null (or 0!)
     $date = $_POST['date'];
     $time = $_POST['time'];
     $comment = $_POST['comment'];
     $courseid = $_POST['courseid'];
     $gamedate = $date . " " . $time . ":00";
     $game = new Game(array('gameid' => $gameid, 'courseid' => $courseid, 'gamedate' => $gamedate, 'comment' => $comment, 'rain' => $rain, 'wet_no_rain' => $wet_no_rain, 'windy' => $windy, 'variant' => $variant, 'dark' => $dark, 'led' => $led, 'snow' => $snow, 'doubles' => $doubles, 'temp' => $temp));
     $errors = $game->errors();
     $course = Course::find($courseid);
     $player_scores = Score::all_game_scores($gameid);
     // Cycle through players
     foreach ($player_scores as $playerid => $scores) {
         // playerid is i.e. 'player4'
         $legal_index = 'legal-' . $playerid;
         $legal = isset($_POST[$legal_index]) && $_POST[$legal_index] ? "1" : "0";
         // checked=1, unchecked=0
         foreach ($scores as $score) {
             // inputs are in format 'player1-hole1'
             $stroke = $_POST[$playerid . '-hole' . $score->hole_num];
             $ob = $_POST[$playerid . '-obhole' . $score->hole_num];
             $score->stroke = (int) $stroke;
             $score->ob = (int) $ob;
             $score->legal = $legal;
             $errors = array_merge($errors, $score->errors());
         }
     }
     if (count($errors) == 0) {
         // Game and scores were all valid
         $gameid = $game->update();
         foreach ($player_scores as $playerid => $scores) {
             foreach ($scores as $score) {
                 $score->update();
             }
         }
         // Clear cached pages
         Cache::clear();
         Redirect::to('/game/' . $game->gameid, array('message' => 'Peli ja sen tulokset päivitetty.'));
     } else {
         $game->prepare();
         View::make('game/edit.html', array('errors' => $errors, 'game' => $game, 'date' => $date, 'time' => $time, 'players' => Game::games_players($gameid), 'attributes' => $attributes, 'course' => $game->course));
     }
 }
开发者ID:virtalas,项目名称:disc-golf-stats,代码行数:62,代码来源:game_controller.php


注:本文中的Game::games_players方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。