Merge pull request #1156 from AndreasK79/dxcc_station_logbooks

[DXCC Award] Updated code to support station logbooks
pull/1162/head
Peter Goodhall 2021-09-09 21:51:03 +01:00 zatwierdzone przez GitHub
commit 4fc4897142
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 45 dodań i 104 usunięć

Wyświetl plik

@ -34,12 +34,14 @@ class DXCC extends CI_Model {
function get_worked_bands() { function get_worked_bands() {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('logbooks_model');
$station_id = $CI->Stations->find_active(); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$location_list = "'".implode("','",$logbooks_locations_array)."'";
// get all worked slots from database // get all worked slots from database
$data = $this->db->query( $data = $this->db->query(
"SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\"" "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE != \"SAT\""
); );
$worked_slots = array(); $worked_slots = array();
foreach($data->result() as $row){ foreach($data->result() as $row){
@ -47,7 +49,7 @@ class DXCC extends CI_Model {
} }
$SAT_data = $this->db->query( $SAT_data = $this->db->query(
"SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` WHERE station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\"" "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE = \"SAT\""
); );
foreach($SAT_data->result() as $row){ foreach($SAT_data->result() as $row){
@ -66,69 +68,6 @@ class DXCC extends CI_Model {
return $results; return $results;
} }
function show_stats(){
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$data = $this->db->query(
"select COL_COUNTRY, COL_MODE, lcase(COL_BAND) as COL_BAND, count(COL_COUNTRY) as cnt
from ".$this->config->item('table_name')."
where station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\"
group by COL_COUNTRY, COL_MODE, COL_BAND"
);
$results = array();
$last_country = "";
foreach($data->result() as $row){
if ($last_country != $row->COL_COUNTRY){
// new row
$results[$row->COL_COUNTRY] = $this->bandslots;
$last_country = $row->COL_COUNTRY;
}
// update stats
if (!isset($results[$row->COL_COUNTRY]))
$results[$row->COL_COUNTRY] = [];
if (!isset($results[$row->COL_COUNTRY][$row->COL_BAND]))
$results[$row->COL_COUNTRY][$row->COL_BAND] = 0;
$results[$row->COL_COUNTRY][$row->COL_BAND] += $row->cnt;
}
// Satellite DXCC
$satellite_data = $this->db->query(
"select COL_COUNTRY, COL_PROP_MODE as COL_PROP_MODE, count(COL_COUNTRY) as cnt
from ".$this->config->item('table_name')."
where station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\"
group by COL_COUNTRY"
);
foreach($satellite_data->result() as $row){
if ($last_country != $row->COL_COUNTRY){
// new row
$results[$row->COL_COUNTRY] = $this->bandslots;
$last_country = $row->COL_COUNTRY;
}
// update stats
if (!isset($results[$row->COL_COUNTRY]))
$results[$row->COL_COUNTRY] = [];
if (!isset($results[$row->COL_COUNTRY][$row->COL_PROP_MODE]))
$results[$row->COL_COUNTRY][$row->COL_PROP_MODE] = 0;
$results[$row->COL_COUNTRY][$row->COL_PROP_MODE] += $row->cnt;
}
// print_r($results);
// return;
return $results;
}
/** /**
* Function: mostactive * Function: mostactive
* Information: Returns the most active band * Information: Returns the most active band
@ -169,7 +108,7 @@ class DXCC extends CI_Model {
} }
/* /*
* Fethes a list of all dxcc's, both current and deleted * Fetches a list of all dxcc's, both current and deleted
*/ */
function list() { function list() {
$this->db->order_by('name', 'ASC'); $this->db->order_by('name', 'ASC');
@ -187,8 +126,10 @@ class DXCC extends CI_Model {
function get_dxcc_array($dxccArray, $bands, $postdata) { function get_dxcc_array($dxccArray, $bands, $postdata) {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('logbooks_model');
$station_id = $CI->Stations->find_active(); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$location_list = "'".implode("','",$logbooks_locations_array)."'";
foreach ($bands as $band) { // Looping through bands and entities to generate the array needed for display foreach ($bands as $band) { // Looping through bands and entities to generate the array needed for display
foreach ($dxccArray as $dxcc) { foreach ($dxccArray as $dxcc) {
@ -201,7 +142,7 @@ class DXCC extends CI_Model {
// If worked is checked, we add worked entities to the array // If worked is checked, we add worked entities to the array
if ($postdata['worked'] != NULL) { if ($postdata['worked'] != NULL) {
$workedDXCC = $this->getDxccBandWorked($station_id, $band, $postdata); $workedDXCC = $this->getDxccBandWorked($location_list, $band, $postdata);
foreach ($workedDXCC as $wdxcc) { foreach ($workedDXCC as $wdxcc) {
//function displayContacts(searchphrase, band, mode, type) { //function displayContacts(searchphrase, band, mode, type) {
$dxccMatrix[$wdxcc->dxcc][$band] = '<div class="alert-danger"><a href=\'javascript:displayContacts("'.str_replace("&", "%26", $wdxcc->name).'","'. $band . '","'. $postdata['mode'] . '","DXCC")\'>W</a></div>'; $dxccMatrix[$wdxcc->dxcc][$band] = '<div class="alert-danger"><a href=\'javascript:displayContacts("'.str_replace("&", "%26", $wdxcc->name).'","'. $band . '","'. $postdata['mode'] . '","DXCC")\'>W</a></div>';
@ -210,7 +151,7 @@ class DXCC extends CI_Model {
// If confirmed is checked, we add confirmed entities to the array // If confirmed is checked, we add confirmed entities to the array
if ($postdata['confirmed'] != NULL) { if ($postdata['confirmed'] != NULL) {
$confirmedDXCC = $this->getDxccBandConfirmed($station_id, $band, $postdata); $confirmedDXCC = $this->getDxccBandConfirmed($location_list, $band, $postdata);
foreach ($confirmedDXCC as $cdxcc) { foreach ($confirmedDXCC as $cdxcc) {
$dxccMatrix[$cdxcc->dxcc][$band] = '<div class="alert-success"><a href=\'javascript:displayContacts("'.str_replace("&", "%26", $cdxcc->name).'","'. $band . '","'. $postdata['mode'] . '","DXCC")\'>C</a></div>'; $dxccMatrix[$cdxcc->dxcc][$band] = '<div class="alert-success"><a href=\'javascript:displayContacts("'.str_replace("&", "%26", $cdxcc->name).'","'. $band . '","'. $postdata['mode'] . '","DXCC")\'>C</a></div>';
} }
@ -219,7 +160,7 @@ class DXCC extends CI_Model {
// We want to remove the worked dxcc's in the list, since we do not want to display them // We want to remove the worked dxcc's in the list, since we do not want to display them
if ($postdata['worked'] == NULL) { if ($postdata['worked'] == NULL) {
$workedDxcc = $this->getDxccWorked($station_id, $postdata); $workedDxcc = $this->getDxccWorked($location_list, $postdata);
foreach ($workedDxcc as $wdxcc) { foreach ($workedDxcc as $wdxcc) {
if (array_key_exists($wdxcc->dxcc, $dxccMatrix)) { if (array_key_exists($wdxcc->dxcc, $dxccMatrix)) {
unset($dxccMatrix[$wdxcc->dxcc]); unset($dxccMatrix[$wdxcc->dxcc]);
@ -229,7 +170,7 @@ class DXCC extends CI_Model {
// We want to remove the confirmed dxcc's in the list, since we do not want to display them // We want to remove the confirmed dxcc's in the list, since we do not want to display them
if ($postdata['confirmed'] == NULL) { if ($postdata['confirmed'] == NULL) {
$confirmedDxcc = $this->getDxccConfirmed($station_id, $postdata); $confirmedDxcc = $this->getDxccConfirmed($location_list, $postdata);
foreach ($confirmedDxcc as $cdxcc) { foreach ($confirmedDxcc as $cdxcc) {
if (array_key_exists($cdxcc->dxcc, $dxccMatrix)) { if (array_key_exists($cdxcc->dxcc, $dxccMatrix)) {
unset($dxccMatrix[$cdxcc->dxcc]); unset($dxccMatrix[$cdxcc->dxcc]);
@ -245,12 +186,12 @@ class DXCC extends CI_Model {
} }
} }
function getDxccBandConfirmed($station_id, $band, $postdata) { function getDxccBandConfirmed($location_list, $band, $postdata) {
$sql = "select adif as dxcc, name from dxcc_entities $sql = "select adif as dxcc, name from dxcc_entities
join ( join (
select col_dxcc from ".$this->config->item('table_name')." thcv select col_dxcc from ".$this->config->item('table_name')." thcv
where station_id = " . $station_id . where station_id in (" . $location_list .
" and col_dxcc > 0"; ") and col_dxcc > 0";
if ($band == 'SAT') { if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'"; $sql .= " and col_prop_mode ='" . $band . "'";
@ -280,12 +221,12 @@ class DXCC extends CI_Model {
return $query->result(); return $query->result();
} }
function getDxccBandWorked($station_id, $band, $postdata) { function getDxccBandWorked($location_list, $band, $postdata) {
$sql = "select adif as dxcc, name from dxcc_entities $sql = "select adif as dxcc, name from dxcc_entities
join ( join (
select col_dxcc from ".$this->config->item('table_name')." thcv select col_dxcc from ".$this->config->item('table_name')." thcv
where station_id = " . $station_id . where station_id in (" . $location_list .
" and col_dxcc > 0"; ") and col_dxcc > 0";
if ($band == 'SAT') { if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'"; $sql .= " and col_prop_mode ='" . $band . "'";
@ -315,14 +256,16 @@ class DXCC extends CI_Model {
function fetchDxcc($postdata) { function fetchDxcc($postdata) {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('logbooks_model');
$station_id = $CI->Stations->find_active(); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = "select adif, prefix, name, date(end) Enddate, date(start) Startdate $sql = "select adif, prefix, name, date(end) Enddate, date(start) Startdate
from dxcc_entities"; from dxcc_entities";
if ($postdata['notworked'] == NULL) { if ($postdata['notworked'] == NULL) {
$sql .= " join (select col_dxcc from " . $this->config->item('table_name') . " where station_id = " . $station_id . " and col_dxcc > 0"; $sql .= " join (select col_dxcc from " . $this->config->item('table_name') . " where station_id in (" . $location_list . ") and col_dxcc > 0";
if ($postdata['band'] != 'All') { if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') { if ($postdata['band'] == 'SAT') {
@ -355,13 +298,13 @@ class DXCC extends CI_Model {
return $query->result(); return $query->result();
} }
function getDxccWorked($station_id, $postdata) { function getDxccWorked($location_list, $postdata) {
$sql = "SELECT adif as dxcc FROM dxcc_entities $sql = "SELECT adif as dxcc FROM dxcc_entities
join ( join (
select col_dxcc select col_dxcc
from ".$this->config->item('table_name')." thcv from ".$this->config->item('table_name')." thcv
where station_id = " . $station_id . where station_id in (" . $location_list .
" and col_dxcc > 0"; ") and col_dxcc > 0";
if ($postdata['band'] != 'All') { if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') { if ($postdata['band'] == 'SAT') {
@ -377,7 +320,7 @@ class DXCC extends CI_Model {
$sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')";
} }
$sql .= " and not exists (select 1 from ".$this->config->item('table_name')." where station_id = $station_id and col_dxcc = thcv.col_dxcc and col_dxcc > 0"; $sql .= " and not exists (select 1 from ".$this->config->item('table_name')." where station_id in (". $location_list .") and col_dxcc = thcv.col_dxcc and col_dxcc > 0";
if ($postdata['band'] != 'All') { if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') { if ($postdata['band'] == 'SAT') {
@ -412,13 +355,13 @@ class DXCC extends CI_Model {
return $query->result(); return $query->result();
} }
function getDxccConfirmed($station_id, $postdata) { function getDxccConfirmed($location_list, $postdata) {
$sql = "SELECT adif as dxcc FROM dxcc_entities $sql = "SELECT adif as dxcc FROM dxcc_entities
join ( join (
select col_dxcc select col_dxcc
from ".$this->config->item('table_name')." thcv from ".$this->config->item('table_name')." thcv
where station_id = ". $station_id . where station_id in (". $location_list .
" and col_dxcc > 0"; ") and col_dxcc > 0";
if ($postdata['band'] != 'All') { if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') { if ($postdata['band'] == 'SAT') {
@ -507,18 +450,20 @@ class DXCC extends CI_Model {
function get_dxcc_summary($bands) function get_dxcc_summary($bands)
{ {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('logbooks_model');
$station_id = $CI->Stations->find_active(); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$location_list = "'".implode("','",$logbooks_locations_array)."'";
foreach ($bands as $band) { foreach ($bands as $band) {
$worked = $this->getSummaryByBand($band, $station_id); $worked = $this->getSummaryByBand($band, $location_list);
$confirmed = $this->getSummaryByBandConfirmed($band, $station_id); $confirmed = $this->getSummaryByBandConfirmed($band, $location_list);
$dxccSummary['worked'][$band] = $worked[0]->count; $dxccSummary['worked'][$band] = $worked[0]->count;
$dxccSummary['confirmed'][$band] = $confirmed[0]->count; $dxccSummary['confirmed'][$band] = $confirmed[0]->count;
} }
$workedTotal = $this->getSummaryByBand('All', $station_id); $workedTotal = $this->getSummaryByBand('All', $location_list);
$confirmedTotal = $this->getSummaryByBandConfirmed('All', $station_id); $confirmedTotal = $this->getSummaryByBandConfirmed('All', $location_list);
$dxccSummary['worked']['Total'] = $workedTotal[0]->count; $dxccSummary['worked']['Total'] = $workedTotal[0]->count;
$dxccSummary['confirmed']['Total'] = $confirmedTotal[0]->count; $dxccSummary['confirmed']['Total'] = $confirmedTotal[0]->count;
@ -526,11 +471,11 @@ class DXCC extends CI_Model {
return $dxccSummary; return $dxccSummary;
} }
function getSummaryByBand($band, $station_id) function getSummaryByBand($band, $location_list)
{ {
$sql = "SELECT count(distinct thcv.col_dxcc) as count FROM " . $this->config->item('table_name') . " thcv"; $sql = "SELECT count(distinct thcv.col_dxcc) as count FROM " . $this->config->item('table_name') . " thcv";
$sql .= " where station_id = " . $station_id . " and col_dxcc > 0"; $sql .= " where station_id in (" . $location_list . ") and col_dxcc > 0";
if ($band == 'SAT') { if ($band == 'SAT') {
@ -546,11 +491,11 @@ class DXCC extends CI_Model {
return $query->result(); return $query->result();
} }
function getSummaryByBandConfirmed($band, $station_id) function getSummaryByBandConfirmed($band, $location_list)
{ {
$sql = "SELECT count(distinct thcv.col_dxcc) as count FROM " . $this->config->item('table_name') . " thcv"; $sql = "SELECT count(distinct thcv.col_dxcc) as count FROM " . $this->config->item('table_name') . " thcv";
$sql .= " where station_id = " . $station_id; $sql .= " where station_id in (" . $location_list . ")";
if ($band == 'SAT') { if ($band == 'SAT') {
$sql .= " and thcv.col_prop_mode ='" . $band . "'"; $sql .= " and thcv.col_prop_mode ='" . $band . "'";

Wyświetl plik

@ -236,10 +236,6 @@ class Logbook_model extends CI_Model {
* Used to fetch QSOs from the logbook in the awards * Used to fetch QSOs from the logbook in the awards
*/ */
public function qso_details($searchphrase, $band, $mode, $type){ public function qso_details($searchphrase, $band, $mode, $type){
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('logbooks_model'); $CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));