示例#1
0
 public static function addFlights($competition, $registrations)
 {
     $flight_size = $competition->flight_size ? $competition->flight_size : Competition::FLIGHT_SIZE_DEFAULT;
     $position = Flight::find()->andWhere(['competition_id' => $competition->id])->max('position');
     if (!intval($position) > 0) {
         $position = 0;
     }
     $position++;
     $count = $flight_size;
     // we collect the teams for which we don't have a registration yet
     $team_ids = [];
     foreach ($registrations->each() as $registration) {
         $team_ids[$registration->team_id] = $registration->team_id;
     }
     foreach (Team::find()->andWhere(['id' => $team_ids])->each() as $team) {
         if ($count >= $flight_size) {
             $count = 0;
             $flight = new Flight();
             $flight->position = $position++;
             $flight->save();
             $flight->refresh();
         }
         foreach ($team->getRegistrations()->each() as $registration) {
             $registration->flight_id = $flight->id;
             $registration->save();
         }
         $count++;
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Team::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_date' => $this->created_date, 'updated_date' => $this->updated_date]);
     $query->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'name_en', $this->name_en])->andFilterWhere(['like', 'name_ru', $this->name_ru])->andFilterWhere(['like', 'name_am', $this->name_am])->andFilterWhere(['like', 'sname_en', $this->sname_en])->andFilterWhere(['like', 'sname_ru', $this->sname_ru])->andFilterWhere(['like', 'sname_am', $this->sname_am])->andFilterWhere(['like', 'position_en', $this->position_en])->andFilterWhere(['like', 'position_ru', $this->position_ru])->andFilterWhere(['like', 'position_am', $this->position_am]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Team::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, 'event_id' => $this->event_id]);
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'contact', $this->contact]);
     return $dataProvider;
 }
示例#4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TeamModel::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'added_by_id' => $this->added_by_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'logo', $this->logo]);
     return $dataProvider;
 }
示例#5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $teamTable = Team::tableName();
     // set up query with relation to `country.name`
     $countryTable = Country::tableName();
     $query = Team::find();
     $query->joinWith(['country' => function ($query) use($countryTable) {
         $query->from(['country' => $countryTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
     // 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(["{$teamTable}.id" => $this->id, 'country_id' => $this->country_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', "{$teamTable}.name", $this->name])->andFilterWhere(['like', 'country.name', $this->getAttribute('country.name')])->andFilterWhere(['like', 'info', $this->info]);
     return $dataProvider;
 }
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $dp = new ActiveDataProvider(['query' => Team::find()->where(['event_id' => Yii::$app->params['currentEvent']]), 'pagination' => false]);
     return $this->render('index', ['teams' => $dp]);
 }
示例#7
0
 public function actionTeam()
 {
     $team = Team::find()->all();
     return $this->render('team', ['team' => $team]);
 }
 /**
  * Displays a single Event model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $event = $this->findModel($id);
     $dp = new ActiveDataProvider(['query' => Team::find()->where(['event_id' => $id])->addOrderBy('name asc'), 'pagination' => false]);
     return $this->render('view', ['model' => $event, 'dataProvider' => $dp]);
 }
示例#9
0
use common\models\Season;
use common\models\Team;
use common\models\Coach;
/* @var $this yii\web\View */
/* @var $model common\models\TeamCoach */
/* @var $form yii\widgets\ActiveForm */
?>

<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];