public function createCurrentData() { static $nawabari = null; if ($nawabari === null) { $nawabari = Rule::findOne(['key' => 'nawabari'])->id; } $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); $shortCondition = sprintf('(({{battle}}.[[end_at]] IS NOT NULL) AND ({{battle}}.[[end_at]] BETWEEN %s AND %s))', Yii::$app->db->quoteValue(gmdate('Y-m-d H:i:sO', $now - 86400 + 1)), Yii::$app->db->quoteValue(gmdate('Y-m-d H:i:sO', $now))); $column_battle_count = "COUNT(*)"; $column_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[is_win]] IS NULL THEN 0 ELSE 1 END)"); $column_wp_short = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {$shortCondition} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {$shortCondition} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)"); $column_total_kill = sprintf("SUM(%s)", "CASE WHEN " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END"); $column_total_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END"); $column_nawabari_count = "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} THEN 1 ELSE 0 END)"; $column_nawabari_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)"); $column_nawabari_kill = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END"); $column_nawabari_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END"); $column_gachi_count = "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} THEN 1 ELSE 0 END)"; $column_gachi_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)"); $column_gachi_kill = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END"); $column_gachi_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END"); $query = (new \yii\db\Query())->select(['battle_count' => $column_battle_count, 'wp' => $column_wp, 'wp_short' => $column_wp_short, 'total_kill' => $column_total_kill, 'total_death' => $column_total_death, 'nawabari_count' => $column_nawabari_count, 'nawabari_wp' => $column_nawabari_wp, 'nawabari_kill' => $column_nawabari_kill, 'nawabari_death' => $column_nawabari_death, 'gachi_count' => $column_gachi_count, 'gachi_wp' => $column_gachi_wp, 'gachi_kill' => $column_gachi_kill, 'gachi_death' => $column_gachi_death])->from('battle')->andWhere(['{{battle}}.[[user_id]]' => $this->user_id]); $this->attributes = $query->createCommand()->queryOne(); $keys = ['battle_count', 'total_kill', 'total_death', 'nawabari_count', 'nawabari_kill', 'nawabari_death', 'gachi_count', 'gachi_kill', 'gachi_death']; foreach ($keys as $key) { $this->{$key} = (int) $this->{$key}; } }
private function createSelectQueryForUpdateEntireWeapons() { $ruleNawabari = Rule::findOne(['key' => 'nawabari'])->id; $query = BattlePlayer::find()->innerJoinWith(['battle' => function ($q) { return $q->orderBy(null); }, 'battle.lobby', 'weapon'])->andWhere(['{{battle}}.[[is_automated]]' => true])->andWhere(['<>', '{{lobby}}.[[key]]', 'private'])->andWhere(['not', ['{{battle}}.[[is_win]]' => null]])->andWhere(['not', ['{{battle_player}}.[[kill]]' => null]])->andWhere(['not', ['{{battle_player}}.[[death]]' => null]])->andWhere(['{{battle_player}}.[[is_me]]' => false])->groupBy('{{battle}}.[[rule_id]], {{battle_player}}.[[weapon_id]]'); // ルール別の処理を記述 $query->andWhere(['or', ['and', ['{{battle}}.[[rule_id]]' => $ruleNawabari], ['not', ['{{battle_player}}.[[point]]' => null]], ['or', ['{{lobby}}.[[key]]' => 'standard'], ['{{lobby}}.[[key]]' => 'fest', '{{battle_player}}.[[is_my_team]]' => false]], ['or', ['and', ['=', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 300]], ['and', ['<>', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 0]]]], ['and', ['<>', '{{battle}}.[[rule_id]]', $ruleNawabari], ['not like', '{{lobby}}.[[key]]', 'squad_%', false]]]); $query->select(['rule_id' => '{{battle}}.[[rule_id]]', 'weapon_id' => '{{battle_player}}.[[weapon_id]]', 'players' => 'COUNT(*)', 'total_kill' => 'SUM({{battle_player}}.[[kill]])', 'total_death' => 'SUM({{battle_player}}.[[death]])', 'win_count' => sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle}}.[[is_win]] = TRUE AND {{battle_player}}.[[is_my_team]] = TRUE THEN 1', 'WHEN {{battle}}.[[is_win]] = FALSE AND {{battle_player}}.[[is_my_team]] = FALSE THEN 1', 'ELSE 0'])), 'total_point' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'WHEN {{battle}}.[[is_win]] = {{battle_player}}.[[is_my_team]] THEN battle_player.point - 300', 'ELSE {{battle_player}}.[[point]]']))), 'point_available' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'ELSE 1'])))]); return $query; }
public function createCurrentData() { $db = Yii::$app->db; static $nawabari = null; if ($nawabari === null) { $nawabari = Rule::findOne(['key' => 'nawabari'])->id; } $condIsNawabari = sprintf('({{battle}}.[[rule_id]] = %s)', $db->quoteValue($nawabari)); $condIsGachi = sprintf('({{battle}}.[[rule_id]] <> %s)', $db->quoteValue($nawabari)); static $private = null; if ($private === null) { $private = Lobby::findOne(['key' => 'private'])->id; } $condIsNotPrivate = sprintf('({{battle}}.[[lobby_id]] IS NULL OR {{battle}}.[[lobby_id]] <> %s)', $db->quoteValue($private)); $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); $cond24Hours = sprintf('(({{battle}}.[[end_at]] IS NOT NULL) AND ({{battle}}.[[end_at]] BETWEEN %s AND %s))', $db->quoteValue(gmdate('Y-m-d H:i:sO', $now - 86400 + 1)), $db->quoteValue(gmdate('Y-m-d H:i:sO', $now))); $condKDPresent = sprintf('(%s)', implode(' AND ', ['{{battle}}.[[kill]] IS NOT NULL', '{{battle}}.[[death]] IS NOT NULL'])); $column_battle_count = "COUNT(*)"; $column_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] IS NOT NULL']))); $column_wp_short = sprintf("(%s * 100.0 / NULLIF(%s, 0))", sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] IS NOT NULL']))); $column_total_kd_battle_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent])); $column_total_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent])); $column_total_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent])); $column_nawabari_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari])); $column_nawabari_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] IS NOT NULL']))); $column_nawabari_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent])); $column_nawabari_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent])); $column_gachi_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi])); $column_gachi_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] IS NOT NULL']))); $column_gachi_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent])); $column_gachi_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent])); $query = (new \yii\db\Query())->select(['battle_count' => $column_battle_count, 'wp' => $column_wp, 'wp_short' => $column_wp_short, 'total_kill' => $column_total_kill, 'total_death' => $column_total_death, 'total_kd_battle_count' => $column_total_kd_battle_count, 'nawabari_count' => $column_nawabari_count, 'nawabari_wp' => $column_nawabari_wp, 'nawabari_kill' => $column_nawabari_kill, 'nawabari_death' => $column_nawabari_death, 'gachi_count' => $column_gachi_count, 'gachi_wp' => $column_gachi_wp, 'gachi_kill' => $column_gachi_kill, 'gachi_death' => $column_gachi_death])->from('battle')->andWhere(['{{battle}}.[[user_id]]' => $this->user_id]); $this->attributes = $query->createCommand()->queryOne(); $keys = ['battle_count', 'total_kill', 'total_death', 'total_kd_battle_count', 'nawabari_count', 'nawabari_kill', 'nawabari_death', 'gachi_count', 'gachi_kill', 'gachi_death']; foreach ($keys as $key) { $this->{$key} = (int) $this->{$key}; } return $this; }
private function mapUpdateRegular() { echo "regular...\n"; $latestPeriod = $this->getLatestPeriod(GameMode::findOne(['key' => 'regular'])); $currntPeriod = \app\components\helpers\Battle::calcPeriod(time()); $futureOnly = $latestPeriod >= $currntPeriod; $json = array_filter(array_map(function ($item) { $item->period = \app\components\helpers\Battle::calcPeriod(strtotime($item->start)); return $item; }, $this->queryJson($futureOnly ? 'http://splapi.retrorocket.biz/regular/next_all' : 'http://splapi.retrorocket.biz/regular')->result), function ($item) use($latestPeriod) { return $item->period > $latestPeriod; }); if (empty($json)) { echo "no data updated.\n"; return; } printf("count(new_data) = %d\n", count($json)); usort($json, function ($a, $b) { return $a->period - $b->period; }); echo "Converting to insert data...\n"; $map = $this->getMapTable(); $rule_id = Rule::findOne(['key' => 'nawabari'])->id; $insert = []; foreach ($json as $item) { foreach ($item->maps as $mapName) { if (isset($map[$mapName])) { $insert[] = [$item->period, $rule_id, $map[$mapName]]; } else { echo "Unknown map name: {$mapName}\n"; } } } echo "inserting...\n"; Yii::$app->db->createCommand()->batchInsert(PeriodMap::tableName(), ['period', 'rule_id', 'map_id'], $insert)->execute(); echo "done.\n"; }
public static function execute($id) { echo '$id: ' . $id . '<br/>' . PHP_EOL; Yii::info('execute id: ' . $id, 'rule'); $model = Rule::findOne($id); // Rule Condition Yii::info('condition', 'rule'); $modelsRuleCondition = RuleCondition::findAll(['rule_id' => $id]); /*echo('$modelsRuleCondition: <pre>'); print_r($modelsRuleCondition); echo('</pre>');*/ // condition foreach ($modelsRuleCondition as $modelRuleCondition) { Yii::info('$modelRuleCondition->id: ' . $modelRuleCondition->id, 'rule'); Yii::info('$modelRuleCondition->condition: ' . $modelRuleCondition->condition, 'rule'); Yii::info('$modelRuleCondition->condition_value: ' . $modelRuleCondition->condition_value, 'rule'); Yii::info('$modelRuleCondition->equation: ' . $modelRuleCondition->equation, 'rule'); Yii::info('$modelRuleCondition->value: ' . $modelRuleCondition->value, 'rule'); Yii::info('$modelRuleCondition->value_value: ' . $modelRuleCondition->value_value, 'rule'); echo '$modelRuleCondition->id: ' . $modelRuleCondition->id . '<br/>' . PHP_EOL; echo '$modelRuleCondition->condition: ' . $modelRuleCondition->condition . '<br/>' . PHP_EOL; echo '$modelRuleCondition->condition_value: ' . $modelRuleCondition->condition_value . '<br/>' . PHP_EOL; echo '$modelRuleCondition->equation: ' . $modelRuleCondition->equation . '<br/>' . PHP_EOL; echo '$modelRuleCondition->value: ' . $modelRuleCondition->value . '<br/>' . PHP_EOL; echo '$modelRuleCondition->value_value: ' . $modelRuleCondition->value_value . '<br/>' . PHP_EOL; if (!class_exists('app\\models\\' . $modelRuleCondition->condition)) { Yii::info('!class_exists: ' . 'app\\models\\' . $modelRuleCondition->condition, 'rule'); return false; } if (!class_exists('app\\models\\' . $modelRuleCondition->value)) { Yii::info('!class_exists: ' . 'app\\models\\' . $modelRuleCondition->value, 'rule'); return false; } $conditions = call_user_func(array('app\\models\\' . ucfirst($modelRuleCondition->condition), 'ruleCondition'), $modelRuleCondition->condition_value); Yii::info('$conditions: ' . json_encode($conditions), 'rule'); echo '$conditions: <pre>'; print_r($conditions); echo '</pre>'; $conditions_values = call_user_func(array('app\\models\\' . ucfirst($modelRuleCondition->value), 'ruleCondition'), $modelRuleCondition->value_value); Yii::info('$conditions_values: ' . json_encode($conditions_values), 'rule'); echo '$conditions_values: <pre>'; print_r($conditions_values); echo '</pre>'; // if one of the $values is true relative to the $condition $equation = false; Yii::info('$equation: ' . json_encode($equation), 'rule'); // json_encode prints true or false foreach ($conditions_values as $value) { Yii::info('$value: ' . $value, 'rule'); foreach ($conditions as $condition) { echo '$value: ' . $value . '<br/>' . PHP_EOL; echo '$condition: ' . $condition . '<br/>' . PHP_EOL; // $equal = version_compare($condition, $value, $modelRuleCondition->equation); Yii::info('$equal: ' . json_encode($equal), 'rule'); // json_encode prints true or false if ($equal) { $equation = true; } } } echo '$equation: ' . $equation . '<br/>' . PHP_EOL; var_dump($equation); //exit(); if (!$equation) { Yii::info('!$equation', 'rule'); return false; } } echo 'condition is: ' . $equation . '<br/>' . PHP_EOL; // if nothing has returned something, the condition must be gone good Yii::info('action', 'rule'); $modelsRuleAction = RuleAction::findAll(['rule_id' => $id]); /*echo('$modelsRuleCondition: <pre>'); print_r($modelsRuleCondition); echo('</pre>');*/ foreach ($modelsRuleAction as $modelRuleAction) { Yii::info('$modelRuleAction->id: ' . $modelRuleAction->id, 'rule'); Yii::info('$modelRuleAction->action: ' . $modelRuleAction->action, 'rule'); Yii::info('$modelRuleAction->action_value: ' . $modelRuleAction->action_value, 'rule'); Yii::info('$modelRuleAction->value: ' . $modelRuleAction->value, 'rule'); Yii::info('$modelRuleAction->value_value: ' . $modelRuleAction->value_value, 'rule'); echo '$modelRuleAction->id: ' . $modelRuleAction->id . '<br/>' . PHP_EOL; echo '$modelRuleAction->action: ' . $modelRuleAction->action . '<br/>' . PHP_EOL; echo '$modelRuleAction->action_value: ' . $modelRuleAction->action_value . '<br/>' . PHP_EOL; echo '$modelRuleAction->value: ' . $modelRuleAction->value . '<br/>' . PHP_EOL; echo '$modelRuleAction->value_value: ' . $modelRuleAction->value_value . '<br/>' . PHP_EOL; //exit(); if (!class_exists('app\\models\\' . $modelRuleAction->action)) { Yii::info('!class_exists: ' . 'app\\models\\' . $modelRuleAction->action, 'rule'); return false; } // only retrieve a value if the action is setting $value = ''; if ('setting' == $modelRuleAction->action) { if (!class_exists('app\\models\\' . $modelRuleAction->value)) { Yii::info('!class_exists: ' . 'app\\models\\' . $modelRuleAction->value, 'rule'); return false; } // get the value $values = call_user_func(array('app\\models\\' . ucfirst($modelRuleAction->value), 'ruleCondition'), $modelRuleAction->value_value); Yii::info('$value: ' . $value, 'rule'); echo '$values: <pre>'; print_r($values); echo '</pre>'; $value = HelperData::dataImplode($values); echo '$value: ' . $value . '<br/>' . PHP_EOL; } // use the value $return = call_user_func(array('app\\models\\' . ucfirst($modelRuleAction->action), 'ruleAction'), $modelRuleAction->action_value, $value); Yii::info('$return: ' . json_encode($return), 'rule'); //exit(); if (!$return) { return false; } } return true; }
/** * Finds the Rule model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Rule the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Rule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function toBattle() { $user = $this->getUser(); $o = new Battle(); $o->user_id = $user->id; $o->env_id = $user->env_id; $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null; $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null; $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null; $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null; $o->level = $this->level ? (int) $this->level : null; $o->level_after = $this->level_after ? (int) $this->level_after : null; $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null; $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null; $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null; $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null; $o->cash = (string) $this->cash != '' ? (int) $this->cash : null; $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null; $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null); $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null; $o->kill = (string) $this->kill != '' ? (int) $this->kill : null; $o->death = (string) $this->death != '' ? (int) $this->death : null; $o->gender_id = $this->gender === 'boy' ? 1 : ($this->gender === 'girl' ? 2 : null); $o->fest_title_id = $this->fest_title ? FestTitle::findOne(['key' => $this->fest_title])->id : null; $o->fest_title_after_id = $this->fest_title_after ? FestTitle::findOne(['key' => $this->fest_title_after])->id : null; $o->fest_exp = (string) $this->fest_exp != '' ? (int) $this->fest_exp : null; $o->fest_exp_after = (string) $this->fest_exp_after != '' ? (int) $this->fest_exp_after : null; $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null; $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null; $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null; $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null; $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null; $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now(); $o->agent_id = null; $o->ua_custom = (string) $this->agent_custom == '' ? null : (string) $this->agent_custom; $o->at = new Now(); $o->is_automated = $this->automated === 'yes'; $o->my_point = (string) $this->my_point != '' ? (int) $this->my_point : null; $o->my_team_final_point = (string) $this->my_team_final_point != '' ? (int) $this->my_team_final_point : null; $o->his_team_final_point = (string) $this->his_team_final_point != '' ? (int) $this->his_team_final_point : null; $o->my_team_final_percent = (string) $this->my_team_final_percent != '' ? sprintf('%.1f', (double) $this->my_team_final_percent) : null; $o->his_team_final_percent = (string) $this->his_team_final_percent != '' ? sprintf('%.1f', (double) $this->his_team_final_percent) : null; $o->is_knock_out = $this->knock_out === 'yes' ? true : ($this->knock_out === 'no' ? false : null); $o->my_team_count = (string) $this->my_team_count != '' ? (int) $this->my_team_count : null; $o->his_team_count = (string) $this->his_team_count != '' ? (int) $this->his_team_count : null; $o->events = null; if ($this->events) { $o->events = json_encode($this->events, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } if ($this->gears) { $o->headgear_id = $this->processGear('headgear'); $o->clothing_id = $this->processGear('clothing'); $o->shoes_id = $this->processGear('shoes'); } if ($this->isTest) { $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); $o->id = 0; foreach ($o->attributes as $k => $v) { if ($v instanceof Now) { $o->{$k} = gmdate('Y-m-d H:i:sP', $now); } } } return $o; }
public function toBattle() { $o = new Battle(); $o->user_id = $this->getUser()->id; $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null; $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null; $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null; $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null; $o->level = $this->level ? (int) $this->level : null; $o->level_after = $this->level_after ? (int) $this->level_after : null; $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null; $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null; $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null; $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null; $o->cash = (string) $this->cash != '' ? (int) $this->cash : null; $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null; $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null); $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null; $o->kill = (string) $this->kill != '' ? (int) $this->kill : null; $o->death = (string) $this->death != '' ? (int) $this->death : null; $o->gender_id = $this->fest_gender === 'boy' ? 1 : ($this->fest_gender === 'girl' ? 2 : null); $o->fest_title_id = $this->fest_rank ? FestTitle::findOne(['key' => $this->fest_rank])->id : null; $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null; $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null; $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null; $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null; $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null; $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now(); $o->agent_id = null; $o->at = new Now(); return $o; }