cloudlog/application/models/Setup_model.php

61 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-10-30 12:15:08 +01:00
<?php
class Setup_model extends CI_Model {
function getCountryCount() {
$sql = 'select count(*) as count from dxcc_entities';
$query = $this->db->query($sql);
2023-10-30 12:15:08 +01:00
return $query->row()->count;
2023-10-30 12:15:08 +01:00
}
function getLogbookCount() {
$userid = (int) $this->session->userdata('user_id');
// Count logbooks the user owns OR has been granted permissions to
$this->db->select('COUNT(DISTINCT sl.logbook_id) AS count', false);
$this->db->from('station_logbooks sl');
$this->db->join('station_logbooks_permissions slp', 'slp.logbook_id = sl.logbook_id AND slp.user_id = '.$this->db->escape($userid), 'left', false);
$this->db->group_start();
$this->db->where('sl.user_id', $userid);
$this->db->or_where('slp.user_id', $userid);
$this->db->group_end();
$query = $this->db->get();
2023-10-30 12:15:08 +01:00
return $query->row()->count;
2023-10-30 12:15:08 +01:00
}
function getLocationCount() {
$userid = (int) $this->session->userdata('user_id');
$this->db->select('count(*) as count', false);
$this->db->where('user_id', $userid);
$query = $this->db->get('station_profile');
2023-10-30 12:15:08 +01:00
return $query->row()->count;
2023-10-30 12:15:08 +01:00
}
// Consolidated method to get all setup counts in one query
function getAllSetupCounts() {
$userid = (int) $this->session->userdata('user_id');
$userid_escaped = $this->db->escape($userid);
$sql = "SELECT
(SELECT COUNT(*) FROM dxcc_entities) as country_count,
(SELECT COUNT(DISTINCT sl.logbook_id) FROM station_logbooks sl
LEFT JOIN station_logbooks_permissions slp
ON slp.logbook_id = sl.logbook_id AND slp.user_id = {$userid_escaped}
WHERE sl.user_id = {$userid_escaped} OR slp.user_id = {$userid_escaped}) as logbook_count,
(SELECT COUNT(*) FROM station_profile WHERE user_id = {$userid_escaped}) as location_count";
$query = $this->db->query($sql);
$row = $query->row();
return array(
'country_count' => $row->country_count,
'logbook_count' => $row->logbook_count,
'location_count' => $row->location_count
);
}
2023-10-30 12:15:08 +01:00
}
?>