示例#1
0
 public function getClosedByRoundForCricket()
 {
     $hits = Hit::join('game_user->user')->where(['game_user_id' => $this->id])->order('hits.id asc')->fetchAll();
     $byRound = Arrays::groupBy($hits, Functions::extract()->round);
     $closedInRound = [];
     $closed = [15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 25 => 0];
     foreach ($byRound as $round => $hits) {
         $closedInCurrentRound = 0;
         foreach ($hits as $hit) {
             if (isset($closed[$hit->field])) {
                 $closedField = min($hit->multiplier, 3 - $closed[$hit->field]);
                 $closedInCurrentRound += $closedField;
                 $closed[$hit->field] += $closedField;
             }
         }
         $closedInRound[$round] = $closedInCurrentRound;
     }
     return $closedInRound;
 }
示例#2
0
 public function mostFrequentlyHitField()
 {
     return Hit::join('game_user')->where(['user_id' => $this->id])->select(['field', 'count(*)'])->groupBy('field')->order('count(*) DESC')->limit(1)->fetch()[0];
 }