@@ -201,8 +201,8 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
201201 $ band = $ band_row ->COL_BAND ;
202202 $ new_dxcc_by_band [$ band ] = array ();
203203
204- // Get all unique DXCC entities worked on this band this month (group by DXCC)
205- $ this ->db ->select ('COL_DXCC, MAX(COL_COUNTRY) as COL_COUNTRY ' , FALSE );
204+ // Get all unique DXCC entities worked on this band this month (group by DXCC, get earliest callsign )
205+ $ this ->db ->select ('COL_DXCC, MAX(COL_COUNTRY) as COL_COUNTRY, MIN(COL_TIME_ON) as FIRST_QSO ' , FALSE );
206206 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
207207 $ this ->db ->where_in ('station_id ' , $ locations );
208208 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
@@ -228,9 +228,22 @@ private function get_new_dxcc_by_band($locations, $start_date, $end_date, $prev_
228228
229229 // If not worked before on this band, it's new
230230 if ($ prev_row ->count == 0 ) {
231+ // Get the callsign from the first QSO with this DXCC on this band
232+ $ this ->db ->select ('COL_CALL ' );
233+ $ this ->db ->from ($ this ->config ->item ('table_name ' ));
234+ $ this ->db ->where_in ('station_id ' , $ locations );
235+ $ this ->db ->where ('COL_DXCC ' , $ row ->COL_DXCC );
236+ $ this ->db ->where ('COL_BAND ' , $ band );
237+ $ this ->db ->where ('COL_TIME_ON ' , $ row ->FIRST_QSO );
238+ $ this ->db ->limit (1 );
239+
240+ $ call_query = $ this ->db ->get ();
241+ $ call_row = $ call_query ->row ();
242+
231243 $ new_dxcc_by_band [$ band ][] = array (
232244 'dxcc_id ' => $ row ->COL_DXCC ,
233- 'name ' => $ row ->COL_COUNTRY
245+ 'name ' => $ row ->COL_COUNTRY ,
246+ 'callsign ' => $ call_row ? $ call_row ->COL_CALL : ''
234247 );
235248 }
236249 }
@@ -297,20 +310,23 @@ private function get_new_gridsquares($locations, $start_date, $end_date, $prev_m
297310 $ new_grids = array ();
298311
299312 // Get all gridsquares worked this month (including VUCC grids)
300- $ this ->db ->select ('COL_GRIDSQUARE, COL_VUCC_GRIDS ' );
313+ $ this ->db ->select ('COL_CALL, COL_GRIDSQUARE, COL_VUCC_GRIDS, COL_TIME_ON ' );
301314 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
302315 $ this ->db ->where_in ('station_id ' , $ locations );
303316 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
304317 $ this ->db ->where ('COL_TIME_ON <= ' , $ end_date );
318+ $ this ->db ->order_by ('COL_TIME_ON ' , 'ASC ' );
305319
306320 $ query = $ this ->db ->get ();
307- $ all_grids = array ();
321+ $ grid_callsigns = array ();
308322
309323 foreach ($ query ->result () as $ row ) {
310324 // Process main gridsquare (first 4 characters only)
311325 if (!empty ($ row ->COL_GRIDSQUARE ) && strlen ($ row ->COL_GRIDSQUARE ) >= 4 ) {
312326 $ grid_4char = strtoupper (substr ($ row ->COL_GRIDSQUARE , 0 , 4 ));
313- $ all_grids [$ grid_4char ] = true ;
327+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
328+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
329+ }
314330 }
315331
316332 // Process VUCC grids (comma-separated, first 4 characters only)
@@ -320,16 +336,18 @@ private function get_new_gridsquares($locations, $start_date, $end_date, $prev_m
320336 $ grid = trim ($ grid );
321337 if (strlen ($ grid ) >= 4 ) {
322338 $ grid_4char = strtoupper (substr ($ grid , 0 , 4 ));
323- $ all_grids [$ grid_4char ] = true ;
339+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
340+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
341+ }
324342 }
325343 }
326344 }
327345 }
328346
329347 // Check each grid to see if it's new
330- foreach (array_keys ( $ all_grids ) as $ grid ) {
348+ foreach ($ grid_callsigns as $ grid => $ callsign ) {
331349 if ($ this ->is_grid_new ($ locations , $ grid , $ start_date )) {
332- $ new_grids [] = array ('grid ' => $ grid );
350+ $ new_grids [] = array ('grid ' => $ grid, ' callsign ' => $ callsign );
333351 }
334352 }
335353
@@ -348,21 +366,24 @@ private function get_new_gridsquares_by_prop($locations, $start_date, $end_date,
348366 $ new_grids = array ();
349367
350368 // Get all gridsquares worked this month with this prop mode
351- $ this ->db ->select ('COL_GRIDSQUARE, COL_VUCC_GRIDS ' );
369+ $ this ->db ->select ('COL_CALL, COL_GRIDSQUARE, COL_VUCC_GRIDS, COL_TIME_ON ' );
352370 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
353371 $ this ->db ->where_in ('station_id ' , $ locations );
354372 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
355373 $ this ->db ->where ('COL_TIME_ON <= ' , $ end_date );
356374 $ this ->db ->where ('COL_PROP_MODE ' , $ prop_mode );
375+ $ this ->db ->order_by ('COL_TIME_ON ' , 'ASC ' );
357376
358377 $ query = $ this ->db ->get ();
359- $ all_grids = array ();
378+ $ grid_callsigns = array ();
360379
361380 foreach ($ query ->result () as $ row ) {
362381 // Process main gridsquare (first 4 characters only)
363382 if (!empty ($ row ->COL_GRIDSQUARE ) && strlen ($ row ->COL_GRIDSQUARE ) >= 4 ) {
364383 $ grid_4char = strtoupper (substr ($ row ->COL_GRIDSQUARE , 0 , 4 ));
365- $ all_grids [$ grid_4char ] = true ;
384+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
385+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
386+ }
366387 }
367388
368389 // Process VUCC grids (first 4 characters only)
@@ -372,16 +393,18 @@ private function get_new_gridsquares_by_prop($locations, $start_date, $end_date,
372393 $ grid = trim ($ grid );
373394 if (strlen ($ grid ) >= 4 ) {
374395 $ grid_4char = strtoupper (substr ($ grid , 0 , 4 ));
375- $ all_grids [$ grid_4char ] = true ;
396+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
397+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
398+ }
376399 }
377400 }
378401 }
379402 }
380403
381404 // Check each grid to see if it's new for this prop mode
382- foreach (array_keys ( $ all_grids ) as $ grid ) {
405+ foreach ($ grid_callsigns as $ grid => $ callsign ) {
383406 if ($ this ->is_grid_new_for_prop ($ locations , $ grid , $ start_date , $ prop_mode )) {
384- $ new_grids [] = array ('grid ' => $ grid );
407+ $ new_grids [] = array ('grid ' => $ grid, ' callsign ' => $ callsign );
385408 }
386409 }
387410
@@ -400,21 +423,24 @@ private function get_new_gridsquares_hf($locations, $start_date, $end_date, $pre
400423 $ new_grids = array ();
401424
402425 // Get all gridsquares worked this month via HF
403- $ this ->db ->select ('COL_GRIDSQUARE, COL_VUCC_GRIDS ' );
426+ $ this ->db ->select ('COL_CALL, COL_GRIDSQUARE, COL_VUCC_GRIDS, COL_TIME_ON ' );
404427 $ this ->db ->from ($ this ->config ->item ('table_name ' ));
405428 $ this ->db ->where_in ('station_id ' , $ locations );
406429 $ this ->db ->where ('COL_TIME_ON >= ' , $ start_date );
407430 $ this ->db ->where ('COL_TIME_ON <= ' , $ end_date );
408431 $ this ->db ->where ("(COL_PROP_MODE IS NULL OR COL_PROP_MODE = '' OR COL_PROP_MODE NOT IN ('SAT','EME')) " );
432+ $ this ->db ->order_by ('COL_TIME_ON ' , 'ASC ' );
409433
410434 $ query = $ this ->db ->get ();
411- $ all_grids = array ();
435+ $ grid_callsigns = array ();
412436
413437 foreach ($ query ->result () as $ row ) {
414438 // Process main gridsquare (first 4 characters only)
415439 if (!empty ($ row ->COL_GRIDSQUARE ) && strlen ($ row ->COL_GRIDSQUARE ) >= 4 ) {
416440 $ grid_4char = strtoupper (substr ($ row ->COL_GRIDSQUARE , 0 , 4 ));
417- $ all_grids [$ grid_4char ] = true ;
441+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
442+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
443+ }
418444 }
419445
420446 // Process VUCC grids (first 4 characters only)
@@ -424,16 +450,18 @@ private function get_new_gridsquares_hf($locations, $start_date, $end_date, $pre
424450 $ grid = trim ($ grid );
425451 if (strlen ($ grid ) >= 4 ) {
426452 $ grid_4char = strtoupper (substr ($ grid , 0 , 4 ));
427- $ all_grids [$ grid_4char ] = true ;
453+ if (!isset ($ grid_callsigns [$ grid_4char ])) {
454+ $ grid_callsigns [$ grid_4char ] = $ row ->COL_CALL ;
455+ }
428456 }
429457 }
430458 }
431459 }
432460
433461 // Check each grid to see if it's new for HF
434- foreach (array_keys ( $ all_grids ) as $ grid ) {
462+ foreach ($ grid_callsigns as $ grid => $ callsign ) {
435463 if ($ this ->is_grid_new_for_hf ($ locations , $ grid , $ start_date )) {
436- $ new_grids [] = array ('grid ' => $ grid );
464+ $ new_grids [] = array ('grid ' => $ grid, ' callsign ' => $ callsign );
437465 }
438466 }
439467
0 commit comments