From 660cdc6b24c1ad1895b5c3ddb6e2c9d665e198ae Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 16 Feb 2024 14:26:08 +0000 Subject: [PATCH] [Upcoming Dxped] Split output into months --- application/controllers/Workabledxcc.php | 184 +++++++++--------- .../workabledxcc/components/dxcclist.php | 71 ++++--- 2 files changed, 140 insertions(+), 115 deletions(-) diff --git a/application/controllers/Workabledxcc.php b/application/controllers/Workabledxcc.php index c26c7b65..c4271853 100644 --- a/application/controllers/Workabledxcc.php +++ b/application/controllers/Workabledxcc.php @@ -1,89 +1,98 @@ -load->model('user_model'); - if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } } - public function index() { - // Load public view - $data['page_title'] = "Upcoming DXPeditions"; - $this->load->view('interface_assets/header', $data); - $this->load->view('/workabledxcc/index'); - $this->load->view('interface_assets/footer'); - } + public function index() + { + // Load public view + $data['page_title'] = "Upcoming DXPeditions"; + $this->load->view('interface_assets/header', $data); + $this->load->view('/workabledxcc/index'); + $this->load->view('interface_assets/footer'); + } - public function dxcclist() { + public function dxcclist() + { - $json = file_get_contents('https://cdn.cloudlog.org/read_ng3k_dxped_list.php'); + $json = file_get_contents('https://cdn.cloudlog.org/read_ng3k_dxped_list.php'); - // Decode the JSON data into a PHP array - $dataResult = json_decode($json, true); - - // Initialize an empty array to store the required data - $requiredData = array(); - - // Get Date format - if($this->session->userdata('user_date_format')) { - // If Logged in and session exists - $custom_date_format = $this->session->userdata('user_date_format'); - } else { - // Get Default date format from /config/cloudlog.php - $custom_date_format = $this->config->item('qso_date_format'); - } + // Decode the JSON data into a PHP array + $dataResult = json_decode($json, true); - // Iterate through the decoded JSON data - foreach ($dataResult as $item) { - // Create a new array with the required fields and add it to the main array - $oldStartDate = DateTime::createFromFormat('Y-m-d', $item['0']); - - $StartDate = $oldStartDate->format($custom_date_format); + // Initialize an empty array to store the required data + $requiredData = array(); - $oldEndDate = DateTime::createFromFormat('Y-m-d', $item['1']); - - $EndDate = $oldEndDate->format($custom_date_format); + // Get Date format + if ($this->session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/cloudlog.php + $custom_date_format = $this->config->item('qso_date_format'); + } - $this->load->model('logbook_model'); - $dxccInfo = $this->logbook_model->dxcc_lookup($item['callsign'], $StartDate); + // Iterate through the decoded JSON data + foreach ($dataResult as $item) { + // Create a new array with the required fields and add it to the main array + $oldStartDate = DateTime::createFromFormat('Y-m-d', $item['0']); - // Call DXCC Worked function to check if the DXCC has been worked before - if (isset($dxccInfo['entity'])) { - $dxccWorked = $this->dxccWorked($dxccInfo['entity']); - } else { - // Handle the case where 'entity' is not set in $dxccInfo - $dxccWorked = array( - 'workedBefore' => false, - 'confirmed' => false, - ); - } + $StartDate = $oldStartDate->format($custom_date_format); - $requiredData[] = array( - 'start_date' => $StartDate, - 'end_date' => $EndDate, - 'country' => $item['2'], - 'notes' => $item['6'], - 'callsign' => $item['callsign'], - 'workedBefore' => $dxccWorked['workedBefore'], - 'confirmed' => $dxccWorked['confirmed'], - ); - } + $oldEndDate = DateTime::createFromFormat('Y-m-d', $item['1']); - $data['dxcclist'] = $requiredData; - - // Return the array with the required data + $EndDate = $oldEndDate->format($custom_date_format); - $this->load->view('/workabledxcc/components/dxcclist', $data); - } + $this->load->model('logbook_model'); + $dxccInfo = $this->logbook_model->dxcc_lookup($item['callsign'], $StartDate); - function dxccWorked($country) { + // Call DXCC Worked function to check if the DXCC has been worked before + if (isset($dxccInfo['entity'])) { + $dxccWorked = $this->dxccWorked($dxccInfo['entity']); + } else { + // Handle the case where 'entity' is not set in $dxccInfo + $dxccWorked = array( + 'workedBefore' => false, + 'confirmed' => false, + ); + } + + $requiredData[] = array( + 'clean_date' => $item['0'], + 'start_date' => $StartDate, + 'end_date' => $EndDate, + 'country' => $item['2'], + 'notes' => $item['6'], + 'callsign' => $item['callsign'], + 'workedBefore' => $dxccWorked['workedBefore'], + 'confirmed' => $dxccWorked['confirmed'], + ); + } + + $data['dxcclist'] = $requiredData; + + // Return the array with the required data + + $this->load->view('/workabledxcc/components/dxcclist', $data); + } + + function dxccWorked($country) + { $return = [ "workedBefore" => false, @@ -95,50 +104,49 @@ class Workabledxcc extends CI_Controller { $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); $this->load->model('logbook_model'); - if(!empty($logbooks_locations_array)) { - $this->db->where('COL_PROP_MODE !=','SAT'); + if (!empty($logbooks_locations_array)) { + $this->db->where('COL_PROP_MODE !=', 'SAT'); $this->db->where_in('station_id', $logbooks_locations_array); $this->db->where('COL_COUNTRY', urldecode($country)); $query = $this->db->get($this->config->item('table_name'), 1, 0); - foreach ($query->result() as $workedBeforeRow) - { + foreach ($query->result() as $workedBeforeRow) { $return['workedBefore'] = true; } - $extrawhere=''; + $extrawhere = ''; if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Q') !== false) { - $extrawhere="COL_QSL_RCVD='Y'"; + $extrawhere = "COL_QSL_RCVD='Y'"; } if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'L') !== false) { - if ($extrawhere!='') { - $extrawhere.=" OR"; + if ($extrawhere != '') { + $extrawhere .= " OR"; } - $extrawhere.=" COL_LOTW_QSL_RCVD='Y'"; + $extrawhere .= " COL_LOTW_QSL_RCVD='Y'"; } if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'E') !== false) { - if ($extrawhere!='') { - $extrawhere.=" OR"; + if ($extrawhere != '') { + $extrawhere .= " OR"; } - $extrawhere.=" COL_EQSL_QSL_RCVD='Y'"; + $extrawhere .= " COL_EQSL_QSL_RCVD='Y'"; } if (isset($user_default_confirmation) && strpos($user_default_confirmation, 'Z') !== false) { - if ($extrawhere!='') { - $extrawhere.=" OR"; + if ($extrawhere != '') { + $extrawhere .= " OR"; } - $extrawhere.=" COL_QRZCOM_QSO_DOWNLOAD_STATUS='Y'"; + $extrawhere .= " COL_QRZCOM_QSO_DOWNLOAD_STATUS='Y'"; } - $this->load->model('logbook_model'); - $this->db->where('COL_PROP_MODE !=','SAT'); - if ($extrawhere != '') { - $this->db->where('('.$extrawhere.')'); - } else { - $this->db->where("1=0"); - } + $this->load->model('logbook_model'); + $this->db->where('COL_PROP_MODE !=', 'SAT'); + if ($extrawhere != '') { + $this->db->where('(' . $extrawhere . ')'); + } else { + $this->db->where("1=0"); + } $this->db->where_in('station_id', $logbooks_locations_array); @@ -146,7 +154,7 @@ class Workabledxcc extends CI_Controller { $query = $this->db->get($this->config->item('table_name'), 1, 0); foreach ($query->result() as $workedBeforeRow) { - $return['confirmed']=true; + $return['confirmed'] = true; } return $return; diff --git a/application/views/workabledxcc/components/dxcclist.php b/application/views/workabledxcc/components/dxcclist.php index 05e75203..8cbbf8d4 100644 --- a/application/views/workabledxcc/components/dxcclist.php +++ b/application/views/workabledxcc/components/dxcclist.php @@ -1,39 +1,56 @@ - + +// Step 2: Iterate over $dxcclist. +foreach ($dxcclist as $dxcc) { + // Get the month from the start date. + $month = date('F Y', strtotime($dxcc['clean_date'])); + + // Check if this month already exists in $grouped. + if (!isset($grouped[$month])) { + // If it doesn't, create a new array for it. + $grouped[$month] = []; + } + + // Add the current item to the array for its month. + $grouped[$month][] = $dxcc; +} + +// Step 5: Iterate over $grouped to create a table for each month. +foreach ($grouped as $month => $dxccs) { + echo "

$month

"; + echo '
'; + echo ' - + '; + foreach ($dxccs as $dxcc) { + echo ' + + + + + - - - - - + + '; + } - - Not Worked Before - - Worked Before - - - - Confirmed - - - - - - -
Start Date End Date Country Callsign Notes
' . $dxcc['start_date'] . '' . $dxcc['end_date'] . '' . $dxcc['country'] . '' . $dxcc['callsign'] . ''; + if (!$dxcc['workedBefore']) { + echo 'Not Worked Before'; + } else { + echo 'Worked Before'; + } - -
- + if ($dxcc['confirmed']) { + echo 'Confirmed'; + } - + echo '' . $dxcc['notes'] . '
\ No newline at end of file + echo ''; +}