From 34212d2976ec6f792df71db849bfc2784afa11f8 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 15 Feb 2016 17:46:33 +0000 Subject: [PATCH] DXCC awards has links to show stations worked on that band and country --- application/controllers/api.php | 97 +++++++++++++++------- application/controllers/awards.php | 35 ++++++++ application/controllers/logbook.php | 6 +- application/models/dxcc.php | 8 +- application/views/awards/dxcc/index.php | 7 +- application/views/view_log/partial/log.php | 2 + 6 files changed, 120 insertions(+), 35 deletions(-) diff --git a/application/controllers/api.php b/application/controllers/api.php index d135353e..6109b9b2 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -151,13 +151,15 @@ class API extends CI_Controller { $this->load->model('user_model'); $arguments = $this->_retrieve(); + print_r($arguments); + return; if((!$this->user_model->authorize(3)) && ($this->api_model->authorize($arguments['key']) == 0)) { - $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); - } + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); + } // Retrieve the arguments from the query string - $data['data']['format'] = $arguments['format']; + $data['data']['format'] = $arguments['format']; // Call the parser within the API model to build the query $query = $this->api_model->select_parse($arguments); @@ -166,33 +168,45 @@ class API extends CI_Controller { $s = $this->logbook_model->api_search_query($query); $a = 0; - if(isset($s['results'])) { - $results = $s['results']; + // Print query results using original column names and exit + if ($arguments['format'] == 'original'){ + $results = array(); + foreach($s['results']->result() as $row){ + //print_r($row); + array_push($results, $row); + } - // Cycle through the results, and translate between MySQL column names - // and more friendly, descriptive names - if($results->num_rows != 0) - { - foreach ($results->result() as $row) { - $record = (array)$row; - $r[$a]['rid'] = $a; - while (list($key, $val) = each($record)) { - $r[$a][$this->api_model->name($key)] = $val; - } - $a++; - } - // Add the result record to the main results array - $data['data']['search_Result']['results'] = $r; - } - else - { - // We've got no results, so make this empty for completeness - $data['data']['search_Result']['results'] = ""; - } - } else { - $data['data']['error'] = $s['error']; - $data['data']['search_Result']['results'] = ""; - } + print json_encode($results); + return; + } + + if(isset($s['results'])) { + $results = $s['results']; + + // Cycle through the results, and translate between MySQL column names + // and more friendly, descriptive names + if($results->num_rows != 0) + { + foreach ($results->result() as $row) { + $record = (array)$row; + $r[$a]['rid'] = $a; + while (list($key, $val) = each($record)) { + $r[$a][$this->api_model->name($key)] = $val; + } + $a++; + } + // Add the result record to the main results array + $data['data']['search_Result']['results'] = $r; + } + else + { + // We've got no results, so make this empty for completeness + $data['data']['search_Result']['results'] = ""; + } + } else { + $data['data']['error'] = $s['error']; + $data['data']['search_Result']['results'] = ""; + } // Add some debugging information to the XML output $data['data']['queryInfo']['call'] = "search"; @@ -204,6 +218,31 @@ class API extends CI_Controller { $this->load->view('api/index', $data); } + /* + * version of search that is callable internally + * $arguments is an array of columns to query + */ + function api_search($arguments){ + // Load the API and Logbook models + $this->load->model('api_model'); + $this->load->model('logbook_model'); + $this->load->model('user_model'); + + if((!$this->user_model->authorize(3)) && ($this->api_model->authorize($arguments['key']) == 0)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); + } + + // Retrieve the arguments from the query string + $data['data']['format'] = $arguments['format']; + + // Call the parser within the API model to build the query + $query = $this->api_model->select_parse($arguments); + + // Execute the query, and retrieve the results + $s = $this->logbook_model->api_search_query($query); + return $s; + } + function validate() { // Load the API and Logbook models diff --git a/application/controllers/awards.php b/application/controllers/awards.php index 4e2e1222..2c1055a8 100644 --- a/application/controllers/awards.php +++ b/application/controllers/awards.php @@ -30,6 +30,41 @@ class Awards extends CI_Controller { $this->load->view('layout/footer'); } + + public function dxcc_details(){ + $a = $this->input->get(); + $q = ""; + foreach ($a as $key => $value) { + $q .= $key."=".$value.("(and)"); + } + $q = substr($q, 0, strlen($q)-13); + + $arguments["query"] = $q; + $arguments["fields"] = ''; + $arguments["format"] = "json"; + $arguments["limit"] = ''; + $arguments["order"] = ''; + + // print_r($arguments); + // return; + + // Load the API and Logbook models + $this->load->model('api_model'); + $this->load->model('logbook_model'); + + // Call the parser within the API model to build the query + $query = $this->api_model->select_parse($arguments); + + // Execute the query, and retrieve the results + $data = $this->logbook_model->api_search_query($query); + + // Render Page + $data['page_title'] = "Log View - DXCC"; + $data['filter'] = $a["Country"] . " and " . $a["Band"]; + $this->load->view('layout/header', $data); + $this->load->view('awards/dxcc/details'); + $this->load->view('layout/footer'); + } /* Handles Displaying of WAB Squares worked. diff --git a/application/controllers/logbook.php b/application/controllers/logbook.php index babab64b..477d8fbc 100644 --- a/application/controllers/logbook.php +++ b/application/controllers/logbook.php @@ -291,7 +291,7 @@ class Logbook extends CI_Controller { } } - function search_result($id) { + function search_result($id="") { $this->load->model('user_model'); if(!$this->user_model->authorize($this->config->item('auth_mode'))) { return; } @@ -304,7 +304,7 @@ class Logbook extends CI_Controller { if ($query->num_rows() > 0) { $data['results'] = $query; - $this->load->view('search/result_search.php', $data); + $this->load->view('view_log/partial/log.php', $data); } else { $this->load->model('search'); @@ -313,7 +313,7 @@ class Logbook extends CI_Controller { if ($iota_search->num_rows() > 0) { $data['results'] = $iota_search; - $this->load->view('search/result_search.php', $data); + $this->load->view('view_log/partial/log.php', $data); } else { if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { // Lookup using QRZ diff --git a/application/models/dxcc.php b/application/models/dxcc.php index d3ec2873..df101839 100644 --- a/application/models/dxcc.php +++ b/application/models/dxcc.php @@ -40,7 +40,8 @@ class DXCC extends CI_Model { $results[$row->COL_COUNTRY][$row->COL_BAND] = $row->cnt; } - //print_r($results); + // print_r($results); + // return; return $results; } @@ -75,6 +76,11 @@ class DXCC extends CI_Model { } } + function search(){ + print_r($this->input->get()); + return; + } + function empty_table($table) { $this->db->empty_table($table); } diff --git a/application/views/awards/dxcc/index.php b/application/views/awards/dxcc/index.php index a62472e6..b69704ef 100644 --- a/application/views/awards/dxcc/index.php +++ b/application/views/awards/dxcc/index.php @@ -35,8 +35,11 @@ foreach($dxcc as $country=>$val){ print("$country"); foreach($val as $band=>$count){ - $count = ($count == 0)?" ":$count; - print("$count"); + if ($count == 0){ + print(" "); + }else{ + printf("%d", $country, $band, $count); + } } print(""); } diff --git a/application/views/view_log/partial/log.php b/application/views/view_log/partial/log.php index b7d844d4..a7eefc94 100644 --- a/application/views/view_log/partial/log.php +++ b/application/views/view_log/partial/log.php @@ -88,9 +88,11 @@ + pagination)){ ?> +