/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TeamCoach::find();
     $teamCoachTable = TeamCoach::tableName();
     $coachTable = Coach::tableName();
     $teamTable = Team::tableName();
     $seasonTable = Season::tableName();
     $query->joinWith(['coach' => function ($query) use($coachTable) {
         $query->from(['coach' => $coachTable]);
     }]);
     $query->joinWith(['team' => function ($query) use($teamTable) {
         $query->from(['team' => $teamTable]);
     }]);
     $query->joinWith(['season' => function ($query) use($seasonTable) {
         $query->from(['season' => $seasonTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $addSortAttributes = ["coach.name", "team.name", "season.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$teamCoachTable}.id" => $this->id, 'team_id' => $this->team_id, 'season_id' => $this->season_id, 'coach_id' => $this->coach_id, 'is_main' => $this->is_main]);
     $query->andFilterWhere(['like', 'coach.name', $this->getAttribute('coach.name')])->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')])->andFilterWhere(['like', 'season.name', $this->getAttribute('season.name')]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Coach::find();
     $country = new Country();
     $coachTable = Coach::tableName();
     $countryTable = Country::tableName();
     $query->joinWith(['country' => function ($query) use($countryTable) {
         $query->from(['country' => $countryTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["country.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$coachTable}.id" => $this->id, 'birthday' => $this->birthday, 'country_id' => $this->country_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', "{$coachTable}.name", $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'notes', $this->notes])->andFilterWhere(['like', 'player_carrer', $this->player_carrer])->andFilterWhere(['like', 'coach_carrer', $this->coach_carrer])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'country.name', $this->getAttribute('country.name')]);
     return $dataProvider;
 }
 /**
  * Finds the Coach model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Coach the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Coach::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
<div class="team-coach-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'team_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Team::find()->where(['id' => Team::getTeamsConstants()])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите команду...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'season_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Season::find()->where(['window' => Season::WINDOW_WINTER])->orderBy(['name' => SORT_DESC])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите сезон...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'coach_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Coach::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите тренера...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
// $availableCoaches = [];
// $coach = $model->coach;
// if(isset($coach->id)) {
//     $availableCoaches = [$coach->id => $coach->name];
// }
// echo $form->field($model, 'coach_id')->widget(SelectizeDropDownList::classname(), [
//     'loadUrl' => Url::to(['coach/coach-list']),
//     'items' => $availableCoaches,
//     'options' => [
//         'multiple' => false,
//         'placeholder' => 'Выберите тренера...',
//     ],
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCoach()
 {
     return $this->hasOne(Coach::className(), ['id' => 'coach_id']);
 }
 /**
  * Url: /coach/{$id}-{$slug}
  * @param int $id Player id
  * @param $slug
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionCoach($id, $slug)
 {
     $coach = Coach::findOne($id);
     if (!isset($coach)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $image = $coach->getAsset(Asset::THUMBNAIL_CONTENT);
     $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $coach->name, 'columnFirst' => ['post' => ['view' => '@frontend/views/site/coach', 'data' => compact('coach', 'image'), 'weight' => 0]], 'columnSecond' => ['blog_column' => SiteBlock::getBlogPosts(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]];
     return $this->render('@frontend/views/site/index', $options);
 }