From 17f4b407bb41c5b15f5089d83712a6b5dfaed00b Mon Sep 17 00:00:00 2001 From: P2P-Next Koala Date: Fri, 2 Sep 2011 11:36:40 +0300 Subject: [PATCH] minimal search feature added --- application/controllers/catalog.php | 48 +++++++++++++++++++++++++++-- application/models/videos_model.php | 45 +++++++++++++++++++++++++++ application/views/header.php | 6 ++-- 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index a22a1e8..0248f9e 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -142,9 +142,53 @@ class Catalog extends CI_Controller { $this->load->view('html_end'); } - public function search($query_str) + public function search($str_search = "") { - echo '

Search not yet implemented

'; + // TODO get query string from URL. + $str_search = $this->input->post('search', TRUE); + + // ** + // ** LOADING MODEL + // ** + // Video Category + $vs_data['category_name'] = ""; + $vs_data['category_title'] = "Search Results for «$str_search»"; + + // Retrieve videos summary. + $this->load->model('videos_model'); + $vs_data['videos'] = $this->videos_model->search_videos( + $str_search); + if ($vs_data['videos'] === NULL) + $vs_data['videos'] = array(); + + $vs_data['pagination'] = ''; + + // Video Summary + $data['video_summary'] = $this->load->view('catalog/videos_summary_view', + $vs_data, TRUE); + + $params = array( 'title' => $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + //'js' => array(), + //'metas' => array('description'=>'','keywords'=>'') + ); + $this->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** + $this->load->view('html_begin', $this->html_head_params); + $this->load->view('header'); + + $main_params['content'] = $this->load->view('catalog/category_view', $data, TRUE); + $main_params['side'] = $this->load->view('side_default.php', NULL, TRUE); + $this->load->view('main', $main_params); + + $this->load->view('footer'); + $this->load->view('html_end'); + } } diff --git a/application/models/videos_model.php b/application/models/videos_model.php index 1ba9e8f..c887b70 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -200,6 +200,51 @@ class Videos_model extends CI_Model { return $thumbs; } + + public function search_videos($str_search) + { + // TODO offset, count for search + $offset = 0; + $count = 100; + + $str_search = trim($str_search); + + $this->load->helper('text'); + + $query = $this->db->query( + "SELECT id, name, title, duration, user_id, views, thumbs_count, + default_thumb + FROM `videos` + WHERE title LIKE '%". $str_search . "%' + ORDER BY name + LIMIT ?, ?", // TODO summary order + array($offset, $count)); + + if ($query->num_rows() > 0) + $videos = $query->result_array(); + else + return NULL; + + foreach ($videos as & $video) + { + // P2P-Tube Video URL + $video['video_url'] = site_url(sprintf("watch/%d/%s", + $video['id'], $video['name'])); + + // Thumbnails + $video['thumbs'] = $this->get_thumbs($video['name'], + $video['thumbs_count']); + + // Ellipsized title + //$video['shorted_title'] = ellipsize($video['title'], 45, 0.75); + $video['shorted_title'] = character_limiter($video['title'], 50); + + // TODO: user information + $video['user_name'] = 'TODO'; + } + + return $videos; + } } /* End of file videos_model.php */ diff --git a/application/views/header.php b/application/views/header.php index d6cb618..7659482 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -28,8 +28,8 @@ endif ?> \ No newline at end of file + -- 2.20.1