private function getData(User $user, BattleFilterForm $filter)
 {
     $query = (new \yii\db\Query())->select(['map_key' => 'MAX({{map}}.[[key]])', 'rule_key' => 'MAX({{rule}}.[[key]])', 'result' => '(CASE WHEN {{battle}}.[[is_win]] = TRUE THEN \'win\' ELSE \'lose\' END)', 'count' => 'COUNT(*)'])->from('battle')->innerJoin('map', '{{battle}}.[[map_id]] = {{map}}.[[id]]')->innerJoin('rule', '{{battle}}.[[rule_id]] = {{rule}}.[[id]]')->leftJoin('lobby', '{{battle}}.[[lobby_id]] = {{lobby}}.[[id]]')->leftJoin('game_mode', '{{rule}}.[[mode_id]] = {{game_mode}}.[[id]]')->leftJoin('weapon', '{{battle}}.[[weapon_id]] = {{weapon}}.[[id]]')->leftJoin('weapon_type', '{{weapon}}.[[type_id]] = {{weapon_type}}.[[id]]')->leftJoin('subweapon', '{{weapon}}.[[subweapon_id]] = {{subweapon}}.[[id]]')->leftJoin('special', '{{weapon}}.[[special_id]] = {{special}}.[[id]]')->andWhere(['{{battle}}.[[user_id]]' => $user->id])->andWhere(['in', '{{battle}}.[[is_win]]', [true, false]])->groupBy(['{{battle}}.[[map_id]]', '{{battle}}.[[rule_id]]', '{{battle}}.[[is_win]]']);
     if ($filter && !$filter->hasErrors()) {
         $this->filter($query, $filter);
     }
     $maps = Map::find()->all();
     $rules = Rule::find()->all();
     $ret = [];
     foreach ($maps as $map) {
         $tmp = [];
         foreach ($rules as $rule) {
             $tmp[$rule->key] = ['win' => 0, 'lose' => 0];
         }
         $ret[$map->key] = $tmp;
     }
     foreach ($query->createCommand()->queryAll() as $row) {
         $row = (object) $row;
         $ret[$row->map_key][$row->rule_key][$row->result] = (int) $row->count;
     }
     $maps2 = [];
     foreach ($maps as $map) {
         $maps2[$map->key] = Yii::t('app-map', $map->name);
     }
     asort($maps2);
     $rules2 = [];
     foreach ($rules as $rule) {
         $rules2[$rule->key] = Yii::t('app-rule', $rule->name);
     }
     asort($rules2);
     return ['data' => $ret, 'mapNames' => $maps2, 'ruleNames' => $rules2];
 }
 public function run()
 {
     $rules = [];
     $query = Rule::find()->innerJoinWith('mode')->andWhere(['{{game_mode}}.[[key]]' => 'gachi']);
     foreach ($query->all() as $rule) {
         $rules[$rule->id] = Yii::t('app-rule', $rule->name);
     }
     asort($rules);
     $maps = [];
     foreach (Map::find()->all() as $map) {
         $maps[$map->id] = Yii::t('app-map', $map->name);
     }
     asort($maps);
     // init data
     $data = [];
     foreach (array_keys($maps) as $mapId) {
         $data[$mapId] = [];
         foreach (array_keys($rules) as $ruleId) {
             $data[$mapId][$ruleId] = (object) ['battle_count' => 0, 'ko_count' => 0];
         }
     }
     // set data
     foreach ($this->query() as $row) {
         $ruleId = $row['rule_id'];
         $mapId = $row['map_id'];
         $data[$mapId][$ruleId]->battle_count = (int) $row['battle_count'];
         $data[$mapId][$ruleId]->ko_count = (int) $row['ko_count'];
     }
     return $this->controller->render('knockout.tpl', ['rules' => $rules, 'maps' => $maps, 'data' => $data]);
 }
Exemple #3
0
 public function run()
 {
     $response = Yii::$app->getResponse();
     $response->format = 'json';
     return array_map(function ($map) {
         return $map->toJsonArray();
     }, Map::find()->all());
 }
 private function makeMapsList()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->key] = Yii::t('app-map', $map->name);
     }
     asort($ret);
     return array_merge(['' => Yii::t('app-map', 'Any Map')], $ret);
 }
