Make stats publicly usable with API key
这个提交包含在:
父节点
80f8b88c5a
当前提交
c57932be86
共有 3 个文件被更改,包括 76 次插入 和 14 次删除
|
|
@ -672,14 +672,14 @@ class API extends CI_Controller {
|
|||
*
|
||||
*/
|
||||
|
||||
function statistics() {
|
||||
function statistics($key = null) {
|
||||
header('Content-type: application/json');
|
||||
$this->load->model('logbook_model');
|
||||
|
||||
$data['todays_qsos'] = $this->logbook_model->todays_qsos();
|
||||
$data['total_qsos'] = $this->logbook_model->total_qsos();
|
||||
$data['month_qsos'] = $this->logbook_model->month_qsos();
|
||||
$data['year_qsos'] = $this->logbook_model->year_qsos();
|
||||
$data['todays_qsos'] = $this->logbook_model->todays_qsos(null, $key);
|
||||
$data['total_qsos'] = $this->logbook_model->total_qsos(null, $key);
|
||||
$data['month_qsos'] = $this->logbook_model->month_qsos(null, $key);
|
||||
$data['year_qsos'] = $this->logbook_model->year_qsos(null, $key);
|
||||
|
||||
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']]);
|
||||
|
|
@ -841,4 +841,4 @@ class API extends CI_Controller {
|
|||
$latlng = $this->qra->qra2latlong($qra);
|
||||
return $latlng;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1583,11 +1583,23 @@ class Logbook_model extends CI_Model {
|
|||
}
|
||||
|
||||
/* Return total number of qsos */
|
||||
function total_qsos($StationLocationsArray = null) {
|
||||
function total_qsos($StationLocationsArray = null, $api_key = null) {
|
||||
if($StationLocationsArray == null) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('logbooks_model');
|
||||
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
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 = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
}
|
||||
} else {
|
||||
$logbooks_locations_array = $StationLocationsArray;
|
||||
}
|
||||
|
|
@ -1610,11 +1622,23 @@ class Logbook_model extends CI_Model {
|
|||
}
|
||||
|
||||
/* Return number of QSOs had today */
|
||||
function todays_qsos($StationLocationsArray = null) {
|
||||
function todays_qsos($StationLocationsArray = null, $api_key = null) {
|
||||
if($StationLocationsArray == null) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('logbooks_model');
|
||||
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
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 = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
}
|
||||
} else {
|
||||
$logbooks_locations_array = $StationLocationsArray;
|
||||
}
|
||||
|
|
@ -1713,11 +1737,23 @@ class Logbook_model extends CI_Model {
|
|||
}
|
||||
|
||||
// Return QSOs made during the current month
|
||||
function month_qsos($StationLocationsArray = null) {
|
||||
function month_qsos($StationLocationsArray = null, $api_key = null) {
|
||||
if($StationLocationsArray == null) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('logbooks_model');
|
||||
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
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 = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
}
|
||||
} else {
|
||||
$logbooks_locations_array = $StationLocationsArray;
|
||||
}
|
||||
|
|
@ -1764,12 +1800,24 @@ class Logbook_model extends CI_Model {
|
|||
|
||||
|
||||
/* Return QSOs made during the current Year */
|
||||
function year_qsos($StationLocationsArray = null) {
|
||||
function year_qsos($StationLocationsArray = null, $api_key = null) {
|
||||
|
||||
if($StationLocationsArray == null) {
|
||||
$CI =& get_instance();
|
||||
$CI->load->model('logbooks_model');
|
||||
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
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 = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
||||
}
|
||||
} else {
|
||||
$logbooks_locations_array = $StationLocationsArray;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,5 +308,19 @@ class Logbooks_model extends CI_Model {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function find_active_station_logbook_from_userid($userid) {
|
||||
$this->db->select('active_station_logbook');
|
||||
$this->db->where('user_id', $userid);
|
||||
$query = $this->db->get('users');
|
||||
if ($query->num_rows() > 0){
|
||||
foreach ($query->result() as $row)
|
||||
{
|
||||
return $row->active_station_logbook;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
正在加载…
在新工单中引用