diff --git a/application/models/Timeline_model.php b/application/models/Timeline_model.php index ed0df9ef9..43316f53f 100644 --- a/application/models/Timeline_model.php +++ b/application/models/Timeline_model.php @@ -26,8 +26,11 @@ class Timeline_model extends CI_Model { public function get_timeline_dxcc($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(date(COL_TIME_ON)) date, prefix, dxcc_entities.name as dxcc_name, end, adif from " - .$this->config->item('table_name'). " thcv + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, prefix, dxcc_entities.name as dxcc_name, end, adif, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY adif ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv join dxcc_entities on thcv.col_dxcc = dxcc_entities.adif where station_id in (" . $location_list . ") and col_dxcc > 0 "; @@ -64,8 +67,9 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " group by col_dxcc - order by date desc"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); return $query->result(); @@ -73,8 +77,11 @@ class Timeline_model extends CI_Model { public function get_timeline_waja($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(date(COL_TIME_ON)) date, col_state from " - .$this->config->item('table_name'). " thcv + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, col_state, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY COL_STATE ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv where station_id in (" . $location_list . ")"; if ($band == 'SAT') { // Left for compatibility reasons @@ -113,8 +120,10 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " group by col_state - order by date desc"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); @@ -123,8 +132,11 @@ class Timeline_model extends CI_Model { public function get_timeline_was($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(date(COL_TIME_ON)) date, col_state from " - .$this->config->item('table_name'). " thcv + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, col_state, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY COL_STATE ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv where station_id in (" . $location_list . ")"; if ($band == 'SAT') { // Left for compatibility reasons @@ -163,8 +175,9 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " group by col_state - order by date desc"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); @@ -173,8 +186,11 @@ class Timeline_model extends CI_Model { public function get_timeline_iota($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(date(COL_TIME_ON)) date, col_iota, name, prefix from " - .$this->config->item('table_name'). " thcv + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, col_iota, name, prefix, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY col_iota ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv join iota on thcv.col_iota = iota.tag where station_id in (" . $location_list . ")"; @@ -212,8 +228,10 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " and col_iota <> '' group by col_iota, name, prefix - order by date desc"; + $sql .= " and col_iota <> ''"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); @@ -222,8 +240,11 @@ class Timeline_model extends CI_Model { public function get_timeline_waz($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(date(COL_TIME_ON)) date, col_cqz from " - .$this->config->item('table_name'). " thcv + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, col_cqz, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY col_cqz ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv where station_id in (" . $location_list . ")"; if ($band == 'SAT') { // Left for compatibility reasons @@ -260,8 +281,10 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " and col_cqz <> '' group by col_cqz - order by date desc"; + $sql .= " and col_cqz <> ''"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); @@ -369,7 +392,8 @@ class Timeline_model extends CI_Model { foreach ($col_gridsquare as $grid) { $timeline[] = array( 'gridsquare' => $grid->gridsquare, - 'date' => $grid->date); + 'date' => $grid->date, + 'sat_name' => $grid->sat_name ?? ''); } $col_vucc_grids = $this->get_vucc_grids($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew); @@ -383,7 +407,8 @@ class Timeline_model extends CI_Model { // Doesn't exist, add new entry $timeline[] = array( 'gridsquare' => $grid_four, - 'date' => $gridSplit->date + 'date' => $gridSplit->date, + 'sat_name' => $gridSplit->sat_name ?? '' ); } else { // Exists, check the date @@ -403,9 +428,12 @@ class Timeline_model extends CI_Model { public function get_gridsquare($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select min(COL_TIME_ON) date, upper(substring(col_gridsquare, 1, 4)) gridsquare from " - .$this->config->item('table_name'). " thcv - where station_id in (" . $location_list . ")"; + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, upper(substring(COL_GRIDSQUARE, 1, 4)) AS gridsquare, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY upper(substring(COL_GRIDSQUARE, 1, 4)) ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv + WHERE station_id IN (" . $location_list . ")"; if ($band == 'SAT') { // Left for compatibility reasons $sql .= " and col_prop_mode = ?"; @@ -440,8 +468,10 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " and col_gridsquare <> '' group by upper(substring(col_gridsquare, 1, 4)) - order by date desc"; + $sql .= " AND COL_GRIDSQUARE <> ''"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); @@ -450,9 +480,12 @@ class Timeline_model extends CI_Model { public function get_vucc_grids($band, $mode, $propmode, $location_list, $qsl, $lotw, $eqsl, $clublog, $year, $qrz, $onlynew) { $binding = []; - $sql = "select COL_TIME_ON as date, upper(col_vucc_grids) gridsquare from " - .$this->config->item('table_name'). " thcv - where station_id in (" . $location_list . ")"; + $sql = "SELECT * FROM ("; + $sql .= "SELECT COL_TIME_ON AS date, upper(COL_VUCC_GRIDS) AS gridsquare, "; + $sql .= "COL_SAT_NAME AS sat_name, "; + $sql .= "ROW_NUMBER() OVER (PARTITION BY upper(COL_VUCC_GRIDS) ORDER BY COL_TIME_ON ASC) AS rn "; + $sql .= "FROM ".$this->config->item('table_name'). " thcv + WHERE station_id IN (" . $location_list . ")"; if ($band == 'SAT') { // Left for compatibility reasons $sql .= " and col_prop_mode = ?"; @@ -487,7 +520,10 @@ class Timeline_model extends CI_Model { $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl, $clublog, $qrz); - $sql .= " and col_vucc_grids <> ''"; + $sql .= " AND COL_VUCC_GRIDS <> ''"; + $sql .= ") ranked "; + $sql .= "WHERE rn = 1 "; + $sql .= "ORDER BY date DESC;"; $query = $this->db->query($sql, $binding); return $query->result(); diff --git a/application/views/timeline/index.php b/application/views/timeline/index.php index 2484a10c3..d36a1d6d7 100644 --- a/application/views/timeline/index.php +++ b/application/views/timeline/index.php @@ -197,8 +197,11 @@ function write_dxcc_timeline($timeline_array, $custom_date_format, $bandselect, # ' . __("Date") . ' ' . __("Prefix") . ' - ' . __("Country") . ' - ' . __("Status") . ' + ' . __("Country") . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' ' . __("Status") . ' ' . __("End Date") . ' ' . __("Show QSOs") . ' @@ -211,8 +214,11 @@ function write_dxcc_timeline($timeline_array, $custom_date_format, $bandselect, ' . $i-- . ' ' . date($custom_date_format, $date_as_timestamp) . ' ' . $line->prefix . ' - ' . ucwords(strtolower($line->dxcc_name)) . ' - '; + ' . ucwords(strtolower($line->dxcc_name)) . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ''.$line->sat_name.''; + } + echo ' '; if (!empty($line->end)) echo '' . __("Deleted DXCC") . ''; echo ' ' . $line->end . ' @@ -234,8 +240,11 @@ function write_waja_timeline($timeline_array, $custom_date_format, $bandselect, # '.__("Date").' - '.__("Prefecture").' - '.__("Show QSOs").' + '.__("Prefecture").''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' '.__("Show QSOs").' '; @@ -246,8 +255,11 @@ function write_waja_timeline($timeline_array, $custom_date_format, $bandselect, echo ' ' . $i-- . ' ' . date($custom_date_format, $date_as_timestamp) . ' - ' . $CI->Waja->jaPrefectures[$line->col_state] . ' ('.$line->col_state.') - col_state . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' + ' . $CI->Waja->jaPrefectures[$line->col_state] . ' ('.$line->col_state.')'; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ''.$line->sat_name.''; + } + echo ' col_state . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' '; } echo ''; @@ -262,8 +274,11 @@ function write_was_timeline($timeline_array, $custom_date_format, $bandselect, $ # ' . __("Date") . ' - ' . __("State") . ' - ' . __("Show QSOs") . ' + ' . __("State") . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' ' . __("Show QSOs") . ' '; @@ -274,8 +289,11 @@ function write_was_timeline($timeline_array, $custom_date_format, $bandselect, $ echo ' ' . $i-- . ' ' . date($custom_date_format, $date_as_timestamp) . ' - ' . $line->col_state . ' - col_state . '","' . $bandselect . '","' . $modeselect . '","' . $propmode . '","' . $award .'")>' . __("Show") . ' + ' . $line->col_state . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo '' . $line->sat_name . ''; + } + echo ' col_state . '","' . $bandselect . '","' . $modeselect . '","' . $propmode . '","' . $award .'")>' . __("Show") . ' '; } echo ''; @@ -294,8 +312,11 @@ function write_iota_timeline($timeline_array, $custom_date_format, $bandselect, '.__("Date").' '.__("IOTA").' '.__("Name").' - '.__("Prefix").' - '.__("Show QSOs").' + '.__("Prefix").''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' '.__("Show QSOs").' '; @@ -308,8 +329,11 @@ function write_iota_timeline($timeline_array, $custom_date_format, $bandselect, ' . date($custom_date_format, $date_as_timestamp) . ' ' . $line->col_iota . ' ' . $line->name . ' - ' . $line->prefix . ' - col_iota . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' + ' . $line->prefix . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo '' . $line->sat_name . ''; + } + echo ' col_iota . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' '; } echo ''; @@ -324,8 +348,11 @@ function write_waz_timeline($timeline_array, $custom_date_format, $bandselect, $ # '.__("Date").' - '.__("CQ Zone").' - '.__("Show QSOs").' + '.__("CQ Zone").''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' '.__("Show QSOs").' '; @@ -336,14 +363,17 @@ function write_waz_timeline($timeline_array, $custom_date_format, $bandselect, $ echo ' ' . $i-- . ' ' . date($custom_date_format, $date_as_timestamp) . ' - ' . $line->col_cqz . ' - col_cqz . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' + ' . $line->col_cqz . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo '' . $line->sat_name . ''; + } + echo ' col_cqz . '","'. $bandselect . '","'. $modeselect. '","' . $propmode . '","' . $award .'")>'.__("Show").' '; } echo ''; } -function write_vucc_timeline($timeline_array, $custom_date_format, $bandselect, $modeselect, $propmode,$award, $selectedyear, $onlynew) { +function write_vucc_timeline($timeline_array, $custom_date_format, $bandselect, $modeselect, $propmode, $award, $selectedyear, $onlynew) { // Apply filtering to the timeline array $filtered_timeline = filter_timeline_array_vucc($timeline_array, $selectedyear, $onlynew); $i = count($filtered_timeline); // General counter for all entries @@ -353,8 +383,11 @@ function write_vucc_timeline($timeline_array, $custom_date_format, $bandselect, # '.__("Date").' '.__("Time").' - '.__("Gridsquare").' - '.__("Show QSOs").' + '.__("Gridsquare").''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ' '.__("Satellite").''; + } + echo ' '.__("Show QSOs").' '; @@ -366,8 +399,11 @@ function write_vucc_timeline($timeline_array, $custom_date_format, $bandselect, ' . $i-- . ' ' . date($custom_date_format, $date_as_timestamp) . ' ' . date('H:i', $date_as_timestamp) . ' - ' . $line['gridsquare'] . ' - '.__("Show").' + ' . $line['gridsquare'] . ''; + if ($propmode == 'SAT' || $propmode == 'All') { + echo ''.$line['sat_name'].''; + } + echo ' '.__("Show").' '; } echo '';