more cameCase to snake_case, defined function types and prefixed private functions with _, removed unused functions from old dxcluster

This commit is contained in:
HB9HIL
2026-02-02 23:07:45 +01:00
parent 4c4d5845e5
commit c0c36a50d4
4 changed files with 30 additions and 138 deletions

View File

@@ -15,7 +15,7 @@ class Dxcluster extends CI_Controller {
}
function spots($band, $age = '', $de = '', $mode = 'All') {
public function spots($band, $age = '', $de = '', $mode = 'All') {
// Sanitize inputs
$band = $this->security->xss_clean($band);
$mode = $this->security->xss_clean($mode);
@@ -52,7 +52,7 @@ class Dxcluster extends CI_Controller {
}
}
function qrg_lookup($qrg) {
public function qrg_lookup($qrg) {
$call_found = $this->dxcluster_model->dxc_qrg_lookup($this->security->xss_clean($qrg));
header('Content-Type: application/json');
if ($call_found) {
@@ -63,7 +63,7 @@ class Dxcluster extends CI_Controller {
}
}
function call($call) {
public function call($call) {
$date = date('Y-m-d', time());
$dxccobj = new Dxcc($date);

View File

@@ -24,14 +24,14 @@ class DxclusterCache {
/**
* Generate RAW spot cache key (instance-wide, shared by all users)
*/
public function getRawCacheKey($maxage, $band) {
public function get_raw_cache_key($maxage, $band) {
return "dxcluster_raw_{$maxage}_{$band}_Any_All";
}
/**
* Generate logbook IDs key component (user-specific)
*/
public function getLogbookKey($user_id, $logbook_ids, $confirmation_prefs) {
public function get_logbook_key($user_id, $logbook_ids, $confirmation_prefs) {
$logbook_ids_str = implode('_', $logbook_ids);
$confirmation_hash = md5($confirmation_prefs);
return "{$user_id}_{$logbook_ids_str}_{$confirmation_hash}";
@@ -66,7 +66,7 @@ class DxclusterCache {
* Invalidate cache after QSO add/edit/delete for current user
* @param string $callsign - The worked callsign
*/
public function invalidateForCallsign($callsign) {
public function invalidate_for_callsign($callsign) {
// Skip if worked cache is disabled
if ($this->CI->config->item('enable_dxcluster_file_cache_worked') !== true) return;
@@ -107,7 +107,7 @@ class DxclusterCache {
if (empty($logbook_ids)) return null;
return $this->getLogbookKey($user_id, $logbook_ids, $confirmation_prefs);
return $this->get_logbook_key($user_id, $logbook_ids, $confirmation_prefs);
}
// =========================================================================

View File

@@ -71,7 +71,7 @@ class Dxcluster_model extends CI_Model {
// Cache key for RAW cluster response (instance-wide, no worked status)
// Use DxclusterCache library for centralized key generation
$raw_cache_key = $this->dxclustercache->getRawCacheKey($maxage, $band);
$raw_cache_key = $this->dxclustercache->get_raw_cache_key($maxage, $band);
// Check cache for raw processed spots (without worked status)
$spotsout = null;
@@ -155,7 +155,7 @@ class Dxcluster_model extends CI_Model {
$singlespot->frequency = floatval($singlespot->frequency);
// Validate against amateur band allocations (skip non-amateur frequencies)
if (!$this->isFrequencyInAmateurBand($singlespot->frequency)) {
if (!$this->_is_frequency_in_amateurband($singlespot->frequency)) {
continue;
}
@@ -168,7 +168,7 @@ class Dxcluster_model extends CI_Model {
// Only determine mode if not provided by cluster
if (!isset($singlespot->mode) || empty($singlespot->mode)) {
$singlespot->mode = $this->get_mode($singlespot);
$singlespot->mode = $this->_get_mode($singlespot);
} else {
// Normalize cluster-provided mode to lowercase
$singlespot->mode = strtolower($singlespot->mode);
@@ -176,7 +176,7 @@ class Dxcluster_model extends CI_Model {
// Only determine submode if not provided by cluster
if (!isset($singlespot->submode) || empty($singlespot->submode)) {
$singlespot->submode = $this->get_submode($singlespot);
$singlespot->submode = $this->_get_submode($singlespot);
} else {
// Normalize cluster-provided submode to uppercase
$singlespot->submode = strtoupper($singlespot->submode);
@@ -232,7 +232,7 @@ class Dxcluster_model extends CI_Model {
}
// Extract park references from message
$singlespot = $this->enrich_spot_metadata($singlespot);
$singlespot = $this->_enrich_spot_metadata($singlespot);
// Collect spots for batch processing
$spotsout[] = $singlespot;
@@ -249,7 +249,7 @@ class Dxcluster_model extends CI_Model {
$de_lower = strtolower($de);
$filter_continent = ($de != '' && $de != 'Any');
$spotsout = array_filter($spotsout, function($spot) use ($mode, $de_lower, $filter_continent) {
if ($mode != 'All' && !$this->modefilter($spot, $mode)) return false;
if ($mode != 'All' && !$this->_modefilter($spot, $mode)) return false;
if ($filter_continent && ($de_lower != strtolower($spot->dxcc_spotter->cont ?? ''))) return false;
return true;
});
@@ -341,13 +341,14 @@ class Dxcluster_model extends CI_Model {
return $spotsout;
} // Determine mode with priority: POTA/SOTA mode > message keywords > frequency-based
function get_mode($spot) {
private function _get_mode($spot) {
// Priority 0: If spot already has a valid mode from cluster, use it
if (isset($spot->mode) && !empty($spot->mode)) {
$existingMode = strtolower($spot->mode);
// Validate it's a known mode category
if (in_array($existingMode, ['cw', 'phone', 'digi', 'ssb'])) {
return $this->mapToModeCategory($existingMode);
return $this->_map_to_mode_category($existingMode);
}
}
@@ -356,10 +357,10 @@ class Dxcluster_model extends CI_Model {
$sotaMode = $spot->sota_mode ?? $spot->dxcc_spotted->sota_mode ?? null;
if (!empty($potaMode)) {
return $this->mapToModeCategory($potaMode);
return $this->_map_to_mode_category($potaMode);
}
if (!empty($sotaMode)) {
return $this->mapToModeCategory($sotaMode);
return $this->_map_to_mode_category($sotaMode);
}
// Priority 2: Message keywords (explicit mode in message text)
@@ -381,7 +382,7 @@ class Dxcluster_model extends CI_Model {
// Priority 3: Frequency-based mode (from bandedges table)
// If frequency falls within a defined band edge, use that mode
$frequencyMode = $this->Frequency2Mode($spot->frequency);
$frequencyMode = $this->_frequency_to_mode($spot->frequency);
if ($frequencyMode != '') {
return $frequencyMode;
}
@@ -391,7 +392,7 @@ class Dxcluster_model extends CI_Model {
}
// Map specific mode names to mode categories (phone/cw/digi)
function mapToModeCategory($mode) {
private function _map_to_mode_category($mode) {
$modeUpper = strtoupper($mode);
// CW modes
@@ -416,7 +417,7 @@ class Dxcluster_model extends CI_Model {
}
// Determine submode for more specific mode classification
function get_submode($spot) {
private function _get_submode($spot) {
// Priority 0: If spot already has a valid submode from cluster, use it
if (isset($spot->submode) && !empty($spot->submode)) {
return strtoupper($spot->submode);
@@ -466,16 +467,16 @@ class Dxcluster_model extends CI_Model {
return strtoupper($mode);
}
function modefilter($spot, $mode) {
private function _modefilter($spot, $mode) {
$mode = strtolower($mode); // Normalize case
$spotMode = strtolower($spot->mode ?? ''); // Get already-determined mode
// Since get_mode() already determined the mode using priority logic
// Since _get_mode() already determined the mode using priority logic
// (frequency > POTA/SOTA > message), we can directly compare
return $spotMode === $mode;
}
public function Frequency2Mode($frequency) {
private function _frequency_to_mode($frequency) {
// Ensure frequency is in Hz if input is in kHz
if ($frequency < 1_000_000) {
$frequency *= 1000;
@@ -489,29 +490,12 @@ class Dxcluster_model extends CI_Model {
return '';
}
public function isFrequencyInMode($frequency, $mode) {
// Ensure frequency is in Hz if input is in kHz
if ($frequency < 1_000_000) {
$frequency *= 1000;
}
foreach ($this->bandedges as $band) {
if (strtolower($band['mode']) === strtolower($mode)) {
if ($frequency >= $band['frequencyfrom'] && $frequency < $band['frequencyto']) {
return true;
}
}
}
return false;
}
/**
* Check if frequency falls within amateur band allocations
* @param float $frequency Frequency in Hz
* @return bool True if frequency is in amateur band
*/
public function isFrequencyInAmateurBand($frequency) {
private function _is_frequency_in_amateurband($frequency) {
// Ensure frequency is in Hz if input is in kHz
if ($frequency < 1_000_000) {
$frequency *= 1000;
@@ -569,98 +553,6 @@ class Dxcluster_model extends CI_Model {
}
}
function check_if_continent_worked_in_logbook($cont, $StationLocationsArray = null, $band = null, $mode = null) {
if ($StationLocationsArray == null) {
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
$this->db->select('COL_CONT');
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->where('COL_CONT', $cont);
if (isset($mode)) {
$this->db->where(" COL_MODE in ".$this->Modes->get_modes_from_qrgmode($mode,true));
}
$band = ($band == 'All') ? null : $band;
if ($band != null && $band != 'SAT') {
$this->db->where('COL_BAND', $band);
} else if ($band == 'SAT') {
// Where col_sat_name is not empty
$this->db->where('COL_SAT_NAME !=', '');
}
$this->db->limit('2');
$query = $this->db->get($this->config->item('table_name'));
return $query->num_rows();
}
function check_if_continent_cnfmd_in_logbook($cont, $StationLocationsArray = null, $band = null, $mode = null) {
if ($StationLocationsArray == null) {
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
$user_default_confirmation = $this->session->userdata('user_default_confirmation');
$extrawhere = '';
if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) {
$extrawhere = "COL_QSL_RCVD='Y'";
}
if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) {
if ($extrawhere != '') {
$extrawhere .= " OR";
}
$extrawhere .= " COL_LOTW_QSL_RCVD='Y'";
}
if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) {
if ($extrawhere != '') {
$extrawhere .= " OR";
}
$extrawhere .= " COL_EQSL_QSL_RCVD='Y'";
}
if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Z') !== false) {
if ($extrawhere != '') {
$extrawhere .= " OR";
}
$extrawhere .= " COL_QRZCOM_QSO_DOWNLOAD_STATUS='Y'";
}
$this->db->select('COL_CONT');
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->where('COL_CONT', $cont);
if (isset($mode)) {
$this->db->where(" COL_MODE in ".$this->Modes->get_modes_from_qrgmode($mode,true));
}
$band = ($band == 'All') ? null : $band;
if ($band != null && $band != 'SAT') {
$this->db->where('COL_BAND', $band);
} else if ($band == 'SAT') {
// Where col_sat_name is not empty
$this->db->where('COL_SAT_NAME !=', '');
}
if ($extrawhere != '') {
$this->db->where('(' . $extrawhere . ')');
} else {
$this->db->where("1=0");
}
$this->db->limit('2');
$query = $this->db->get($this->config->item('table_name'));
return $query->num_rows();
}
/**
* Enrich spot metadata with park references and contest detection
* Extracts SOTA/POTA/IOTA/WWFF references and detects contest spots
@@ -668,7 +560,7 @@ class Dxcluster_model extends CI_Model {
* @param object $spot - Spot object with message and dxcc_spotted properties
* @return object - Spot object with enriched dxcc_spotted containing references and isContest flag
*/
function enrich_spot_metadata($spot) {
private function _enrich_spot_metadata($spot) {
// Ensure dxcc_spotted object exists
if (!property_exists($spot, 'dxcc_spotted') || !is_object($spot->dxcc_spotted)) {
$spot->dxcc_spotted = (object)[];

View File

@@ -899,7 +899,7 @@ class Logbook_model extends CI_Model {
}
// Invalidate DXCluster cache for this callsign
$this->dxclustercache->invalidateForCallsign($data['COL_CALL']);
$this->dxclustercache->invalidate_for_callsign($data['COL_CALL']);
// Return QSO ID for ADIF generation
return $last_id;
@@ -1674,7 +1674,7 @@ class Logbook_model extends CI_Model {
$retvals['success']=true;
// Invalidate DXCluster cache for this callsign
$this->dxclustercache->invalidateForCallsign($data['COL_CALL']);
$this->dxclustercache->invalidate_for_callsign($data['COL_CALL']);
} catch (Exception $e) {
$retvals['success']=false;
$retvals['detail']=$e;
@@ -2746,7 +2746,7 @@ class Logbook_model extends CI_Model {
// Build cache key with user_id, logbook_ids, and confirmation preference
$user_id = $this->session->userdata('user_id');
$logbook_ids_key = $this->dxclustercache->getLogbookKey($user_id, $logbooks_locations_array, $user_default_confirmation);
$logbook_ids_key = $this->dxclustercache->get_logbook_key($user_id, $logbooks_locations_array, $user_default_confirmation);
$spots_by_callsign = []; // Group spots by callsign for processing
foreach ($spots as $spot) {
@@ -4354,7 +4354,7 @@ class Logbook_model extends CI_Model {
$this->db->delete("oqrs");
// Invalidate DXCluster cache for this callsign
$this->dxclustercache->invalidateForCallsign($callsign);
$this->dxclustercache->invalidate_for_callsign($callsign);
} else {
return;
}