From 14163bd2cf49ea2c6d30530515e5f27cf7b5850b Mon Sep 17 00:00:00 2001 From: Calin Burloiu Date: Wed, 14 Sep 2011 17:41:04 +0300 Subject: [PATCH] search category dropdown adde to the interface --- application/controllers/catalog.php | 17 +++++++++----- application/language/english/ui_lang.php | 1 + application/models/videos_model.php | 20 +++++++++++++++-- application/views/header.php | 28 ++++++++++++------------ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 7d86d36..79d0f96 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -131,7 +131,6 @@ class Catalog extends CI_Controller { $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', array( 'search_category_name'=>$vs_data['category_name'], - 'search_category_title'=>$vs_data['category_title'] )); // $main_params['content'] = $this->load->view('catalog/category_view', $data, TRUE); @@ -146,15 +145,22 @@ class Catalog extends CI_Controller { public function search($search_query = "", $offset = 0, $category_name = NULL) { + $this->load->model('videos_model'); + $this->load->library('security'); + // Redirect to an URL which contains search string if data was passed // via POST method and not via URL segments. $str_post_search = $this->input->post('search'); + $str_post_category = $this->input->post('search-category'); if ($search_query === "" && $str_post_search !== FALSE) - redirect('catalog/search/'. $str_post_search); + { + redirect('catalog/search/' + . $this->videos_model->encode_search_query($str_post_search) + . '/0' + . ($str_post_category === FALSE ? '' : "/$str_post_category")); + return; + } - $this->load->model('videos_model'); - $this->load->library('security'); - // ** // ** LOADING MODEL // ** @@ -176,7 +182,6 @@ class Catalog extends CI_Controller { if ($category_name !== NULL) { $header_data['search_category_name'] = $results_data['category_name']; - $header_data['search_category_title'] = $results_data['category_title']; } // Check if search string is valid. diff --git a/application/language/english/ui_lang.php b/application/language/english/ui_lang.php index d8f62b7..0b83757 100644 --- a/application/language/english/ui_lang.php +++ b/application/language/english/ui_lang.php @@ -23,6 +23,7 @@ $lang['ui_install_browser_version_not_supported'] = ' is not supported for your $lang['ui_install_already_installed'] = ' is installed'; // Video Categories +$lang['ui_categ_all-categories'] = 'All Categories'; $lang['ui_categ_movies'] = 'Movies'; $lang['ui_categ_tech-talks'] = 'TechTalks'; $lang['ui_categ_events'] = 'Events'; diff --git a/application/models/videos_model.php b/application/models/videos_model.php index 46efd10..5ba77c9 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -309,10 +309,10 @@ class Videos_model extends CI_Model { $str_query = "SELECT $selected_columns FROM `videos` - WHERE $category_cond $search_cond + WHERE $category_cond ( $search_cond ) $order $limit"; - //echo "

$str_query

"; +// echo "

$str_query

"; $query = $this->db->query($str_query); if ($query->num_rows() > 0) @@ -364,6 +364,22 @@ class Videos_model extends CI_Model { return $search_query; } + public function encode_search_query($search_query) + { + $search_query = str_replace('*', '_AST_', $search_query); + $search_query = str_replace('+', '_AND_', $search_query); + $search_query = str_replace('>', '_GT_', $search_query); + $search_query = str_replace('<', '_LT_', $search_query); + $search_query = str_replace('(', '_PO_', $search_query); + $search_query = str_replace(')', '_PC_', $search_query); + $search_query = str_replace('~', '_LOW_', $search_query); + $search_query = str_replace('"', '_QUO_', $search_query); + + $search_query = urlencode($search_query); + + return $search_query; + } + /** * Return TRUE if it contains any special caracter from an advanced search * query. diff --git a/application/views/header.php b/application/views/header.php index 829bbb7..242c710 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -4,7 +4,13 @@ if (! isset($search_query)) $search_query = ''; if (! isset($search_category_name)) - $search_category_name = NULL; + $search_category_name = 'all-categories'; + + $categories['all-categories'] = $this->lang->line('ui_categ_all-categories'); + foreach ($this->config->item('categories') as $id => $name) + { + $categories[$name] = $this->lang->line("ui_categ_$name"); + } ?>