Ejemplo n.º 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++;
     }
 }
Ejemplo n.º 2
0
 public function execute($competition)
 {
     $flight_size = $competition->flight_size ? $competition->flight_size : Competition::FLIGHT_SIZE_DEFAULT;
     $flight_interval = $competition->flight_time ? $competition->flight_time : Competition::FLIGHT_TIME_DEFAULT;
     $flight_time = strtotime("-" . $flight_interval . " minutes", strtotime($competition->start_date));
     Yii::trace('Flight size=' . $flight_size, 'BuildFlightChrono::execute');
     $count = $flight_size;
     $position = 1;
     $registrations = $competition->getRegistrations()->andWhere(['status' => Registration::STATUS_REGISTERED])->orderBy('created_at');
     foreach ($registrations->each() as $registration) {
         if ($count >= $flight_size) {
             $flight_time = strtotime("+" . $flight_interval . " minutes", strtotime($flight_time));
             $count = 0;
             $flight = new Flight();
             $flight->position = $position++;
             $flight->start_time = $flight_time;
             $flight->start_hole = $competition->start_hole;
             $flight->save();
             $flight->refresh();
         }
         Yii::trace('doing=' . $registration->id . '=' . $flight->id . ' at=' . $flight_time, 'BuildFlightChrono::execute');
         $registration->flight_id = $flight->id;
         $registration->save();
         $count++;
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Flight::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'competition_id' => $this->competition_id, 'position' => $this->position]);
     $query->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Ejemplo n.º 4
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;
     foreach ($registrations->each() as $registration) {
         if ($count >= $flight_size) {
             $count = 0;
             $flight = new Flight();
             $flight->position = $position++;
             $flight->save();
         }
         $registration->flight_id = $flight->id;
         $registration->save();
         $count++;
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns competition flights, if any
  *
  * @return \yii\db\ActiveQuery
  */
 public function getFlights()
 {
     return $this->hasMany(Flight::className(), ['id' => 'flight_id'])->viaTable('registration', ['competition_id' => 'id']);
 }
Ejemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFlight()
 {
     return $this->hasOne(Flight::className(), ['id' => 'flight_id']);
 }
Ejemplo n.º 7
0
 /**
  * Finds the Flight model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Flight the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Flight::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }