Example #1
0
 private function get_task_select_html(igc_parser $parser, $type, $multi)
 {
     if ($task = $parser->get_task($type)) {
         return node::create('tr', [], [node::create('td', [], $task->title), node::create('td', [], number_format($task->distance, 2) . ' / ' . number_format($multi, 2)), node::create('td', [], number_format($task->distance * $multi, 2)), node::create('td a.button.score_select', ['data-post' => '{"track":' . $parser->id . ',"type":"' . $task->type . '"}'], 'Choose')]);
     }
     return '';
 }
Example #2
0
 /**
  * @param field_file $field
  * @return string
  */
 protected function do_upload_file(field_file $field)
 {
     if ($field->field_name == 'file') {
         if (isset($_FILES[$field->field_name]) && !$_FILES[$field->field_name]['error']) {
             $tmp_name = $_FILES[$field->field_name]['tmp_name'];
             $name = $_FILES[$field->field_name]['name'];
             $ext = pathinfo($name, PATHINFO_EXTENSION);
             if ($ext == 'zip') {
                 $root = root . '/uploads/comp/' . $this->get_primary_key();
                 if (!is_dir($root)) {
                     mkdir($root);
                 }
                 $this->file = str_replace(root, '', $root) . '/comp.zip';
                 $zip = new \ZipArchive();
                 $zip->open(root . $this->file);
                 $zip->extractTo($root . '/');
                 $files = glob($root . '/*.igc');
                 $files = array_map(function ($file) {
                     $exp = explode("/", $file);
                     return ['name' => trim(preg_replace('/[^a-zA-Z ]/', '', substr(end($exp), 0, -3))), 'source' => $file];
                 }, $files);
                 if ($files) {
                     $coords = json_decode($this->coords);
                     $parser = new igc_parser();
                     $parser->exec($this->get_primary_key(), ['type' => 'comp', 'sources' => $files, 'destination' => $root, 'task' => ['type' => 'lat/lng', 'coordinates' => array_map(function ($coord) {
                         return ['lat' => (double) $coord->lat, 'lng' => (double) $coord->lon];
                     }, $coords)]]);
                 }
                 move_uploaded_file($tmp_name, root . $this->file);
                 db::update('comp')->add_value('file', $this->file)->filter_field('cid', $this->cid)->execute();
             }
         }
     } else {
         parent::do_upload_file($field);
     }
 }
Example #3
0
 public function check_date(igc_parser $parser)
 {
     $current_time = time();
     $closure_time = $current_time - 31 * 24 * 60 * 60;
     if (strtotime($parser->get_date()) >= $closure_time && strtotime($parser->get_date()) <= $current_time) {
         return true;
     } else {
         return false;
     }
 }