[Days with QSOs] Fix if no QSOs found

这个提交包含在:
Andreas 2021-11-14 17:49:35 +01:00
父节点 6e6fe817fe
当前提交 341e8f4a33
共有 2 个文件被更改,包括 136 次插入115 次删除

查看文件

@ -9,6 +9,10 @@ class Dayswithqso_model extends CI_Model
$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'));
if (!$logbooks_locations_array) {
return null;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'"; $location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from " $sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from "
@ -25,6 +29,8 @@ class Dayswithqso_model extends CI_Model
*/ */
function getCurrentStreak() { function getCurrentStreak() {
$dates = $this->getDates(); $dates = $this->getDates();
if ($dates) {
$dates = array_reverse($dates); $dates = array_reverse($dates);
$streak = 1; $streak = 1;
$firstrun = true; $firstrun = true;
@ -56,12 +62,15 @@ class Dayswithqso_model extends CI_Model
return null; return null;
} }
} }
}
/* /*
* Function returns streak that ended yesterday, but can be continued if a qso is made today * Function returns streak that ended yesterday, but can be continued if a qso is made today
*/ */
function getAlmostCurrentStreak() { function getAlmostCurrentStreak() {
$dates = $this->getDates(); $dates = $this->getDates();
if ($dates) {
$dates = array_reverse($dates); $dates = array_reverse($dates);
$streak = 1; $streak = 1;
$firstrun = true; $firstrun = true;
@ -94,6 +103,8 @@ class Dayswithqso_model extends CI_Model
} }
} }
}
/* /*
* Function returns the 10 longest streaks of QSOs based on all QSO dates in the log on active station profile * Function returns the 10 longest streaks of QSOs based on all QSO dates in the log on active station profile
*/ */
@ -103,6 +114,7 @@ class Dayswithqso_model extends CI_Model
$dateprev = date_create('1900-01-01'); // init variable with an old date $dateprev = date_create('1900-01-01'); // init variable with an old date
$i = 0; $i = 0;
if ($dates) {
foreach($dates as $date) { // Loop through the result set foreach($dates as $date) { // Loop through the result set
$datecurr = date_create($date->date); $datecurr = date_create($date->date);
if ($dateprev == date_create('1900-01-01')) { // If first run if ($dateprev == date_create('1900-01-01')) { // If first run
@ -126,6 +138,8 @@ class Dayswithqso_model extends CI_Model
} }
} }
if (isset($streaks) && is_array($streaks)) { if (isset($streaks) && is_array($streaks)) {
usort($streaks, array($this,'compareStreak')); // Sort array, highest streak first usort($streaks, array($this,'compareStreak')); // Sort array, highest streak first
$streaks_trimmed = array_slice($streaks, 0,10); // We only want top 10, so we trim the array $streaks_trimmed = array_slice($streaks, 0,10); // We only want top 10, so we trim the array
@ -134,6 +148,7 @@ class Dayswithqso_model extends CI_Model
return null; return null;
} }
} }
}
/* /*
* Used for sorting the array highest streak first * Used for sorting the array highest streak first
@ -150,6 +165,10 @@ class Dayswithqso_model extends CI_Model
$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'));
if (!$logbooks_locations_array) {
return null;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'"; $location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = "select distinct cast(col_time_on as date) as date from " $sql = "select distinct cast(col_time_on as date) as date from "

查看文件

@ -1,9 +1,10 @@
$.ajax({ $.ajax({
url: base_url+'index.php/dayswithqso/get_days', url: base_url + 'index.php/dayswithqso/get_days',
success: function(data) { success: function (data) {
if ($.trim(data)) {
var labels = []; var labels = [];
var dataDxcc = []; var dataDxcc = [];
$.each(data, function(){ $.each(data, function () {
labels.push(this.Year); labels.push(this.Year);
dataDxcc.push(this.Days); dataDxcc.push(this.Days);
}); });
@ -25,7 +26,7 @@ $.ajax({
scales: { scales: {
yAxes: [{ yAxes: [{
ticks: { ticks: {
beginAtZero:true, beginAtZero: true,
fontColor: color fontColor: color
} }
}], }],
@ -43,4 +44,5 @@ $.ajax({
} }
}); });
} }
}
}); });