private function runGetImpl(Battle $battle) { $ret = ['id' => $battle->id, 'url' => Url::to(['show/battle', 'screen_name' => $battle->user->screen_name, 'battle' => $battle->id], true), 'user' => $battle->user ? $battle->user->toJsonArray() : null, 'lobby' => $battle->lobby ? $battle->lobby->toJsonArray() : null, 'rule' => $battle->rule ? $battle->rule->toJsonArray() : null, 'map' => $battle->map ? $battle->map->toJsonArray() : null, 'weapon' => $battle->weapon ? $battle->weapon->toJsonArray() : null, 'rank' => $battle->rank ? $battle->rank->toJsonArray() : null, 'rank_exp' => $battle->rank_exp, 'rank_after' => $battle->rankAfter ? $battle->rankAfter->toJsonArray() : null, 'rank_exp_after' => $battle->rank_exp_after, 'level' => $battle->level, 'level_after' => $battle->level_after, 'cash' => $battle->cash, 'cash_after' => $battle->cash_after, 'result' => $battle->is_win === true ? 'win' : ($battle->is_win === false ? 'lose' : null), 'rank_in_team' => $battle->rank_in_team, 'kill' => $battle->kill, 'death' => $battle->death, 'kill_ratio' => isset($battle->kill_ratio) ? (double) $battle->kill_ratio : null, 'death_reasons' => array_map(function ($model) { return $model->toJsonArray(); }, $battle->getBattleDeathReasons()->with(['reason', 'reason.type'])->all()), 'gender' => $battle->gender ? $battle->gender->toJsonArray() : null, 'fest_title' => $battle->gender && $battle->festTitle ? $battle->festTitle->toJsonArray($battle->gender) : null, 'my_team_color' => ['hue' => $battle->my_team_color_hue, 'rgb' => $battle->my_team_color_rgb], 'his_team_color' => ['hue' => $battle->his_team_color_hue, 'rgb' => $battle->his_team_color_rgb], 'image_judge' => $battle->battleImageJudge ? Url::to(Yii::getAlias('@web/images') . '/' . $battle->battleImageJudge->filename, true) : null, 'image_result' => $battle->battleImageResult ? Url::to(Yii::getAlias('@web/images') . '/' . $battle->battleImageResult->filename, true) : null, 'agent' => ['name' => $battle->agent ? $battle->agent->name : null, 'version' => $battle->agent ? $battle->agent->version : null], 'start_at' => $battle->start_at != '' ? DateTimeFormatter::unixTimeToJsonArray(strtotime($battle->start_at)) : null, 'end_at' => $battle->end_at != '' ? DateTimeFormatter::unixTimeToJsonArray(strtotime($battle->end_at)) : null, 'register_at' => DateTimeFormatter::unixTimeToJsonArray(strtotime($battle->at))]; if ($battle->isNawabari) { $nawabari = $battle->battleNawabari; $ret = array_merge($ret, ['my_point' => $nawabari ? (int) $nawabari->my_point : null, 'my_team_final_point' => $nawabari ? $nawabari->my_team_final_point : null, 'his_team_final_point' => $nawabari ? $nawabari->his_team_final_point : null, 'my_team_final_percent' => $nawabari ? $nawabari->my_team_final_percent : null, 'his_team_final_percent' => $nawabari ? $nawabari->his_team_final_percent : null]); } if ($battle->isGachi) { $gachi = $battle->battleGachi; $ret = array_merge($ret, ['knock_out' => $gachi ? $gachi->is_knock_out : null, 'my_team_count' => $gachi ? $gachi->my_team_count : null, 'his_team_count' => $gachi ? $gachi->his_team_count : null]); } $resp = Yii::$app->getResponse(); $resp->format = 'json'; return $ret; }