/** * Displays all matches and a possibility to register or not. * @return mixed Match view */ public function actionIndex() { $registrationSearchModel = new RegistrationSearch(); $registrationDataProvider = $registrationSearchModel->search(Yii::$app->request->queryParams); if (!($golfer = Golfer::me())) { throw new NotFoundHttpException('You are not a golfer.'); } $registrationDataProvider->query->andWhere(['golfer_id' => $golfer->id]); $now = date('Y-m-d H:i:s'); // single matches (not part of a tournament) $matchesSearchModel = new MatchSearch(); $matchesDataProvider = $matchesSearchModel->search(Yii::$app->request->queryParams); $matchesDataProvider->query->andWhere(['parent_id' => null])->andWhere(['>', 'start_date', $now]); // single tournaments not part of a season /* select c.id as tournament_id, count(c.id) as tot_count from competition c, competition m where c.competition_type = 'TOURNAMENT' and m.competition_type = 'MATCH' and m.parent_id = c.id and c.status = 'OPEN' group by c.id having tot_count = 1 */ $q = new Query(); $q->select(['c.id as competition_id', 'count(c.id) as tot_count'])->from('competition c, competition m')->andWhere(['c.parent_id' => null])->andWhere(['c.competition_type' => Competition::TYPE_TOURNAMENT])->andWhere(['m.competition_type' => Competition::TYPE_MATCH])->andWhere('m.parent_id = c.id')->andWhere(['c.status' => Competition::STATUS_OPEN])->andWhere(['m.status' => Competition::STATUS_OPEN])->andWhere(['>', 'm.start_date', $now])->groupBy('c.id'); $tournament_ids = []; foreach ($q->each() as $tournament) { $tournament_ids[] = $tournament['competition_id']; } $tournamentsSearchModel = new TournamentSearch(); $tournamentsDataProvider = $tournamentsSearchModel->search(Yii::$app->request->queryParams); $tournamentsDataProvider->query->andWhere(['id' => $tournament_ids]); // seasons $seasonsSearchModel = new SeasonSearch(); $seasonsDataProvider = $seasonsSearchModel->search(Yii::$app->request->queryParams); $seasonsDataProvider->query->andWhere(['status' => Competition::STATUS_OPEN]); return $this->render('index', ['registrationSearchModel' => $registrationSearchModel, 'registrationDataProvider' => $registrationDataProvider, 'matchesSearchModel' => $matchesSearchModel, 'matchesDataProvider' => $matchesDataProvider, 'tournamentsSearchModel' => $tournamentsSearchModel, 'tournamentsDataProvider' => $tournamentsDataProvider, 'seasonsSearchModel' => $seasonsSearchModel, 'seasonsDataProvider' => $seasonsDataProvider]); }
<div class="competition-view"> <?php echo DetailView::widget(['model' => $model, 'panel' => ['heading' => '<h3>' . Yii::t('igolf', $model->competition_type) . ' ' . $model->name . '</h3>'], 'labelColOptions' => ['style' => 'width: 30%'], 'attributes' => ['name', 'description', ['attribute' => 'parent_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => $model->getParentCandidates(), 'label' => Yii::t('igolf', 'Parent'), 'value' => $model->parent ? $model->parent->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['view', 'id' => $model->parent_id]) : '', 'visible' => $model->competition_type != Competition::TYPE_SEASON, 'format' => 'raw'], ['attribute' => 'course_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'label' => Yii::t('igolf', 'Course'), 'items' => Course::getCourseList(true), 'value' => $model->course ? $model->course->getFullName() . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['course/view', 'id' => $model->course_id]) : '', 'format' => 'raw'], ['attribute' => 'holes', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => array(18 => '18', 9 => '9')], ['attribute' => 'rule_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(['' => ''] + Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name'), 'value' => $model->rule->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['rule/view', 'id' => $model->rule_id]), 'format' => 'raw'], ['attribute' => 'final_rule_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(['' => ''] + Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name'), 'value' => $model->final_rule_id ? $model->finalRule->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['rule/view', 'id' => $model->final_rule_id]) : '', 'format' => 'raw'], ['attribute' => 'start_date', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_begin ? new DateTime($model->start_date) : ''], ['attribute' => 'recurrence', 'format' => 'raw', 'type' => DetailView::INPUT_TEXT, 'value' => $recurrence], ['attribute' => 'registration_begin', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_begin ? new DateTime($model->registration_begin) : ''], ['attribute' => 'registration_end', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_end ? new DateTime($model->registration_end) : ''], 'handicap_min', 'handicap_max', 'age_min', 'age_max', ['attribute' => 'gender', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ['' => ''] + Competition::getLocalizedConstants('GENDER_')], 'max_players', ['attribute' => 'registration_special', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ['' => ''] + Competition::getLocalizedConstants('SPECIAL_')], 'registration_time', 'flight_size', 'flight_time', ['attribute' => 'status', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Competition::getLocalizedConstants('STATUS_')]]]); ?> <?php if (in_array($model->competition_type, [Competition::TYPE_SEASON, Competition::TYPE_TOURNAMENT])) { switch ($model->competition_type) { case Competition::TYPE_SEASON: $searchModel = new TournamentSearch(); $dataProvider = $searchModel->search(['TournamentSearch' => ['parent_id' => $model->id]]); $type = Competition::TYPE_TOURNAMENT; break; case Competition::TYPE_TOURNAMENT: $searchModel = new MatchSearch(); $dataProvider = $searchModel->search(['MatchSearch' => ['parent_id' => $model->id]]); $type = Competition::TYPE_MATCH; break; } echo $this->render('_list', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'parent' => $model, 'type' => $type]); } $startSearchModel = new StartSearch(); $startDataProvider = $startSearchModel->search(['StartSearch' => ['competition_id' => $model->id]]); if ($model->course) { echo $this->render('../start/_list', ['searchModel' => $startSearchModel, 'dataProvider' => $startDataProvider, 'competition' => $model]); } ?> </div>