mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Refactored to set measurement_base in constructor instead
This commit is contained in:
@@ -149,15 +149,8 @@ class Logbookadvanced extends CI_Controller {
|
||||
|
||||
$qsos = [];
|
||||
|
||||
if ($this->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $this->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $this->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
foreach ($this->logbookadvanced_model->searchQsos($searchCriteria) as $qso) {
|
||||
$qsos[] = $qso->toArray($measurement_base);
|
||||
$qsos[] = $qso->toArray();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
@@ -183,17 +176,10 @@ class Logbookadvanced extends CI_Controller {
|
||||
$qso = $this->logbook_model->qso_info($qsoID)->row_array();
|
||||
}
|
||||
|
||||
if ($this->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $this->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $this->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
$qsoObj = new QSO($qso);
|
||||
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($qsoObj->toArray($measurement_base));
|
||||
echo json_encode($qsoObj->toArray());
|
||||
}
|
||||
|
||||
function export_to_adif() {
|
||||
@@ -243,16 +229,9 @@ class Logbookadvanced extends CI_Controller {
|
||||
$qsos[] = new QSO($data);
|
||||
}
|
||||
|
||||
if ($this->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $this->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $this->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
$q = [];
|
||||
foreach ($qsos as $qso) {
|
||||
$q[] = $qso->toArray($measurement_base);
|
||||
$q[] = $qso->toArray();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
@@ -278,16 +257,9 @@ class Logbookadvanced extends CI_Controller {
|
||||
$qsos[] = new QSO($data);
|
||||
}
|
||||
|
||||
if ($this->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $this->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $this->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
$q = [];
|
||||
foreach ($qsos as $qso) {
|
||||
$q[] = $qso->toArray($measurement_base);
|
||||
$q[] = $qso->toArray();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
@@ -643,15 +615,8 @@ class Logbookadvanced extends CI_Controller {
|
||||
$custom_date_format = $this->config->item('qso_date_format');
|
||||
}
|
||||
|
||||
if ($this->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $this->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $this->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
foreach ($qsos as $qso) {
|
||||
$q[] = $qso->toArray($measurement_base);
|
||||
$q[] = $qso->toArray();
|
||||
}
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
@@ -83,6 +83,8 @@ class QSO
|
||||
private string $stationpower;
|
||||
private float $distance;
|
||||
|
||||
private string $measurement_base;
|
||||
|
||||
/**
|
||||
* @param array $data Does no validation, it's assumed to be a row from the database in array format
|
||||
*/
|
||||
@@ -244,6 +246,15 @@ class QSO
|
||||
|
||||
$this->stationpower = $data['COL_TX_PWR'] ?? '';
|
||||
$this->distance = (float)$data['COL_DISTANCE'] ?? 0;
|
||||
|
||||
if ($CI->session->userdata('user_measurement_base') == NULL) {
|
||||
$measurement_base = $CI->config->item('measurement_base');
|
||||
}
|
||||
else {
|
||||
$measurement_base = $CI->session->userdata('user_measurement_base');
|
||||
}
|
||||
|
||||
$this->measurement_base = $measurement_base;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1001,7 +1012,7 @@ class QSO
|
||||
return '<span id="operator">' . $this->operator . '</span>';
|
||||
}
|
||||
|
||||
public function toArray($measurement_base): array
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'qsoID' => $this->qsoID,
|
||||
@@ -1044,15 +1055,15 @@ class QSO
|
||||
'continent' => $this->continent,
|
||||
'profilename' => $this->profilename,
|
||||
'stationpower' => $this->stationpower,
|
||||
'distance' => $this->getFormattedDistance($measurement_base)
|
||||
'distance' => $this->getFormattedDistance()
|
||||
];
|
||||
}
|
||||
|
||||
private function getFormattedDistance($measurement_base): string
|
||||
private function getFormattedDistance(): string
|
||||
{
|
||||
if ($this->distance == 0) return '';
|
||||
|
||||
switch ($measurement_base) {
|
||||
switch ($this->measurement_base) {
|
||||
case 'M':
|
||||
$unit = "mi";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user