public function actionUpdate($region, $number) { $transaction = Yii::$app->db->beginTransaction(); if (!($region = Region::findOne(['key' => $region]))) { printf("Unknown region: %s\n", $region); return 1; } if (!($fest = Splatfest::findOne(['region_id' => $region->id, '[[order]]' => $number]))) { printf("Unknown number: %s (region = %s)\n", $number, $region->key); return 1; } printf("Target #%d (Region=%s, Number=%d)\n", $fest->id, $region->key, $fest->order); $alpha = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 1]); $bravo = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 2]); if (!$alpha || !$bravo || $alpha->color_hue === null || $bravo->color_hue === null) { printf(" > Team information is not ready\n"); return 1; } printf(" > cleanup ...\n"); SplatfestBattleSummary::deleteAll(['fest_id' => $fest->id]); $this->createBattleSummaryTmpTimestamp($fest); $this->createBattleSummaryTmpTable('tmp_summary_a', $fest, $alpha->color_hue, $bravo->color_hue); $this->createBattleSummaryTmpTable('tmp_summary_b', $fest, $bravo->color_hue, $alpha->color_hue); $this->createBattleSummary($fest); $transaction->commit(); return 0; }
private function doInit() { if (!($form = $this->createAndValidateRequestForm())) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } $this->fest = Splatfest::find()->innerJoinWith('region', false)->andWhere(['{{region}}.[[key]]' => $form->region, '{{splatfest}}.[[order]]' => $form->order])->limit(1)->one(); if (!$this->fest) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } $this->alpha = SplatfestTeam::findOne(['fest_id' => $this->fest->id, 'team_id' => 1]); $this->bravo = SplatfestTeam::findOne(['fest_id' => $this->fest->id, 'team_id' => 2]); if (!$this->alpha || !$this->bravo) { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } }
/** * @return \yii\db\ActiveQuery */ public function getFests() { return $this->hasMany(Splatfest::className(), ['id' => 'fest_id'])->viaTable('splatfest_team', ['team_id' => 'id']); }
private function needUpdateSplatfest() { // データが何もなければ取得が必要 $count = SplatfestMap::find()->innerJoinWith(['splatfest', 'splatfest.region'])->andWhere(['{{region}}.[[key]]' => 'jp'])->count(); if ($count < 1) { return true; } // 今がフェス中でなければ不要 $now = gmdate('Y-m-d\\TH:i:sP', (int) (@$_SERVER['REQUEST_TIME'] ?: time())); $fest = Splatfest::find()->innerJoinWith('region', false)->andWhere(['and', ['{{region}}.[[key]]' => 'jp'], ['<=', '{{splatfest}}.[[start_at]]', $now], ['>', '{{splatfest}}.[[end_at]]', $now]])->one(); if (!$fest) { return false; } // マップ情報をもっていれば不要 $count = SplatfestMap::find()->andWhere(['{{splatfest_map}}.[[splatfest_id]]' => $fest->id])->count(); return $count < 1; }
private function fest($regionId, $festOrder) { $cond = ['region_id' => $regionId, 'order' => $festOrder]; return Splatfest::findOne($cond)->id; }
/** * @return \yii\db\ActiveQuery */ public function getSplatfests() { return $this->hasMany(Splatfest::className(), ['region_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getFest() { return $this->hasOne(Splatfest::className(), ['id' => 'fest_id']); }