Exemple #5
0
 /**
  * @return string
  */
 public function actionGetDots()
 {
     $points = Map::find()->all();
     $data = [];
     /* @var $point Map */
     foreach ($points as $point) {
         $item = ['center' => [$point->latitude, $point->longitude], 'name' => $point->type, 'preset' => "3islands#circleDotIcon", 'iconColor' => "#0095b6", 'balloonContent' => $point->type, 'image' => '/images/' . $point->type . '.gif'];
         $data[] = $item;
     }
     return json_encode($data);
 }
 public function up()
 {
     $map = [];
     // [ 'arowana' => 42, ... ]
     foreach (Map::find()->all() as $_) {
         $map[$_->key] = $_->id;
     }
     // 今後表記揺れが発生する可能性があるので map_id を PKEY にはしない
     $this->createTable('splapi_map', ['id' => $this->primaryKey(), 'map_id' => $this->integer()->notNull(), 'name' => $this->string(32)->notNull()->unique()]);
     $this->addForeignKey('fk_splapi_map_1', 'splapi_map', 'map_id', 'map', 'id');
     $this->batchInsert('splapi_map', ['map_id', 'name'], [[$map['arowana'], 'アロワナモール'], [$map['bbass'], 'Bバスパーク'], [$map['dekaline'], 'デカライン高架下'], [$map['hakofugu'], 'ハコフグ倉庫'], [$map['hirame'], 'ヒラメが丘団地'], [$map['hokke'], 'ホッケふ頭'], [$map['kinmedai'], 'キンメダイ美術館'], [$map['mahimahi'], 'マヒマヒリゾート&スパ'], [$map['masaba'], 'マサバ海峡大橋'], [$map['mongara'], 'モンガラキャンプ場'], [$map['mozuku'], 'モズク農園'], [$map['negitoro'], 'ネギトロ炭鉱'], [$map['shionome'], 'シオノメ油田'], [$map['tachiuo'], 'タチウオパーキング']]);
 }
 public function getInkedData()
 {
     $query = Battle::find()->with(['rule', 'map'])->innerJoinWith(['rule', 'map'])->joinWith(['lobby'])->andWhere(['{{battle}}.[[user_id]]' => $this->user->id, '{{rule}}.[[key]]' => 'nawabari'])->andWhere(['not', ['{{battle}}.[[is_win]]' => null]])->andWhere(['not', ['{{battle}}.[[my_point]]' => null]])->andWhere(['or', ['{{battle}}.[[lobby_id]]' => null], ['<>', '{{lobby}}.[[key]]', 'private']])->orderBy('{{battle}}.[[id]] DESC');
     $maps = [];
     foreach (Map::find()->all() as $map) {
         $maps[$map->key] = (object) ['key' => $map->key, 'name' => Yii::t('app-map', $map->name), 'area' => $map->area, 'battles' => [], 'avgInked' => null];
     }
     foreach ($query->each() as $battle) {
         $tmp = $maps[$battle->map->key];
         $tmp->battles[] = (object) ['index' => -1 * count($tmp->battles), 'inked' => max(0, $battle->my_point - ($battle->is_win ? 300 : 0))];
     }
     foreach ($maps as $map) {
         if (!empty($map->battles)) {
             $sum = array_sum(array_map(function ($a) {
                 return $a->inked;
             }, $map->battles));
             $map->avgInked = $sum / count($map->battles);
         }
     }
     uasort($maps, function ($a, $b) {
         return strnatcasecmp($a->name, $b->name);
     });
     return $maps;
 }
 public function enableMap($id)
 {
     $map = Map::find($id);
     $map->fill(['active' => true]);
     return $map->save();
 }
 private function makeMaps()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->id] = Yii::t('app-map', $map->name);
     }
     asort($ret);
     return static::arrayMerge(['' => Yii::t('app', 'Unknown')], $ret);
 }
 public function getMaps()
 {
     $ret = [];
     foreach (Map::find()->all() as $map) {
         $ret[$map->key] = Yii::t('app-map', $map->name);
     }
     uasort($ret, 'strnatcasecmp');
     return $ret;
 }