Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 /**
  * Build flight and place registration in it. Create flight if necessary.
  * @return flight_id updated or created
  */
 private function makeFlight($flight_str, $competition)
 {
     $competition_date = substr($competition->start_date, 0, 10);
     $flight_arr = explode('-', $flight_str->id);
     // flight-123
     $flight = Flight::findOne($flight_arr[1]);
     if (!$flight) {
         // need to create it
         $flight = new Flight();
     } else {
         // remove existings
         $flight->cleanRegistrations();
     }
     $flight->position = $flight_str->position;
     Yii::trace($competition_date . ' ' . $flight_str->start_time . ':00', 'FlightController::makeFlight');
     $flight->start_time = $competition_date . ' ' . $flight_str->start_time . ':00';
     $flight->save();
     // add currents
     if ($competition->isTeamCompetition()) {
         foreach ($flight_str->registrations as $registration_str) {
             $registration_arr = explode('-', $registration_str);
             // registration-456
             $team = Team::findOne($registration_arr[1]);
             if ($team) {
                 foreach ($team->getRegistrations()->each() as $registration) {
                     $registration->flight_id = $flight->id;
                     $registration->save();
                 }
             }
         }
     } else {
         foreach ($flight_str->registrations as $registration_str) {
             $registration_arr = explode('-', $registration_str);
             // registration-456
             $registration = Registration::findOne($registration_arr[1]);
             if ($registration) {
                 $registration->flight_id = $flight->id;
                 $registration->save();
             }
         }
     }
     return $flight->id;
 }