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 getSplatfestTeams() { return $this->hasMany(SplatfestTeam::className(), ['team_id' => 'id']); }