コード例 #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
ファイル: Team.php プロジェクト: alexsynytskiy/Dynamomania
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransfers()
 {
     return $this->hasMany(Transfer::className(), ['command_to_id' => 'id']);
 }
コード例 #3
0
 /**
  * Finds the Transfer model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Transfer the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Transfer::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Player.php プロジェクト: alexsynytskiy/Dynamomania
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranfers()
 {
     return $this->hasMany(Transfer::className(), ['player_id' => 'id']);
 }
コード例 #5
0
 /**
  * Url: /transfer/{$id}
  * @param int $id Transfer id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionTransfer($id)
 {
     $transfer = Transfer::findOne($id);
     if (!isset($transfer)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Трансферы | ' . $transfer->player->name, 'columnFirst' => ['transfers' => ['view' => '@frontend/views/transfers/transfer_single', 'data' => compact('transfer')], 'comments' => Comment::getCommentsBlock($transfer->id, Comment::COMMENTABLE_TRANSFER)], 'columnSecond' => ['short_news' => SiteBlock::getShortNews(10)]]);
 }