@@ -245,9 +245,9 @@ private function get_new_dxcc($locations, $start_date, $end_date, $prev_month_en
245245 private function get_new_dxcc_by_band ($ locations , $ start_date , $ end_date , $ prev_month_end ) {
246246 $ new_dxcc_by_band = array ();
247247
248- // Get all bands worked this month
248+ // Get all bands worked this month, plus propagation mode to separate SAT/EME
249249 $ this ->db ->distinct ();
250- $ this ->db ->select ('COL_BAND ' );
250+ $ this ->db ->select ('COL_BAND, COL_PROP_MODE ' );
251251 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
252252 $ this ->db ->where_in ('station_id ' , $ locations );
253253 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
@@ -260,9 +260,22 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
260260
261261 foreach ($ bands_query ->result () as $ band_row ) {
262262 $ band = $ band_row ->COL_BAND ;
263- $ new_dxcc_by_band [ $ band ] = array () ;
263+ $ prop_mode = $ band_row -> COL_PROP_MODE ;
264264
265- // Get all unique DXCC entities worked on this band this month (group by DXCC, get earliest callsign)
265+ // Group SAT and EME separately, not by frequency band
266+ if ($ prop_mode == 'SAT ' ) {
267+ $ band_key = 'Satellite ' ;
268+ } elseif ($ prop_mode == 'EME ' ) {
269+ $ band_key = 'EME ' ;
270+ } else {
271+ $ band_key = $ band ;
272+ }
273+
274+ if (!isset ($ new_dxcc_by_band [$ band_key ])) {
275+ $ new_dxcc_by_band [$ band_key ] = array ();
276+ }
277+
278+ // Get all unique DXCC entities worked on this band/prop this month (group by DXCC, get earliest callsign)
266279 $ this ->db ->select ('COL_DXCC, MAX(COL_COUNTRY) as COL_COUNTRY, MIN(COL_TIME_ON) as FIRST_QSO ' , FALSE );
267280 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
268281 $ this ->db ->where_in ('station_id ' , $ locations );
@@ -271,30 +284,49 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
271284 $ this ->db ->where ('COL_BAND ' , $ band );
272285 $ this ->db ->where ('COL_DXCC IS NOT NULL ' );
273286 $ this ->db ->where ('COL_DXCC != ' , '' );
287+
288+ // Filter by propagation mode
289+ if ($ prop_mode ) {
290+ $ this ->db ->where ('COL_PROP_MODE ' , $ prop_mode );
291+ } else {
292+ // For terrestrial, exclude SAT and EME
293+ $ this ->db ->where ('(COL_PROP_MODE IS NULL OR (COL_PROP_MODE != "SAT" AND COL_PROP_MODE != "EME")) ' , NULL , FALSE );
294+ }
295+
274296 $ this ->db ->group_by ('COL_DXCC ' );
275297
276298 $ query = $ this ->db ->get ();
277299
278300 foreach ($ query ->result () as $ row ) {
279- // Check if this DXCC was worked before this month on this band
301+ // Check if this DXCC was worked before this month on this band/prop
280302 $ this ->db ->select ('COUNT(*) as count ' );
281303 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
282304 $ this ->db ->where_in ('station_id ' , $ locations );
283305 $ this ->db ->where ('COL_DXCC ' , $ row ->COL_DXCC );
284306 $ this ->db ->where ('COL_BAND ' , $ band );
307+ if ($ prop_mode ) {
308+ $ this ->db ->where ('COL_PROP_MODE ' , $ prop_mode );
309+ } else {
310+ $ this ->db ->where ('(COL_PROP_MODE IS NULL OR (COL_PROP_MODE != "SAT" AND COL_PROP_MODE != "EME")) ' , NULL , FALSE );
311+ }
285312 $ this ->db ->where ('COL_TIME_ON < ' , $ start_date );
286313
287314 $ prev_query = $ this ->db ->get ();
288315 $ prev_row = $ prev_query ->row ();
289316
290- // If not worked before on this band, it's new
317+ // If not worked before on this band/prop , it's new
291318 if ($ prev_row ->count == 0 ) {
292- // Get the callsign and mode from the first QSO with this DXCC on this band
319+ // Get the callsign and mode from the first QSO with this DXCC on this band/prop
293320 $ this ->db ->select ('COL_CALL, COL_MODE, COL_SUBMODE ' );
294321 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
295322 $ this ->db ->where_in ('station_id ' , $ locations );
296323 $ this ->db ->where ('COL_DXCC ' , $ row ->COL_DXCC );
297324 $ this ->db ->where ('COL_BAND ' , $ band );
325+ if ($ prop_mode ) {
326+ $ this ->db ->where ('COL_PROP_MODE ' , $ prop_mode );
327+ } else {
328+ $ this ->db ->where ('(COL_PROP_MODE IS NULL OR (COL_PROP_MODE != "SAT" AND COL_PROP_MODE != "EME")) ' , NULL , FALSE );
329+ }
298330 $ this ->db ->where ('COL_TIME_ON ' , $ row ->FIRST_QSO );
299331 $ this ->db ->limit (1 );
300332
@@ -306,12 +338,23 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
306338 $ mode = !empty ($ call_row ->COL_SUBMODE ) ? $ call_row ->COL_SUBMODE : $ call_row ->COL_MODE ;
307339 }
308340
309- $ new_dxcc_by_band [$ band ][] = array (
310- 'dxcc_id ' => $ row ->COL_DXCC ,
311- 'name ' => $ row ->COL_COUNTRY ,
312- 'callsign ' => $ call_row ? $ call_row ->COL_CALL : '' ,
313- 'mode ' => $ mode
314- );
341+ // Avoid duplicates in the same band_key
342+ $ already_added = false ;
343+ foreach ($ new_dxcc_by_band [$ band_key ] as $ existing ) {
344+ if ($ existing ['dxcc_id ' ] == $ row ->COL_DXCC ) {
345+ $ already_added = true ;
346+ break ;
347+ }
348+ }
349+
350+ if (!$ already_added ) {
351+ $ new_dxcc_by_band [$ band_key ][] = array (
352+ 'dxcc_id ' => $ row ->COL_DXCC ,
353+ 'name ' => $ row ->COL_COUNTRY ,
354+ 'callsign ' => $ call_row ? $ call_row ->COL_CALL : '' ,
355+ 'mode ' => $ mode
356+ );
357+ }
315358 }
316359 }
317360 }
@@ -333,8 +376,8 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
333376 private function get_new_dxcc_by_prop ($ locations , $ start_date , $ end_date , $ prev_month_end , $ prop_mode ) {
334377 $ new_dxcc = array ();
335378
336- // Get all unique DXCC entities worked this month via this prop mode (group by DXCC)
337- $ this ->db ->select ('COL_DXCC, MAX(COL_COUNTRY) as COL_COUNTRY ' , FALSE );
379+ // Get all unique DXCC entities worked this month via this prop mode (group by DXCC, get earliest time )
380+ $ this ->db ->select ('COL_DXCC, MAX(COL_COUNTRY) as COL_COUNTRY, MIN(COL_TIME_ON) as FIRST_QSO ' , FALSE );
338381 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
339382 $ this ->db ->where_in ('station_id ' , $ locations );
340383 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
@@ -360,9 +403,28 @@ private function get_new_dxcc_by_prop($locations, $start_date, $end_date, $prev_
360403
361404 // If not worked before via this prop mode, it's new
362405 if ($ prev_row ->count == 0 ) {
406+ // Get the callsign and mode from the first QSO
407+ $ this ->db ->select ('COL_CALL, COL_MODE, COL_SUBMODE ' );
408+ $ this ->db ->from ($ this ->config ->item ('table_name ' ));
409+ $ this ->db ->where_in ('station_id ' , $ locations );
410+ $ this ->db ->where ('COL_DXCC ' , $ row ->COL_DXCC );
411+ $ this ->db ->where ('COL_PROP_MODE ' , $ prop_mode );
412+ $ this ->db ->where ('COL_TIME_ON ' , $ row ->FIRST_QSO );
413+ $ this ->db ->limit (1 );
414+
415+ $ call_query = $ this ->db ->get ();
416+ $ call_row = $ call_query ->row ();
417+
418+ $ mode = '' ;
419+ if ($ call_row ) {
420+ $ mode = !empty ($ call_row ->COL_SUBMODE ) ? $ call_row ->COL_SUBMODE : $ call_row ->COL_MODE ;
421+ }
422+
363423 $ new_dxcc [] = array (
364424 'dxcc_id ' => $ row ->COL_DXCC ,
365- 'name ' => $ row ->COL_COUNTRY
425+ 'name ' => $ row ->COL_COUNTRY ,
426+ 'callsign ' => $ call_row ? $ call_row ->COL_CALL : '' ,
427+ 'mode ' => $ mode
366428 );
367429 }
368430 }
0 commit comments