Esempio n. 1
0
 public function do_submit()
 {
     $flight = new flight();
     $flight->set_from_request();
     $flight->dim = 1;
     if (strtotime($this->date) + 30 * 24 * 60 * 60 < time()) {
         $this->force_delay = true;
         $flight->admin_info .= 'delayed as flight is old.';
     }
     $track = new track();
     $task = $track->set_task($this->coords);
     $flight_type = new flight_type();
     $flight_type->do_retrieve(['ftid', 'multi', 'multi_defined'], ['where_equals' => ['fn' => $task->type]]);
     $flight->ftid = $flight_type->ftid;
     $flight->set_date($this->date);
     $flight->multi = !$this->ridge ? flight_type::get_multiplier($flight->ftid, $flight->season, $this->defined) : 1;
     $flight->base_score = $task->get_distance();
     $flight->coords = $this->coords;
     $flight->score = $flight->base_score * $flight->multi;
     $flight->delayed = $this->force_delay ? true : $this->delay;
     $flight->do_save();
     jquery::colorbox(['html' => 'Your flight has been added successfully', 'className' => 'success']);
     $form = new coordinates_form();
     ajax::update($form->get_html()->get());
 }
Esempio n. 2
0
 /**
  * @param $type
  * @return mixed
  */
 public static function get_type($type)
 {
     if (!isset(self::$all_rows)) {
         self::$all_rows = flight_type::get_all([]);
     }
     foreach (self::$all_rows as $flight_type) {
         if ($flight_type->ftid == $type) {
             return $flight_type->title;
         }
     }
     return '';
 }
Esempio n. 3
0
 static function flight_type($int)
 {
     if (!isset(self::$flight_type)) {
         $types = flight_type::get_all(['ftid', 'title']);
         $types->iterate(function (flight_type $type) {
             self::$flight_type[$type->ftid] = $type->title;
         });
     }
     if (isset(self::$flight_type[$int])) {
         return self::$flight_type[$int];
     }
     return false;
 }
Esempio n. 4
0
 function make_table(league_table $data)
 {
     $html = '';
     for ($i = 1; $i < 5; $i++) {
         $where = $data->where . ' AND ftid=' . $i;
         $flights = flight::get_all(['fid', 'flight.pid', 'flight.gid', $data->class_table_alias . '.' . $data->class_primary_key . ' AS ClassID', $data->class_table_alias . '.name AS p_name', $data->S_alias . '.title AS c_name', 'g.class AS class', 'g.name AS g_name', 'coords', 'g.mid', 'g.kingpost', 'did', 'defined', 'lid', 'multi', 'ftid', $data->ScoreType . ' AS score'], ['join' => ["glider g" => "flight.gid=g.gid", "club c" => "flight.cid=c.cid", "pilot p" => "flight.pid=p.pid", 'manufacturer gm' => 'g.mid = gm.mid'], 'where' => $where, 'order' => 'score DESC', 'limit' => 10, 'parameters' => $data->parameters]);
         if ($flights) {
             $html .= node::create('div.table_wrapper', [], node::create('h3.heading', [], flight_type::get_type($i) . ' - ' . $data->year_title) . node::create('table.main.results', [], node::create('thead tr', [], node::create('th', ['style' => 'width:20px'], 'Pos') . node::create('th', ['style' => 'width:100px'], $data->class_table_alias == 'p' ? 'Name' : 'Glider') . node::create('th', ['style' => 'width:70px'], $data->class_table_alias == 'p' ? 'Club' : 'Manufacturer') . ($data->class_table_alias == 'p' ? node::create('th', ['style' => 'width:100px'], 'Glider') : '') . node::create('th', ['style' => 'width:58px'], 'Score') . node::create('th', ['style' => 'width:300px'], 'Flight Waypoints')) . $flights->iterate_return(function (flight $flight, $count) use(&$html, $data) {
                 $count++;
                 return node::create('tr', [], node::create('td', [], $count) . node::create('td', [], $flight->p_name) . node::create('td', [], $flight->c_name) . ($data->class_table_alias == 'p' ? node::create('td', [], $flight->g_name) : '') . $flight->to_print() . node::create('td', [], $flight->coords));
             })));
         }
     }
     return $html;
 }
