From a7375c0bdcc756be22450ef18e159990a397f20c Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 4 Sep 2022 18:26:21 +0200 Subject: [PATCH] [Bands] Added logic to fetch bands from database --- application/controllers/Band.php | 2 +- application/models/Bands.php | 37 ++++++++++++++++++++++++++----- application/views/bands/index.php | 24 ++++++++++---------- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/application/controllers/Band.php b/application/controllers/Band.php index 505575a9..0e3c0792 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -19,7 +19,7 @@ class Band extends CI_Controller { { $this->load->model('bands'); - $data['bands'] = $this->bands->all(); + $data['bands'] = $this->bands->get_all_bands_for_user(); // Render Page $data['page_title'] = "Bands"; diff --git a/application/models/Bands.php b/application/models/Bands.php index a49ae19c..517eae93 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -28,16 +28,41 @@ class Bands extends CI_Model { "SAT"=>0, ); - function all2() { - $this->db->order_by('band', 'ASC'); - return $this->db->get('bands'); + function get_user_bands($award = 'None') { + $this->db->from('bands'); + $this->db->join('bandxuser', 'bandxuser.bandid = bands.id'); + $this->db->where('bandxuser.userid', $this->session->userdata('user_id')); + $this->db->where('bandxuser.active', 1); + + if ($award != 'None') { + $this->db->where('bandxuser.".$award', 1); + } + + $result = $this->db->get()->result(); + + $results = array(); + + foreach($result as $band) { + array_push($results, $band->band); + } + + return $results; + } + + function get_all_bands_for_user() { + $this->db->from('bands'); + $this->db->join('bandxuser', 'bandxuser.bandid = bands.id'); + $this->db->where('bandxuser.userid', $this->session->userdata('user_id')); + + return $this->db->get()->result(); } function all() { return $this->bandslots; } - function get_worked_bands() { + function get_worked_bands($award = 'None') { + $CI =& get_instance(); $CI->load->model('logbooks_model'); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); @@ -65,10 +90,10 @@ class Bands extends CI_Model { array_push($worked_slots, strtoupper($row->COL_PROP_MODE)); } + $bandslots = $this->get_user_bands($award); - // bring worked-slots in order of defined $bandslots $results = array(); - foreach(array_keys($this->bandslots) as $slot) { + foreach($bandslots as $slot) { if(in_array($slot, $worked_slots)) { array_push($results, $slot); } diff --git a/application/views/bands/index.php b/application/views/bands/index.php index b2608a57..fafb3ef4 100644 --- a/application/views/bands/index.php +++ b/application/views/bands/index.php @@ -44,19 +44,19 @@ - $band) { ?> + - - Active -
-
-
-
-
-
-
-
-
+ band?> + active == 1) {echo 'Active';} else {echo 'Not Active';}; ?> +
cq == 1) {echo 'checked';}?>>
+
dok == 1) {echo 'checked';}?>>
+
dxcc == 1) {echo 'checked';}?>>
+
iota == 1) {echo 'checked';}?>>
+
sig == 1) {echo 'checked';}?>>
+
sota == 1) {echo 'checked';}?>>
+
uscounties == 1) {echo 'checked';}?>>
+
was == 1) {echo 'checked';}?>>
+
vucc == 1) {echo 'checked';}?>>