Exemplo n.º 1
0
 public function toJsonArray(array $skips = [])
 {
     return ['id' => $this->id, 'url' => Url::to(['show/battle', 'screen_name' => $this->user->screen_name, 'battle' => $this->id], true), 'user' => !in_array('user', $skips, true) && $this->user ? $this->user->toJsonArray() : null, 'lobby' => $this->lobby ? $this->lobby->toJsonArray() : null, 'rule' => $this->rule ? $this->rule->toJsonArray() : null, 'map' => $this->map ? $this->map->toJsonArray() : null, 'weapon' => $this->weapon ? $this->weapon->toJsonArray() : null, 'rank' => $this->rank ? $this->rank->toJsonArray() : null, 'rank_exp' => $this->rank_exp, 'rank_after' => $this->rankAfter ? $this->rankAfter->toJsonArray() : null, 'rank_exp_after' => $this->rank_exp_after, 'level' => $this->level, 'level_after' => $this->level_after, 'cash' => $this->cash, 'cash_after' => $this->cash_after, 'result' => $this->is_win === true ? 'win' : ($this->is_win === false ? 'lose' : null), 'rank_in_team' => $this->rank_in_team, 'kill' => $this->kill, 'death' => $this->death, 'kill_ratio' => isset($this->kill_ratio) ? (double) $this->kill_ratio : null, 'death_reasons' => in_array('death_reasons', $skips, true) ? null : array_map(function ($model) {
         return $model->toJsonArray();
     }, $this->battleDeathReasons), 'gender' => $this->gender ? $this->gender->toJsonArray() : null, 'fest_title' => $this->gender && $this->festTitle ? $this->festTitle->toJsonArray($this->gender) : null, 'fest_exp' => $this->fest_exp, 'fest_title_after' => $this->gender && $this->festTitleAfter ? $this->festTitleAfter->toJsonArray($this->gender) : null, 'fest_exp_after' => $this->fest_exp_after, 'my_point' => $this->my_point, 'my_team_final_point' => $this->my_team_final_point, 'his_team_final_point' => $this->his_team_final_point, 'my_team_final_percent' => $this->my_team_final_percent, 'his_team_final_percent' => $this->his_team_final_percent, 'knock_out' => $this->is_knock_out, 'my_team_count' => $this->my_team_count, 'his_team_count' => $this->his_team_count, 'my_team_color' => ['hue' => $this->my_team_color_hue, 'rgb' => $this->my_team_color_rgb], 'his_team_color' => ['hue' => $this->his_team_color_hue, 'rgb' => $this->his_team_color_rgb], 'image_judge' => $this->battleImageJudge ? Url::to(Yii::getAlias('@web/images') . '/' . $this->battleImageJudge->filename, true) : null, 'image_result' => $this->battleImageResult ? Url::to(Yii::getAlias('@web/images') . '/' . $this->battleImageResult->filename, true) : null, 'period' => $this->period, 'players' => in_array('players', $skips, true) || count($this->battlePlayers) === 0 ? null : array_map(function ($model) {
         return $model->toJsonArray();
     }, $this->battlePlayers), 'agent' => ['name' => $this->agent ? $this->agent->name : null, 'version' => $this->agent ? $this->agent->version : null, 'custom' => $this->ua_custom], 'automated' => !!$this->is_automated, 'environment' => $this->env ? $this->env->text : null, 'start_at' => $this->start_at != '' ? DateTimeFormatter::unixTimeToJsonArray(strtotime($this->start_at)) : null, 'end_at' => $this->end_at != '' ? DateTimeFormatter::unixTimeToJsonArray(strtotime($this->end_at)) : null, 'register_at' => DateTimeFormatter::unixTimeToJsonArray(strtotime($this->at))];
 }
Exemplo n.º 2
0
 public function __construct()
 {
     $time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
     $strtime = DateTimeFormatter::unixTimeToString($time, new DateTimeZone('Etc/UTC'));
     parent::__construct(Yii::$app->db->quoteValue($strtime));
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 public function toJsonArray()
 {
     return ['id' => $this->id, 'name' => $this->name, 'screen_name' => $this->screen_name, 'url' => Url::to(['show/user', 'screen_name' => $this->screen_name], true), 'join_at' => DateTimeFormatter::unixTimeToJsonArray(strtotime($this->join_at), new DateTimeZone('Etc/UTC')), 'profile' => ['nnid' => (string) $this->nnid != '' ? $this->nnid : null, 'twitter' => (string) $this->twitter != '' ? $this->twitter : null, 'ikanakama' => (string) $this->ikanakama ? sprintf('http://ikazok.net/users/%d', $this->ikanakama) : null, 'environment' => $this->env ? $this->env->text : null], 'stat' => $this->userStat ? $this->userStat->toJsonArray() : null];
 }
Exemplo n.º 5
0
 public function toJsonArray()
 {
     $t = $this->release_at ? strtotime($this->release_at) : null;
     return ['key' => $this->key, 'name' => Translator::translateToAll('app-map', $this->name), 'area' => $this->area, 'release_at' => $t ? DateTimeFormatter::unixTimeToJsonArray($t, new DateTimeZone('Etc/UTC')) : null];
 }
Exemplo n.º 6
0
 public function toJsonArray()
 {
     return ['id' => $this->id, 'name' => $this->name, 'screen_name' => $this->screen_name, 'join_at' => DateTimeFormatter::unixTimeToJsonArray(strtotime($this->join_at), new DateTimeZone('Etc/UTC'))];
 }