mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Set oqrs to done when qsl set as sent
This commit is contained in:
@@ -616,4 +616,15 @@ class Oqrs_model extends CI_Model {
|
||||
return $this->db->affected_rows() > 0;
|
||||
}
|
||||
|
||||
public function update_oqrs_set_done($qsoids) {
|
||||
if (empty($qsoids)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = ['status' => '2'];
|
||||
$this->db->where_in('qsoid', $qsoids);
|
||||
return $this->db->update('oqrs', $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,34 +32,67 @@ class Qslprint_model extends CI_Model {
|
||||
/*
|
||||
* Updates the QSOs that do not have any COL_QSL_SENT_VIA set
|
||||
*/
|
||||
function update_qsos_bureau($station_ids) {
|
||||
$data = array(
|
||||
'COL_QSLSDATE' => date('Y-m-d'),
|
||||
'COL_QSL_SENT' => "Y",
|
||||
'COL_QSL_SENT_VIA' => "B",
|
||||
);
|
||||
|
||||
function update_qsos_bureau($station_ids) {
|
||||
// Step 1: Select IDs to be updated
|
||||
$this->db->select('col_primary_key');
|
||||
$this->db->from($this->config->item('table_name'));
|
||||
$this->db->where_in("station_id", $station_ids);
|
||||
$this->db->where_in("COL_QSL_SENT", array("R","Q"));
|
||||
$this->db->where("coalesce(COL_QSL_SENT_VIA, '') = ''");
|
||||
$this->db->where_in("COL_QSL_SENT", array("R", "Q"));
|
||||
$this->db->where("coalesce(COL_QSL_SENT_VIA, '') = ''", null, false); // raw where for COALESCE
|
||||
$query = $this->db->get();
|
||||
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
$ids = array_column($query->result_array(), 'col_primary_key');
|
||||
|
||||
if (!empty($ids)) {
|
||||
// Step 2: Perform update
|
||||
$data = array(
|
||||
'COL_QSLSDATE' => date('Y-m-d'),
|
||||
'COL_QSL_SENT' => "Y",
|
||||
'COL_QSL_SENT_VIA' => "B",
|
||||
);
|
||||
|
||||
$this->db->where_in('col_primary_key', $ids);
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
}
|
||||
|
||||
$this->load->model('oqrs_model');
|
||||
$this->oqrs_model->update_oqrs_set_done($ids);
|
||||
|
||||
// Step 3: Return updated IDs
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Updates the QSOs that do have COL_QSL_SENT_VIA set
|
||||
*/
|
||||
function update_qsos($station_ids) {
|
||||
$data = array(
|
||||
'COL_QSLSDATE' => date('Y-m-d'),
|
||||
'COL_QSL_SENT' => "Y",
|
||||
);
|
||||
|
||||
// Step 1: Select IDs to be updated
|
||||
$this->db->select('col_primary_key');
|
||||
$this->db->from($this->config->item('table_name'));
|
||||
$this->db->where_in("station_id", $station_ids);
|
||||
$this->db->where_in("COL_QSL_SENT", array("R","Q"));
|
||||
$this->db->where("coalesce(COL_QSL_SENT_VIA, '') != ''");
|
||||
$this->db->where_in("COL_QSL_SENT", array("R", "Q"));
|
||||
$this->db->where("coalesce(COL_QSL_SENT_VIA, '') != ''", null, false); // raw where for COALESCE
|
||||
$query = $this->db->get();
|
||||
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
$ids = array_column($query->result_array(), 'col_primary_key');
|
||||
|
||||
if (!empty($ids)) {
|
||||
// Step 2: Perform update
|
||||
$data = array(
|
||||
'COL_QSLSDATE' => date('Y-m-d'),
|
||||
'COL_QSL_SENT' => "Y",
|
||||
);
|
||||
|
||||
$this->db->where_in('col_primary_key', $ids);
|
||||
$this->db->update($this->config->item('table_name'), $data);
|
||||
}
|
||||
|
||||
$this->load->model('oqrs_model');
|
||||
$this->oqrs_model->update_oqrs_set_done($ids);
|
||||
|
||||
// Step 3: Return updated IDs
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -150,18 +183,18 @@ class Qslprint_model extends CI_Model {
|
||||
if (empty($qso_id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$table_name = $this->config->item('table_name');
|
||||
$sql = "SELECT COUNT(COL_PRIMARY_KEY) AS previous_qsl
|
||||
FROM $table_name
|
||||
$sql = "SELECT COUNT(COL_PRIMARY_KEY) AS previous_qsl
|
||||
FROM $table_name
|
||||
WHERE COL_QSL_SENT = 'Y'
|
||||
AND station_id = (SELECT station_id FROM $table_name WHERE COL_PRIMARY_KEY = ?)
|
||||
AND (COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '')) =
|
||||
(SELECT COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '')
|
||||
FROM $table_name
|
||||
AND (COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '')) =
|
||||
(SELECT COL_CALL, COL_MODE, COL_BAND, COALESCE(COL_SAT_NAME, '')
|
||||
FROM $table_name
|
||||
WHERE COL_PRIMARY_KEY = ?)
|
||||
GROUP BY COL_CALL, COL_MODE, COL_BAND, COL_SAT_NAME";
|
||||
|
||||
|
||||
// we only return the count of previous QSLs as an integer
|
||||
return (int) ($this->db->query($sql, [$qso_id, $qso_id])->row()->previous_qsl ?? 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user