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()); }
protected function get_flight_defined($ftid, $class, $gender) { $flight = new flight(); $flight->do_retrieve(['fid', 'p.name AS p_name', 'base_score', 'date', 'speed'], ['join' => ['pilot p' => 'p.pid = flight.pid', 'glider g' => 'g.gid = flight.gid'], 'where_equals' => ['ftid' => $ftid, 'g.class' => $class, 'p.gender' => $gender], 'order' => 'speed DESC']); $html = ''; if ($flight->fid) { $html .= node::create('tr', [], node::create('td', [], 'Speed') . node::create('td', [], $class) . node::create('td', [], $gender) . node::create('td', [], $flight->p_name) . node::create('td', [], number_format($flight->speed, 2)) . node::create('td', [], date('d/m/Y', $flight->date))); } return $html; }
public function get_latest_flights() { $flights = flight::get_all(['fid', 'date', 'pilot.pid', 'pilot.name', 'glider.gid', 'glider.name', 'club.cid', 'club.title', 'admin_info', 'delayed'], ['join' => flight::$default_joins, 'limit' => 14, 'order' => 'fid DESC']); $table = node::create('table#latest_flights.module.table.table-striped', [], node::create('thead', [], node::create('th', [], 'ID') . node::create('th', [], 'Date Added') . node::create('th', [], 'Pilot') . node::create('th', [], 'Glider') . node::create('th', [], 'Club') . node::create('th', [], 'Admin Notes') . node::create('th', [], 'Delayed')) . $flights->iterate_return(function (flight $flight) { return node::create('tr', [], node::create('td a', ['href' => '/cms/module/2/' . $flight->fid, 'title' => 'Flight: ' . $flight->fid], $flight->fid) . node::create('td a', ['href' => '/cms/module/2/' . $flight->fid, 'title' => 'Flight: ' . $flight->fid], date('d/m/Y', $flight->date)) . node::create('td a', ['href' => '/cms/module/3/' . $flight->pilot->pid, 'title' => 'Pilot: ' . $flight->pilot->name], $flight->pilot->name) . node::create('td a', ['href' => '/cms/module/4/' . $flight->glider->gid, 'title' => 'Glider: ' . $flight->glider->name], $flight->glider->name) . node::create('td a', ['href' => '/cms/module/12/' . $flight->club->cid, 'title' => 'Club: ' . $flight->club->name], $flight->club->name) . node::create('td.col-md-5', [], $flight->admin_info) . node::create('td', [], $flight->delayed ? 'Yes' : 'No')); })); return $table; }
public function get_view() { $flights = flight::get_all(['flight.*', 'pilot.name', 'pilot.pid'], ['join' => ['pilot' => 'flight.pid = pilot.pid'], 'where' => '`delayed` = 0 AND personal = 0', 'limit' => 40, 'order' => 'fid DESC']); $wrapper = node::create('h1.page-header', [], 'Latest') . node::create('div.table_wrapper', [], node::create('table.results.main', [], node::create('thead', [], node::create('tr', [], node::create('th', [], 'ID') . node::create('th', [], 'Pilot') . node::create('th', [], 'Date Flown') . node::create('th', [], 'Date Added') . node::create('th', [], 'Score') . node::create('th', [], 'Flight Waypoints'))) . node::create('tbody', [], $flights->iterate_return(function (flight $flight) use(&$body) { $added = substr($flight->created, 0, 10); return node::create('tr', [], node::create('td', [], $flight->fid) . node::create('td', [], $flight->pilot->name) . node::create('td', [], date('Y-m-d', $flight->date)) . node::create('td', [], $added != '0000-00-00' ? $added : 'Unknown') . $flight->to_print() . node::create('td', [], $flight->coords)); })))); return $wrapper; }
public function get_template_data() { $root = root . '/uploads/comp/' . $this->module->current->get_primary_key(); $files = glob($root . '/*.igc'); $flights = []; foreach ($files as $file) { $name = str_replace($root, '', $file); $name = str_replace('.igc', '', $name); $name = preg_replace('/[0-9.\\-_\\/]/', ' ', $name); $name = preg_replace('/\\s+/', ' ', $name); $name = trim($name); $pilot = new pilot(); $parts = explode(' ', $name); $match = false; if ($pilot->do_retrieve([], ['where_equals' => ['name' => $name]]) || $pilot->do_retrieve([], ['where_equals' => ['name' => implode(' ', array_reverse($parts))]])) { $flight = new flight(); $match = $flight->do_retrieve([], ['where_equals' => ['pid' => $pilot->get_primary_key(), 'date' => date('Y-m-d', $this->module->current->date)]]); } $flights[] = ['data' => ['path' => $file, 'name' => $name, 'cid' => $this->module->current->get_primary_key()], 'name' => $name, 'matched' => $match]; } return ['rows' => $flights]; }
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; }
/** * Generates a sub table showing the top flights in each category. * * @param string $where - a complete sql WHERE clause * @param array $params * * @return string */ function ShowTop4($where, $params = []) { $html = ''; $launch_by_number = [1 => 'Foot', 2 => 'Aerotow', 3 => 'Winch']; $where['delayed'] = '`delayed`=:delayed'; $params['delayed'] = 0; $where['personal'] = 'personal=:personal'; $params['personal'] = 0; foreach ($launch_by_number as $j => $val) { $where_extend = implode(' AND ', $where); $where_extend .= ' AND lid=:lid'; $params['lid'] = $j; $html .= '<tr><td>' . $val . '</td>'; for ($i = 1; $i < 5; $i++) { $where_extend .= ' AND ftid=:ftid'; $params['ftid'] = $i; $flight = new flight(); $flight->do_retrieve(['flight.*', $this->class . '.name AS name', 'glider.class AS class'], ['join' => flight::$default_joins, 'where' => $where_extend, 'order' => 'score DESC', 'parameters' => $params]); if (isset($flight->fid) && $flight->fid) { $prefix = $flight->name . ' (' . ($flight->class == 5 ? 'R' : 'F') . ') '; $html .= $flight->to_print($prefix)->get(); } else { $html .= node::create('td', [], 'No Flights Fit'); } } $html .= '</tr>'; } return node::create('table.top4.main.results', [], node::create('thead', [], node::create('tr', [], node::create('th', ['style' => 'width:52px'], 'Category') . node::create('th', ['style' => 'width:155px;color:black'], 'Open Dist') . node::create('th', ['style' => 'width:155px;color:green'], 'Out & Return') . node::create('th', ['style' => 'width:155px;color:red'], 'Goal') . node::create('th', ['style' => 'width:155px;color:blue'], 'Triangle'))) . $html); }
public function add_flight() { $this->do_retrieve_from_id([], $_REQUEST['cid']); $coords = json_decode($this->coords); $form = new igc_upload_form(); $form->file = $_REQUEST['path']; $form->coords = implode(';', array_map(function ($coord) { $point = new lat_lng($coord->lat, $coord->lon); return geometry::lat_long_to_os($point); }, $coords)); $form->do_submit(); $form = new igc_form(); $form->vis_info = 'Flown in comp: ' . $this->type . ' Round ' . $this->round . ' Task ' . $this->task; $pilot = new pilot(); $parts = explode(' ', $_REQUEST['name']); if ($pilot->do_retrieve([], ['where_equals' => ['name' => $_REQUEST['name']]]) || $pilot->do_retrieve([], ['where_equals' => ['name' => implode(' ', array_reverse($parts))]])) { $form->pid = $pilot->get_primary_key(); $flight = new flight(); if ($flight->do_retrieve([], ['where_equals' => ['pid' => $pilot->get_primary_key()], 'order' => 'date DESC'])) { $form->gid = $flight->gid; $form->cid = $flight->cid; } } ajax::update(node::create('div#second_form', [], $form->get_html())); }
public function get_stats() { return flight::get_statistics(); }
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']); } }