2022-12-18 15:49:54 +00:00
|
|
|
<?php
|
|
|
|
use Cloudlog\QSLManager\QSO;
|
|
|
|
|
|
|
|
class Logbookadvanced_model extends CI_Model {
|
|
|
|
/*
|
|
|
|
* @param array $searchCriteria
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function searchQsos($searchCriteria) : array {
|
|
|
|
$conditions = [];
|
|
|
|
$binding = [$searchCriteria['user_id']];
|
|
|
|
|
|
|
|
if ($searchCriteria['dateFrom'] !== '') {
|
|
|
|
$from = DateTime::createFromFormat('d/m/Y', $searchCriteria['dateFrom']);
|
|
|
|
$from = $from->format('Y-m-d');
|
|
|
|
$conditions[] = "date(COL_TIME_ON) >= ?";
|
|
|
|
$binding[] = $from;
|
|
|
|
}
|
|
|
|
if ($searchCriteria['dateTo'] !== '') {
|
|
|
|
$to = DateTime::createFromFormat('d/m/Y', $searchCriteria['dateTo']);
|
|
|
|
$to = $to->format('Y-m-d');
|
|
|
|
$conditions[] = "date(COL_TIME_ON) <= ?";
|
|
|
|
$binding[] = $to;
|
|
|
|
}
|
|
|
|
if ($searchCriteria['de'] !== '') {
|
|
|
|
$conditions[] = "COL_STATION_CALLSIGN = ?";
|
|
|
|
$binding[] = trim($searchCriteria['de']);
|
|
|
|
}
|
|
|
|
if ($searchCriteria['dx'] !== '') {
|
|
|
|
$conditions[] = "COL_CALL LIKE ?";
|
|
|
|
$binding[] = '%' . trim($searchCriteria['dx']) . '%';
|
|
|
|
}
|
|
|
|
if ($searchCriteria['mode'] !== '') {
|
2022-12-27 17:56:04 +00:00
|
|
|
$conditions[] = "(COL_MODE = ? or COL_SUBMODE = ?)";
|
|
|
|
$binding[] = $searchCriteria['mode'];
|
|
|
|
$binding[] = $searchCriteria['mode'];
|
2022-12-18 15:49:54 +00:00
|
|
|
}
|
|
|
|
if ($searchCriteria['band'] !== '') {
|
2022-12-21 09:49:23 +00:00
|
|
|
if($searchCriteria['band'] != "SAT") {
|
|
|
|
$conditions[] = "COL_BAND = ? and COL_PROP_MODE != 'SAT'";
|
|
|
|
$binding[] = trim($searchCriteria['band']);
|
|
|
|
} else {
|
|
|
|
$conditions[] = "COL_PROP_MODE = 'SAT'";
|
|
|
|
}
|
2022-12-18 15:49:54 +00:00
|
|
|
}
|
|
|
|
if ($searchCriteria['qslSent'] !== '') {
|
|
|
|
$conditions[] = "COL_QSL_SENT = ?";
|
|
|
|
$binding[] = $searchCriteria['qslSent'];
|
|
|
|
}
|
|
|
|
if ($searchCriteria['qslReceived'] !== '') {
|
|
|
|
$conditions[] = "COL_QSL_RCVD = ?";
|
|
|
|
$binding[] = $searchCriteria['qslReceived'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($searchCriteria['iota'] !== '') {
|
|
|
|
$conditions[] = "COL_IOTA = ?";
|
|
|
|
$binding[] = $searchCriteria['iota'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($searchCriteria['dxcc'] !== '') {
|
|
|
|
$conditions[] = "COL_DXCC = ?";
|
|
|
|
$binding[] = $searchCriteria['dxcc'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($searchCriteria['state'] !== '') {
|
|
|
|
$conditions[] = "COL_STATE = ?";
|
|
|
|
$binding[] = $searchCriteria['state'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($searchCriteria['gridsquare'] !== '') {
|
|
|
|
$conditions[] = "(COL_GRIDSQUARE like ? or COL_VUCC_GRIDS like ?)";
|
|
|
|
$binding[] = '%' . $searchCriteria['gridsquare'] . '%';
|
|
|
|
$binding[] = '%' . $searchCriteria['gridsquare'] . '%';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($searchCriteria['propmode'] !== '') {
|
|
|
|
$conditions[] = "COL_PROP_MODE = ?";
|
|
|
|
$binding[] = $searchCriteria['propmode'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$where = trim(implode(" AND ", $conditions));
|
|
|
|
if ($where != "") {
|
|
|
|
$where = "AND $where";
|
|
|
|
}
|
|
|
|
|
2022-12-19 17:20:55 +00:00
|
|
|
$limit = $searchCriteria['qsoresults'];
|
2022-12-18 15:49:54 +00:00
|
|
|
|
|
|
|
$sql = "
|
|
|
|
SELECT *
|
|
|
|
FROM " . $this->config->item('table_name') . " qsos
|
|
|
|
INNER JOIN station_profile ON qsos.station_id=station_profile.station_id
|
|
|
|
WHERE station_profile.user_id = ?
|
|
|
|
$where
|
2023-01-25 23:57:38 +00:00
|
|
|
ORDER BY qsos.COL_TIME_ON desc, qsos.COL_PRIMARY_KEY desc
|
2022-12-18 15:49:54 +00:00
|
|
|
LIMIT $limit
|
|
|
|
";
|
|
|
|
|
|
|
|
$data = $this->db->query($sql, $binding);
|
|
|
|
|
|
|
|
$results = $data->result('array');
|
|
|
|
|
|
|
|
$qsos = [];
|
|
|
|
foreach ($results as $data) {
|
|
|
|
$qsos[] = new QSO($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $qsos;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQsosForAdif($ids, $user_id) : object {
|
|
|
|
$binding = [$user_id];
|
|
|
|
$conditions[] = "COL_PRIMARY_KEY in ?";
|
|
|
|
$binding[] = json_decode($ids, true);
|
|
|
|
|
|
|
|
$where = trim(implode(" AND ", $conditions));
|
|
|
|
if ($where != "") {
|
|
|
|
$where = "AND $where";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "
|
|
|
|
SELECT *
|
|
|
|
FROM " . $this->config->item('table_name') . " qsos
|
|
|
|
INNER JOIN station_profile ON qsos.station_id = station_profile.station_id
|
|
|
|
WHERE station_profile.user_id = ?
|
|
|
|
$where
|
|
|
|
ORDER BY qsos.COL_TIME_ON desc
|
|
|
|
";
|
|
|
|
|
|
|
|
return $this->db->query($sql, $binding);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateQsl($ids, $user_id, $method, $sent) {
|
|
|
|
$this->load->model('user_model');
|
|
|
|
|
|
|
|
if(!$this->user_model->authorize(2)) {
|
|
|
|
return array('message' => 'Error');
|
|
|
|
} else {
|
|
|
|
$data = array(
|
|
|
|
'COL_QSLSDATE' => date('Y-m-d H:i:s'),
|
|
|
|
'COL_QSL_SENT' => $sent,
|
|
|
|
'COL_QSL_SENT_VIA' => $method
|
|
|
|
);
|
|
|
|
$this->db->where_in('COL_PRIMARY_KEY', json_decode($ids, true));
|
|
|
|
$this->db->update($this->config->item('table_name'), $data);
|
|
|
|
|
|
|
|
return array('message' => 'OK');
|
|
|
|
}
|
|
|
|
}
|
2022-12-20 21:23:22 +00:00
|
|
|
|
|
|
|
public function updateQsoWithCallbookInfo($qsoID, $qso, $callbook) {
|
|
|
|
$updatedData = array();
|
|
|
|
if (!empty($callbook['name']) && empty($qso['COL_NAME'])) {
|
|
|
|
$updatedData['COL_NAME'] = $callbook['name'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['gridsquare']) && empty($qso['COL_GRIDSQUARE']) && empty($qso['COL_VUCC_GRIDS'] )) {
|
|
|
|
if (strpos(trim($callbook['gridsquare']), ',') === false) {
|
|
|
|
$updatedData['COL_GRIDSQUARE'] = strtoupper(trim($callbook['gridsquare']));
|
|
|
|
} else {
|
|
|
|
$updatedData['COL_VUCC_GRIDS'] = strtoupper(trim($callbook['gridsquare']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($callbook['city']) && empty($qso['COL_QTH'])) {
|
|
|
|
$updatedData['COL_QTH'] = $callbook['city'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['lat']) && empty($qso['COL_LAT'])) {
|
|
|
|
$updatedData['COL_LAT'] = $callbook['lat'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['long']) && empty($qso['COL_LON'])) {
|
|
|
|
$updatedData['COL_LON'] = $callbook['long'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['iota']) && empty($qso['COL_IOTA'])) {
|
|
|
|
$updatedData['COL_IOTA'] = $callbook['iota'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['state']) && empty($qso['COL_STATE'])) {
|
|
|
|
$updatedData['COL_STATE'] = $callbook['state'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['us_county']) && empty($qso['COL_USACA_COUNTIES'])) {
|
|
|
|
$updatedData['COL_USACA_COUNTIES'] = $callbook['us_county'];
|
|
|
|
}
|
|
|
|
if (!empty($callbook['qslmgr']) && empty($qso['COL_QSL_VIA'])) {
|
|
|
|
$updatedData['COL_QSL_VIA'] = $callbook['qslmgr'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($updatedData) > 0) {
|
|
|
|
$this->db->where('COL_PRIMARY_KEY', $qsoID);
|
|
|
|
$this->db->update($this->config->item('table_name'), $updatedData);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-27 17:56:04 +00:00
|
|
|
|
|
|
|
function get_modes() {
|
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('logbooks_model');
|
|
|
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
|
|
|
|
|
|
|
if (!$logbooks_locations_array) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$modes = array();
|
|
|
|
|
|
|
|
$this->db->select('distinct col_mode, coalesce(col_submode, "") col_submode', FALSE);
|
|
|
|
$this->db->where_in('station_id', $logbooks_locations_array);
|
|
|
|
$this->db->order_by('col_mode, col_submode', 'ASC');
|
|
|
|
|
|
|
|
$query = $this->db->get($this->config->item('table_name'));
|
|
|
|
|
|
|
|
foreach($query->result() as $mode){
|
|
|
|
if ($mode->col_submode == null || $mode->col_submode == "") {
|
|
|
|
array_push($modes, $mode->col_mode);
|
|
|
|
} else {
|
|
|
|
array_push($modes, $mode->col_submode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $modes;
|
|
|
|
}
|
2023-01-25 23:57:38 +00:00
|
|
|
}
|