コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Transfer::find();
     $transferTable = Transfer::tableName();
     // set up query with relation to `player.lastname`
     $playerTable = Player::tableName();
     // set up query with relation to `teamFrom.name` and `teamTo.name`
     $teamTable = Team::tableName();
     $query->joinWith(['player' => function ($query) use($playerTable) {
         $query->from(['player' => $playerTable]);
     }]);
     $query->joinWith(['teamFrom' => function ($query) use($teamTable) {
         $query->from(['teamFrom' => $teamTable]);
     }]);
     $query->joinWith(['teamTo' => function ($query) use($teamTable) {
         $query->from(['teamTo' => $teamTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     // enable sorting for the related columns
     $addSortAttributes = ["player.lastname", "teamFrom.name", "teamTo.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(["{$transferTable}.id" => $this->id, 'season_id' => $this->season_id, 'transfer_type_id' => $this->transfer_type_id, 'player_id' => $this->player_id, 'probability' => $this->probability, 'command_from_id' => $this->command_from_id, 'command_to_id' => $this->command_to_id, 'is_active' => $this->is_active, 'contract_date' => $this->contract_date, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'sum', $this->sum])->andFilterWhere(['like', 'clubs', $this->clubs])->andFilterWhere(['like', 'others', $this->others])->andFilterWhere(['like', 'teamFrom.name', $this->getAttribute('teamFrom.name')])->andFilterWhere(['like', 'teamTo.name', $this->getAttribute('teamTo.name')])->andFilterWhere(['like', 'player.lastname', $this->getAttribute('player.lastname')]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Url: /transfers
  * @return mixed
  */
 public function actionTransfers()
 {
     // transfer type select
     $transferTypes = TransferType::find()->orderBy(['id' => SORT_DESC])->all();
     $activeTransferType = 'all-types';
     if (isset($_GET['transfer-type'])) {
         foreach ($transferTypes as $transferType) {
             if ($_GET['transfer-type'] == $transferType->id) {
                 $activeTransferType = $_GET['transfer-type'];
             }
         }
     }
     $transferTypesData = ['all-types' => ['value' => 'all-types', 'text' => 'Все трансферы', 'active' => false]];
     foreach ($transferTypes as $transferType) {
         $transferTypesData[$transferType->id] = ['value' => $transferType->id, 'text' => $transferType->name, 'active' => false];
     }
     $transferTypesData[$activeTransferType]['active'] = true;
     foreach ($transferTypesData as $key => $transferType) {
         $transferTypesData[$key] = (object) $transferType;
     }
     // season select
     $seasons = Season::find()->innerJoinWith('transfers')->orderBy(['id' => SORT_DESC])->all();
     $firstSeasonObj = array_values($seasons)[0];
     $firstSeasonId = $firstSeasonObj->id;
     $activeSeason = $firstSeasonId;
     if (isset($_GET['season'])) {
         foreach ($seasons as $season) {
             if ($_GET['season'] == $season->id) {
                 $activeSeason = $_GET['season'];
             }
         }
     }
     $seasonsData = [];
     foreach ($seasons as $season) {
         $seasonName = $season->name;
         if ($season->window == $season::WINDOW_WINTER) {
             $seasonName .= ' Зимнее окно';
         } else {
             $seasonName .= ' Летнее окно';
         }
         $seasonsData[$season->id] = ['value' => $season->id, 'text' => $seasonName, 'active' => false];
     }
     $seasonsData[$activeSeason]['active'] = true;
     foreach ($seasonsData as $key => $season) {
         $seasonsData[$key] = (object) $season;
     }
     // transfers tables
     $transferQuery = Transfer::find()->where(['season_id' => $activeSeason])->orderBy(['created_at' => SORT_ASC]);
     if ($activeTransferType != 'all-types') {
         $transferQuery->andWhere(['transfer_type_id' => $activeTransferType]);
     }
     $transfers = $transferQuery->all();
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Трансферы', 'columnFirst' => ['transfers' => ['view' => '@frontend/views/transfers/transfers', 'data' => compact('transferTypesData', 'seasonsData', 'transfers')]], 'columnSecond' => ['short_news' => SiteBlock::getShortNews()]]);
 }