add some comments and self review

这个提交包含在:
Patrick Burns 2024-05-29 15:50:49 -05:00
父节点 928af0eaf3
当前提交 ff97d96c33
共有 2 个文件被更改,包括 58 次插入40 次删除

查看文件

@ -481,7 +481,6 @@ class API extends CI_Controller {
http_response_code(201);
echo json_encode(['Today' => $data['todays_qsos'], 'total_qsos' => $data['total_qsos'], 'month_qsos' => $data['month_qsos'], 'year_qsos' => $data['year_qsos']]);
}
function recent_qsos($key = null) {

查看文件

@ -2239,58 +2239,77 @@ class Logbook_model extends CI_Model
}
/* Return 10 most recent QSOs */
<?php
/* Return most recent QSOs */
function recent_qsos($StationLocationsArray = null, $api_key = null)
{
$CI = &get_instance();
$detailed = $this->input->get('detailed') === 'true' ? true : false;
$limit = $this->input->get('limit');
$limit = is_numeric($limit) ? $limit : 10; // Default to 10 if limit is not a number
// Get a reference to the CodeIgniter instance
$CI = &get_instance();
// Throw an error if limit is greater than 100
if ($limit > 100) {
show_error('The limit cannot be greater than 100.', 400);
return;
}
// Check if 'detailed' parameter is set to 'true' in the URL
$detailed = $this->input->get('detailed') === 'true' ? true : false;
// Get 'limit' parameter from the URL, default to 10 if it's not a number
$limit = $this->input->get('limit');
$limit = is_numeric($limit) ? $limit : 10;
if ($StationLocationsArray == null) {
$CI->load->model('logbooks_model');
if ($api_key != null) {
$CI->load->model('api_model');
if (strpos($this->api_model->access($api_key), 'r') !== false) {
$this->api_model->update_last_used($api_key);
$user_id = $this->api_model->key_userid($api_key);
$active_station_logbook = $CI->logbooks_model->find_active_station_logbook_from_userid($user_id);
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($active_station_logbook);
// Throw an error if limit is greater than 100
if ($limit > 100) {
show_error('The limit cannot be greater than 100.', 400);
return;
}
// If no station locations array is provided, get it from the logbooks model
if ($StationLocationsArray == null) {
$CI->load->model('logbooks_model');
// If an API key is provided, get the logbooks locations array for the user associated with the API key
if ($api_key != null) {
$CI->load->model('api_model');
if (strpos($this->api_model->access($api_key), 'r') !== false) {
$this->api_model->update_last_used($api_key);
$user_id = $this->api_model->key_userid($api_key);
$active_station_logbook = $CI->logbooks_model->find_active_station_logbook_from_userid($user_id);
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($active_station_logbook);
} else {
$logbooks_locations_array = [];
}
} else {
$logbooks_locations_array = [];
// If no API key is provided, get the logbooks locations array for the current session's active station logbook
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
}
} else {
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
$logbooks_locations_array = $StationLocationsArray;
}
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if ($logbooks_locations_array) {
if ($detailed) {
$this->db->select('*');
// If there are any logbooks locations, get the recent QSOs
if ($logbooks_locations_array) {
// If 'detailed' is true, select all columns, otherwise select specific columns
if ($detailed) {
$this->db->select('*');
} else {
$this->db->select('COL_CALL, COL_BAND, COL_FREQ, COL_MODE, COL_SUBMODE, COL_NAME, COL_MY_GRIDSQUARE, COL_COUNTRY, COL_DXCC, COL_CONTEST_ID, COL_FREQ_RX, COL_MY_CITY, COL_MY_CNTY, COL_MY_COUNTRY, COL_COMMENT, COL_DISTANCE, COL_NAME, COL_OPERATOR, COL_RST_RCVD, COL_RST_SENT, COL_STATION_CALLSIGN, COL_TIME_OFF, COL_TIME_ON, COL_TX_PWR');
}
// Filter by station ID and order by time on, descending
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->order_by('COL_TIME_ON', 'DESC');
// Limit the number of results
$this->db->limit($limit);
// Execute the query
$query = $this->db->get($this->config->item('table_name'));
// If there are any results, return them, otherwise return null
if ($query->num_rows() > 0) {
return $query->result();
}
} else {
$this->db->select('COL_CALL, COL_BAND, COL_FREQ, COL_MODE, COL_SUBMODE, COL_NAME, COL_MY_GRIDSQUARE, COL_COUNTRY, COL_DXCC, COL_CONTEST_ID, COL_FREQ_RX, COL_MY_CITY, COL_MY_CNTY, COL_MY_COUNTRY, COL_COMMENT, COL_DISTANCE, COL_NAME, COL_OPERATOR, COL_RST_RCVD, COL_RST_SENT, COL_STATION_CALLSIGN, COL_TIME_OFF, COL_TIME_ON, COL_TX_PWR');
return null;
}
$this->db->where_in('station_id', $logbooks_locations_array);
$this->db->order_by('COL_TIME_ON', 'DESC');
$this->db->limit($limit);
$query = $this->db->get($this->config->item('table_name'));
if ($query->num_rows() > 0) {
return $query->result();
}
} else {
return null;
}
}
?>
/* Return QSOs over a period of days */
function map_week_qsos($start, $end)