/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TransferType::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', 'name', $this->name]);
     return $dataProvider;
 }
Example #2
0
        <?php 
echo Html::a('Добавить трансфер', ['create'], ['class' => 'btn btn-success']);
?>
        <?php 
if (count(Yii::$app->getRequest()->getQueryParams()) > 0) {
    echo Html::a('Сброс', ['/' . Yii::$app->controller->id], ['class' => 'btn btn-primary']);
}
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'options' => ['width' => '80']], ['label' => 'Игрок', 'attribute' => 'player.lastname', 'value' => function ($model) {
    return Html::a($model->player->name, ['/player/' . $model->player->id]);
}, 'format' => 'html'], ['attribute' => 'transfer_type_id', 'value' => function ($model) {
    return $model->transferType->name;
}, 'filter' => ArrayHelper::map(TransferType::find()->all(), 'id', 'name')], ['label' => 'Из команды', 'attribute' => 'teamFrom.name', 'value' => function ($model) {
    if (isset($model->teamFrom)) {
        return Html::a($model->teamFrom->name, ['/team/' . $model->teamFrom->id]);
    } else {
        return null;
    }
}, 'format' => 'html'], ['label' => 'В команду', 'attribute' => 'teamTo.name', 'value' => function ($model) {
    if (isset($model->teamTo)) {
        return Html::a($model->teamTo->name, ['/team/' . $model->teamTo->id]);
    } else {
        return null;
    }
}, 'format' => 'html'], ['attribute' => 'season_id', 'value' => function ($model) {
    return $model->season->name;
}, 'filter' => $seasonFilter, 'options' => ['width' => '120']], 'sum', ['attribute' => 'is_active', 'value' => function ($model) {
    if ($model->is_active) {
 /**
  * Finds the TransferType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TransferType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TransferType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransferType()
 {
     return $this->hasOne(TransferType::className(), ['id' => 'transfer_type_id']);
 }
Example #5
0
    <?php 
$form = ActiveForm::begin();
?>

    <?php 
$availablePlayers = [];
if (!$model->isNewRecord) {
    if (isset($model->player->id)) {
        $availablePlayers = [$model->player->id => $model->player->name];
    }
}
echo $form->field($model, 'player_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['player/player-list']), 'items' => $availablePlayers, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]);
?>

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

    <?php 
$availableTeams = [];
if (!$model->isNewRecord) {
    $team = $model->teamFrom;
    if (isset($team->id)) {
        $availableTeams = [$team->id => $team->name];
    }
}
echo $form->field($model, 'command_from_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['team/team-list']), 'items' => $availableTeams, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]);
?>

    <?php 
$availableTeams = [];
 /**
  * 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()]]);
 }