Esempio n. 5
0
 private function get_defined_task_select_html(igc_parser $parser)
 {
     if ($task = $parser->get_task('declared')) {
         $multiplier = flight_type::get_multiplier($task->type, date('Y'), true);
         return node::create('tr', [], [node::create('td', [], $task->title), node::create('td', [], number_format($task->distance, 3) . ' / ' . number_format($multiplier, 2)), node::create('td', [], number_format($task->distance * $multiplier, 3)), $parser->is_task_completed() ? node::create('td a.button.score_select', ['data-post' => '{"track":' . $parser->id . ',"type":"task"}'], 'Choose') : node::create('td span.button.score_select', [], 'Not Valid')]);
     }
     return '';
 }
Esempio n. 6
0
 public function do_submit()
 {
     $flight = new flight();
     $flight->set_from_request();
     $flight->live = false;
     $flight->do_save();
     if ($flight->fid) {
         $flight->move_temp_files($this->temp_id);
         $igc_parser = new igc_parser();
         $igc_parser->load_data($flight->fid, false);
         $flight->did = $igc_parser->has_height_data() ? 3 : 2;
         $flight->winter = $igc_parser->is_winter();
         $flight->set_date(strtotime($igc_parser->get_date()));
         $this->force_delay = false;
         if (!$this->check_date($igc_parser)) {
             $this->force_delay = true;
             $flight->admin_info .= 'delayed as flight is old.' . "\n";
         }
         if ($igc_parser->get_validated() === 0) {
             $flight->admin_info .= 'G record invalid.' . "\n";
         }
         $flight->defined = $this->type == 'task';
         $flight->duration = $igc_parser->get_duration();
         foreach (['od' => 'open_distance', 'or' => 'out_and_return', 'tr' => 'triangle', 'ft' => 'flat_triangle'] as $task_id => $name) {
             if ($task = $igc_parser->get_task($name)) {
                 $flight->{$task_id . '_score'} = $task->get_distance();
                 $flight->{$task_id . '_time'} = $task->get_duration();
                 $flight->{$task_id . '_coordinates'} = $task->get_gridref();
                 if ($this->type == $task->type) {
                     $flight->ftid = $this->type;
                     $flight->base_score = $task->get_distance();
                     $flight->duration = $task->get_duration();
                     $flight->coords = $task->get_gridref();
                 }
             }
         }
         if ($flight->defined) {
             $task = $igc_parser->get_task('declared');
             $flight->ftid = $task->type;
             if ($flight->ftid == \track\task::TYPE_OPEN_DISTANCE) {
                 $flight->ftid = \track\task::TYPE_GOAL;
             }
             $flight->base_score = $task->get_distance();
             $flight->duration = $task->get_duration();
             $flight->coords = $task->get_gridref();
         }
         $flight->multi = !$flight->ridge ? flight_type::get_multiplier($flight->ftid, $igc_parser->get_date('Y'), $flight->defined) : 1;
         $flight->score = $flight->multi * $flight->base_score;
         $flight->delayed = $this->force_delay || $this->delay;
         $flight->live = true;
         $flight->do_save();
         jquery::colorbox(['html' => 'Your flight has been added successfully', 'className' => 'success']);
         $form = new igc_form();
         ajax::update($form->get_html()->get());
         $users = new_flight_notification::get_all([]);
         foreach ($users as $user) {
             $mail = new email();
             $mail->load_template(root . '/template/email/basic.html');
             $mail->set_recipients([$user->email]);
             $subject = 'New flight added';
             if ($flight->delayed) {
                 $subject .= ' - Delayed';
             }
             if ($igc_parser->get_validated() === 0) {
                 $subject .= ' - G record invalid';
             }
             $mail->set_subject($subject);
             $mail->replacements = ['[content]' => '
                     <h2>New flight added: ' . $flight->get_primary_key() . '</h2>
                     <table class="btn-primary" cellpadding="0" cellspacing="0" border="0">
                         <tr>
                             <td>
                                 <a href="' . host . '/cms/edit/2/' . $flight->get_primary_key() . '">View in CMS</a>
                             </td>
                         </tr>
                     </table>'];
             $mail->send();
         }
     } else {
         jquery::colorbox(['html' => 'Your flight has failed to save', 'className' => 'success failure']);
     }
 }