/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Countries::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'country', $this->country]); return $dataProvider; }
/* @var $model app\models\tournaments\tournaments */ /* @var $form yii\widgets\ActiveForm */ ?> <div class = "row"> <div class="col-xs-8 col-sm-6 col-md-4 col-lg-3"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'tournament_name', [])->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'country', ['template' => '{label} <div class="row"><div class="col-xs-10">{input}{error}{hint}</div></div>'])->dropDownList(ArrayHelper::map(Countries::find()->orderBy('country', 'asc')->all(), 'id', 'country'), ['prompt' => '---Выберите страну---']); ?> <?php echo $form->field($model, 'num_tours', ['template' => '{label} <div class="row"><div class="col-xs-5 col-sm-3">{input}{error}{hint}</div></div>'])->textInput(); ?> <?php echo $form->field($model, 'startsOn', ['template' => '{label} <div class="row"><div class="col-xs-12 col-sm-8">{input}{error}{hint}</div></div>'])->widget(DatePicker::className(), ['removeButton' => false, 'pluginOptions' => ['autoclose' => true, 'format' => 'dd.mm.yyyy', 'todayHighlight' => true], 'options' => ['value' => isset($model->startsOn) ? date('d.m.Y', $model->startsOn) : '']]); ?> <?php echo $form->field($model, 'wfDueTo', ['template' => '{label} <div class="row"><div class="col-xs-12 col-sm-8">{input}{error}{hint}</div></div>'])->widget(DatePicker::className(), ['removeButton' => false, 'pluginOptions' => ['autoclose' => true, 'format' => 'dd.mm.yyyy', 'todayHighlight' => true], 'options' => ['value' => isset($model->wfDueTo) ? date('d.m.Y', $model->wfDueTo) : '']]); ?> <?php
public static function getCountriesArray() { $countries = Countries::find()->orderBy(['country' => SORT_ASC])->asArray()->all(); return ArrayHelper::map($countries, 'id', 'country'); }
<div class="col-xs-12 col-xs-offset-0 col-sm-offset-1 col-sm-10 tournaments-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create', ['modelClass' => 'Tournaments']), ['create'], ['class' => 'btn btn-success']); ?> </p> <div class="row"> <?php echo extendedGridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'col-xs-12 col-md-10 col-lg-8'], 'columns' => [['attribute' => 'id_tournament', 'filter' => false, 'options' => ['class' => 'col-xs-1'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center']], ['attribute' => 'tournament_name', 'filter' => false, 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-3'], 'content' => function ($model) { return Html::a($model->tournament_name, ['tournaments/update', 'id' => $model->id_tournament]); }, 'format' => 'url'], ['header' => 'Игры', 'filter' => false, 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-2'], 'content' => function ($model) { return Html::a('Игры турнира', ['games/index', 'tournament' => $model->id_tournament]); }, 'format' => 'url'], ['attribute' => 'country', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'content' => function ($model) { return Html::a($model->country0->country, ["countries/update", 'id' => $model->country]); }, 'format' => 'url', 'filter' => ArrayHelper::map(Countries::find()->orderBy('country', 'asc')->all(), 'id', 'country'), 'filterInputOptions' => ['class' => 'form-control'], 'options' => ['class' => 'col-xs-2']], ['attribute' => 'num_tours', 'filter' => false, 'header' => 'Туры', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1']], ['attribute' => 'is_active', 'content' => function ($model) { return $model->status; }, 'options' => ['class' => 'col-xs-2'], 'headerOptions' => ['style' => 'text-align:center'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'filter' => ['0' => 'Не начался', '1' => 'Проходит', '2' => 'Закончен']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'options' => ['class' => 'hidden-xs'], 'headerOptions' => ['style' => 'text-align:center'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle']]]]); ?> </div> </div> </div>
/** * @return \yii\db\ActiveQuery */ public function getCountry0() { return $this->hasOne(\app\models\countries\Countries::className(), ['id' => 'country']); }
public static function getFinishedTournamentsOnePerCountry() { $countries = Countries::find()->select('id')->column(); $query = []; foreach ($countries as $country) { $query[] = self::find()->where(['country' => $country])->andWhere(['is_active' => self::FINISHED])->orderBy(['startsOn' => SORT_DESC])->limit(1); } if (!empty($query)) { $toExecute = $query[0]; $i = 1; while (isset($query[$i])) { $toExecute = $toExecute->union($query[$i]); $i++; } $tournaments = $toExecute->column(); } else { $tournaments = []; } if (!empty($tournaments)) { return self::unionQueryPrep($tournaments); } else { return UsersTournaments::find()->findModel(NULL, NULL)->all(); } }
/* @var $model app\models\teams\teams */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="row"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'class' => 'col-xs-8 col-sm-6 col-md-4 col-lg-3']]); ?> <?php echo $form->field($model, 'team_name')->textInput(['maxlength' => 50]); ?> <?php echo $form->field($model, 'country')->dropDownList(ArrayHelper::map(Countries::find()->orderBy('country', 'asc')->all(), 'id', 'country'), ['prompt' => '---Выберите страну---']); ?> <?php if ($model->isNewRecord) { echo $form->field($model, 'team_logo')->label('Логотип')->fileInput(); } else { ?> <div class = 'form-group field-teams-team_logo'> <label class="control-label" for="logo">Логотип</label> <?php echo Html::img($model->fileUrl, ['id' => 'logo', 'width' => 100]); ?> </div>
/** * Finds the countries model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return countries the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Countries::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="row"> <div class="col-xs-12 col-xs-offset-0 col-sm-offset-1 col-sm-10 teams-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create', ['modelClass' => 'Teams']), ['create'], ['class' => 'btn btn-success']); ?> </p> <div class="row"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pager' => ['firstPageLabel' => Html::icon('fast-backward'), 'prevPageLabel' => Html::icon('backward'), 'nextPageLabel' => Html::icon('forward'), 'lastPageLabel' => Html::icon('fast-forward')], 'options' => ['class' => 'col-xs-12 col-md-10 col-lg-7'], 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1']], ['attribute' => 'id_team', 'options' => ['class' => 'col-xs-1'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center']], ['attribute' => 'team_name', 'options' => ['class' => 'col-xs-4'], 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'value' => function ($model) { return Html::a($model->team_name, ['teams/update', 'id' => $model->id_team]); }, 'format' => 'raw'], ['attribute' => 'country', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'value' => function ($model) { return Html::a($model->country0->country, ['countries/update', 'id' => $model->country]); }, 'format' => 'raw', 'filter' => \app\models\countries\Countries::getCountriesArray(), 'filterInputOptions' => ['class' => 'form-control'], 'options' => ['class' => 'col-xs-3']], ['attribute' => 'team_logo', 'options' => ['class' => 'col-xs-2'], 'headerOptions' => ['style' => 'text-align:center'], 'filter' => false, 'format' => 'raw', 'value' => function ($model) { return Html::img($model->fileUrl, ['height' => '50', 'width' => '50']); }, 'contentOptions' => ['align' => 'center']], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Удалить', 'template' => '{delete}', 'options' => ['class' => 'col-xs-1'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center']]]]); ?> </div> </div> </div>