mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Add function to pull all worked grids at once
This commit is contained in:
@@ -723,6 +723,71 @@ class API extends CI_Controller {
|
||||
|
||||
}
|
||||
|
||||
// API function to check if a grid is in the logbook already
|
||||
function logbook_get_worked_grids() {
|
||||
$arr = array();
|
||||
header('Content-type: application/json');
|
||||
$this->load->model('api_model');
|
||||
$obj = json_decode(file_get_contents("php://input"), true);
|
||||
if ($obj === NULL) {
|
||||
echo json_encode(['status' => 'failed', 'reason' => "wrong JSON"]);
|
||||
}
|
||||
if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "missing api key"]);
|
||||
}
|
||||
if(!isset($obj['logbook_public_slug'])) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "missing fields"]);
|
||||
return;
|
||||
}
|
||||
if($obj['logbook_public_slug'] != "") {
|
||||
$logbook_slug = $obj['logbook_public_slug'];
|
||||
if(isset($obj['band'])) {
|
||||
$band = $obj['band'];
|
||||
} else {
|
||||
$band = null;
|
||||
}
|
||||
if(isset($obj['cnfm'])) {
|
||||
$cnfm = $obj['cnfm'];
|
||||
} else {
|
||||
$cnfm = null;
|
||||
}
|
||||
$this->load->model('logbooks_model');
|
||||
if($this->logbooks_model->public_slug_exists($logbook_slug)) {
|
||||
$logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($logbook_slug);
|
||||
if($logbook_id != false)
|
||||
{
|
||||
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id);
|
||||
if (!$logbooks_locations_array) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "Empty Logbook"]);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
http_response_code(404);
|
||||
echo json_encode(['status' => 'failed', 'reason' => $logbook_slug." has no associated station locations"]);
|
||||
die();
|
||||
}
|
||||
$this->load->model('logbook_model');
|
||||
|
||||
$query = $this->logbook_model->get_grids_worked_in_logbook($logbooks_locations_array, $band, $cnfm);
|
||||
http_response_code(201);
|
||||
foreach($query->result() as $line) {
|
||||
$arr[] = $line->gridorcnfm;
|
||||
}
|
||||
echo json_encode($arr);
|
||||
|
||||
} else {
|
||||
http_response_code(404);
|
||||
echo json_encode(['status' => 'failed', 'reason' => "logbook not found"]);
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ENDPOINT for Rig Control */
|
||||
|
||||
function radio() {
|
||||
|
||||
@@ -3335,6 +3335,50 @@ class Logbook_model extends CI_Model {
|
||||
return $query;
|
||||
}
|
||||
|
||||
function get_grids_worked_in_logbook($StationLocationsArray = null, $band = null, $cnfm = 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;
|
||||
}
|
||||
|
||||
switch ($cnfm) {
|
||||
case 'qsl':
|
||||
$this->db->select('COL_QSL_RCVD as gridorcnfm');
|
||||
$this->db->group_by('COL_QSL_RCVD');
|
||||
break;
|
||||
case 'lotw':
|
||||
$this->db->select('COL_LOTW_QSL_RCVD as gridorcnfm');
|
||||
$this->db->group_by('COL_LOTW_QSL_RCVD');
|
||||
break;
|
||||
case 'eqsl':
|
||||
$this->db->select('COL_EQSL_QSL_RCVD as gridorcnfm');
|
||||
$this->db->group_by('COL_EQSL_QSL_RCVD');
|
||||
break;
|
||||
default:
|
||||
$this->db->select('SUBSTR(COL_GRIDSQUARE,1 ,4) as gridorcnfm');
|
||||
$this->db->group_by('gridorcnfm');
|
||||
break;
|
||||
}
|
||||
$this->db->order_by('gridorcnfm');
|
||||
$this->db->where_in('station_id', $logbooks_locations_array);
|
||||
|
||||
$band = ($band == 'All') ? null : $band;
|
||||
if ($band != null && $band != 'SAT') {
|
||||
$this->db->where('COL_BAND', $band);
|
||||
} else if ($band == 'SAT') {
|
||||
$this->db->where('COL_SAT_NAME !=', '');
|
||||
}
|
||||
$this->db->having('gridorcnfm !=', '');
|
||||
$this->db->having('gridorcnfm is not null');
|
||||
|
||||
$query = $this->db->get($this->config->item('table_name'));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/* Get all QSOs with a valid grid for use in the KML export */
|
||||
function kml_get_all_qsos($band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) {
|
||||
$this->load->model('logbooks_model');
|
||||
|
||||
Reference in New Issue
Block a user