示例#1
0
 function make_table(league_table $data)
 {
     $pilots = 2000;
     if ($data->options->official) {
         $pilots = 4;
     }
     $pilots_array = new table_array();
     /** @var \object\flight $flight */
     foreach ($data->flights as $flight) {
         if (isset($pilots_array[$flight->ClassID . '.' . $flight->c_name])) {
             $pilots_array[$flight->ClassID . '.' . $flight->c_name]->add_flight($flight);
         } else {
             /** @var pilot $pilot */
             $pilot = new $data->class();
             $pilot->set_from_flight($flight, $data->max_flights, false);
             $pilots_array[$flight->ClassID . '.' . $flight->c_name] = $pilot;
         }
     }
     // Sort pilots by score.
     if ($pilots_array->count()) {
         $pilots_array->uasort(['\\module\\tables\\object\\league_table', 'cmp']);
     } else {
         return node::create('table.main thead tr th.c', ['style' => 'width:663px'], 'No Flights to display');
     }
     $club_array = new table_array();
     $pilots_array->iterate(function (scorable $pilot) use($data, $pilots, $club_array) {
         /** @var club $club */
         if ($pilot->club) {
             if (isset($club_array[$pilot->club])) {
                 $club = $club_array[$pilot->club];
                 $club->AddSub($pilot);
             } else {
                 $club = new $data->SClass();
                 $club->set_from_pilot($pilot, $pilots);
                 $club_array[$pilot->club] = $club;
             }
         }
     });
     $club_array->uasort(['\\module\\tables\\object\\league_table', 'cmp']);
     $html = node::create('div.table_wrapper', [], node::create('h3.heading', [], $data->Title) . $club_array->iterate_return(function (club $club, $i) use($data) {
         return node::create('div.table_wrapper.inner', [], $club->writeClubSemiHead($i + 1) . node::create('table.results.main.flights_' . $data->max_flights, [], $data->write_table_header($data->max_flights, $data->class_primary_key) . $club->content));
     }));
     return $html;
 }
示例#2
0
 public function get_color_at_value($value)
 {
     if (count($this->color) == 0) {
         return '';
     }
     for ($i = 0; $i < count($this->color); $i++) {
         $currC = $this->color[$i];
         if ($value < $currC->val) {
             $prevC = $this->color[max(0, $i - 1)];
             $valueDiff = $prevC->val - $currC->val;
             $fractBetween = $valueDiff == 0 ? 0 : ($value - $currC->val) / $valueDiff;
             $red = ($prevC->r - $currC->r) * $fractBetween + $currC->r;
             $green = ($prevC->g - $currC->g) * $fractBetween + $currC->g;
             $blue = ($prevC->b - $currC->b) * $fractBetween + $currC->b;
             return $this->to_hex($red, $green, $blue);
         }
     }
     $red = $this->color->last()->r;
     $green = $this->color->last()->g;
     $blue = $this->color->last()->b;
     return $this->to_hex($red, $green, $blue);
 }
示例#3
0
 /**
  * @param table_array $elements
  * @param string      $class
  *
  * @return node
  */
 public function get_table_rows($elements, $class = '')
 {
     $nodes = node::create('tbody');
     $keys = $this->allowed_keys;
     /**
      * @var \classes\table $obj
      * @return string
      */
     return $elements->iterate_return(function (table $obj) use($nodes, $keys, $class) {
         if ($obj->_has_child && in_array($obj->get_primary_key(), $keys)) {
             $obj->_is_expanded = true;
             $children = $this->get_elements($obj->get_primary_key());
         } else {
             $obj->_is_expanded = false;
             $children = false;
         }
         return node::create('tr#' . get::__class_name($obj) . $obj->get_primary_key() . ($obj->deleted ? '.danger.deleted' : '') . $class . '.vertical-align', [], $obj->get_cms_list()) . ($children ? $this->get_table_rows($children, '.active') : '');
     });
 }
示例#4
0
 public function generate_csv()
 {
     $flights = flight::get_all(['p.pid AS p_pid', 'p.name AS p_name', 'c.title AS c_title', 'g.class AS g_class', 'g.name AS g_name', 'score', 'defined', 'lid'], ['join' => ['glider g' => 'flight.gid=g.gid', 'pilot p' => 'p.pid = flight.pid', 'club c' => 'c.cid=flight.cid'], 'where' => '`delayed`=0 AND personal=0 AND score>10 AND season = 2012']);
     $array = new table_array();
     $flights->iterate(function (flight $flight) use(&$array) {
         if (isset($array[$flight->p_pid])) {
             $array[$flight->p_pid]->add_flight($flight);
         } else {
             $array[$flight->p_pid] = new pilot_official();
             $array[$flight->p_pid]->set_from_flight($flight, 6, 0);
             $array[$flight->p_pid]->output_function = 'csv';
         }
     });
     $array->uasort(['\\module\\tables\\object\\league_table', 'cmp']);
     $class1 = $class5 = 1;
     echo node::create('pre', [], '
     Pos ,Name ,Glider ,Club ,Best ,Second ,Third ,Forth ,Fifth ,Sixth ,Total' . "\n" . $array->iterate_return(function (scorable $pilot) use(&$class1, &$class5) {
         if ($pilot->class == 1) {
             $class1++;
             return $pilot->output($class1);
         } else {
             $class5++;
             return $pilot->output($class5);
         }
     }));
     die;
 }
示例#5
0
 public static function get_all(array $fields, array $options = [])
 {
     $array = new _table_array();
     $array->get_all(get_called_class(), $fields, $options);
     return $array;
 }