Example #1
0
 public static function getSchedule()
 {
     $currentPeriod = \app\components\helpers\Battle::calcPeriod(@$_SERVER['REQUEST_TIME'] ?: time());
     $ret = (object) ['current' => (object) ['t' => \app\components\helpers\Battle::periodToRange($currentPeriod), 'regular' => [], 'gachi' => []], 'next' => (object) ['t' => \app\components\helpers\Battle::periodToRange($currentPeriod + 1), 'regular' => [], 'gachi' => []]];
     $list = static::findByModeAndPeriod(['regular', 'gachi'], [$currentPeriod, $currentPeriod + 1])->all();
     foreach ($list as $o) {
         $key = $o->period == $currentPeriod ? 'current' : 'next';
         $ret->{$key}->{$o->rule->mode->key}[] = $o;
     }
     return $ret;
 }
Example #2
0
 private function mapUpdateGachi()
 {
     echo "gachi...\n";
     $gameMode = GameMode::findOne(['key' => 'gachi']);
     $latestPeriod = $this->getLatestPeriod($gameMode);
     $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/gachi/next_all' : 'http://splapi.retrorocket.biz/gachi')->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 = $this->getRuleTable($gameMode);
     $insert = [];
     foreach ($json as $item) {
         if (!isset($rule[$item->rule])) {
             echo "Unknown rule name: {$item->rule}\n";
             continue;
         }
         foreach ($item->maps as $mapName) {
             if (isset($map[$mapName])) {
                 $insert[] = [$item->period, $rule[$item->rule], $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 function filterByTerm($query, $value, array $options = [])
 {
     $now = @$_SERVER['REQUEST_TIME'] ?: time();
     $currentPeriod = \app\components\helpers\Battle::calcPeriod($now);
     switch ($value) {
         case 'this-period':
             $query->andWhere(['{{battle}}.[[period]]' => $currentPeriod]);
             break;
         case 'last-period':
             $query->andWhere(['{{battle}}.[[period]]' => $currentPeriod - 1]);
             break;
         case '24h':
             $query->andWhere(['>=', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $now - 86400)]);
             break;
         case 'today':
             $t = mktime(0, 0, 0, date('n', $now), date('j', $now), date('Y', $now));
             $query->andWhere(['>=', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $t)]);
             break;
         case 'yesterday':
             // 昨日の 00:00:00
             $t1 = mktime(0, 0, 0, date('n', $now), date('j', $now) - 1, date('Y', $now));
             // 今日の 00:00:00
             $t2 = mktime(0, 0, 0, date('n', $now), date('j', $now), date('Y', $now));
             $query->andWhere(['>=', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $t1)]);
             $query->andWhere(['<', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $t2)]);
             break;
         case 'term':
             if (isset($options['from']) && $options['from'] != '') {
                 if ($t = @strtotime($options['from'])) {
                     $query->andWhere(['>=', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $t)]);
                 }
             }
             if (isset($options['to']) && $options['to'] != '') {
                 if ($t = @strtotime($options['to'])) {
                     $query->andWhere(['<=', '{{battle}}.[[at]]', gmdate('Y-m-d\\TH:i:sP', $t)]);
                 }
             }
             break;
     }
     return $this;
 }
Example #4
0
 public function setPeriod()
 {
     // 開始時間があれば開始時間から15秒(適当)引いた値を使うを使う。
     // 終了時間があれば終了時間から3分30秒(適当)引いた値を仕方ないので使う。
     // どっちもなければ登録時間から3分45秒(適当)引いた値を仕方ないので使う。
     $onSale = strtotime('2015-05-28 00:00:00+09:00');
     $now = (int) (@$_SERVER['REQUEST_TIME'] ?: time());
     $time = false;
     if ($time === false && is_string($this->start_at) && trim($this->start_at) !== '') {
         if (($t = strtotime($this->start_at)) !== false && $t >= $onSale && $t <= $now) {
             $time = $t - 15;
         }
     }
     if ($time === false && is_string($this->end_at) && trim($this->end_at) !== '') {
         if (($t = strtotime($this->end_at)) !== false && $t >= $onSale && $t <= $now) {
             $time = $t - (180 + 30);
         }
     }
     if ($time === false && is_string($this->at) && trim($this->at) !== '') {
         if (($t = strtotime($this->at)) !== false && $t >= $onSale && $t <= $now) {
             $time = $t - (180 + 45);
         }
     }
     if ($time === false) {
         $time = $now;
     }
     $this->period = \app\components\helpers\Battle::calcPeriod($time);
 }
 public function toPermLink($formName = false)
 {
     if ($formName === false) {
         $formName = $this->formName();
     }
     $ret = [];
     $push = function ($key, $value) use($formName, &$ret) {
         if ($formName != '') {
             $key = sprintf('%s[%s]', $formName, $key);
         }
         $ret[$key] = $value;
     };
     foreach (['lobby', 'rule', 'map', 'weapon', 'result'] as $key) {
         $value = $this->{$key};
         if ((string) $value !== '') {
             $push($key, $value);
         }
     }
     $now = @$_SERVER['REQUEST_TIME'] ?: time();
     switch ($this->term) {
         case 'this-period':
             $t = BattleHelper::periodToRange(BattleHelper::calcPeriod($now), 180);
             $push('term', 'term');
             $push('term_from', date('Y-m-d H:i:s', $t[0]));
             $push('term_to', date('Y-m-d H:i:s', $t[1] - 1));
             break;
         case 'last-period':
             $t = BattleHelper::periodToRange(BattleHelper::calcPeriod($now - 14400), 180);
             $push('term', 'term');
             $push('term_from', date('Y-m-d H:i:s', $t[0]));
             $push('term_to', date('Y-m-d H:i:s', $t[1] - 1));
             break;
         case '24h':
             $push('term', 'term');
             $push('term_from', date('Y-m-d H:i:s', $now - 86400));
             $push('term_to', date('Y-m-d H:i:s', $now));
             break;
         case 'today':
             $push('term', 'term');
             $push('term_from', date('Y-m-d 00:00:00', $now));
             $push('term_to', date('Y-m-d 23:59:59', $now));
             break;
         case 'yesterday':
             $t = mktime(12, 0, 0, date('n', $now), date('j', $now) - 1, date('Y', $now));
             $push('term', 'term');
             $push('term_from', date('Y-m-d 00:00:00', $t));
             $push('term_to', date('Y-m-d 23:59:59', $t));
             break;
         case 'term':
             $push('term', 'term');
             $push('term_from', date('Y-m-d H:i:s', strtotime($this->term_from)));
             $push('term_to', date('Y-m-d H:i:s', strtotime($this->term_to)));
             break;
     }
     return $ret;
 }
Example #6
0
 public function getPeriodId()
 {
     // 開始時間があれば開始時間から5秒(適当)引いた値を使うを使う。
     // 終了時間があれば終了時間から3分15秒(適当)引いた値を仕方ないので使う。
     // どっちもなければ登録時間から3分30秒(適当)引いた値を仕方ないので使う。
     if ($this->start_at) {
         $time = strtotime($this->start_at) - 5;
     } elseif ($this->end_at) {
         $time = strtotime($this->end_at) - (180 + 15);
     } else {
         $time = strtotime($this->at) - (180 + 30);
     }
     return \app\components\helpers\Battle::calcPeriod($time);
 }