4 * Class Catalog controls video hierarchy and searching
7 * @author Călin-Andrei Burloiu
9 class Catalog extends CI_Controller {
11 public function __construct()
13 parent::__construct();
15 //$this->lang->load('catalog');
18 public function index()
23 // Retrieve videos summary.
24 $this->load->model('videos_model');
25 foreach ($this->config->item('categories') as $id => $name)
28 $vs_data['videos'] = $this->videos_model->get_videos_summary(
29 $id, NULL, 0, $this->config->item('videos_per_row'));
32 $vs_data['category_name'] = $name;
33 $vs_data['category_id'] = $id;
34 $videos_summary['category_name'] = $name;
35 $videos_summary['category_title'] = $name ?
36 $this->lang->line("ui_categ_$name") : $name;
38 // Pagination (not required)
39 $vs_data['pagination'] = '';
41 $videos_summary['content'] = $this->load->view(
42 'catalog/videos_summary_view', $vs_data, TRUE);
43 $data['videos_summaries'][] = $videos_summary;
46 $params = array('title' => $this->config->item('site_name'),
51 //'metas' => array('description'=>'','keywords'=>'')
53 $this->load->library('html_head_params', $params);
58 $this->load->view('html_begin', $this->html_head_params);
59 $this->load->view('header', array(
60 'selected_menu' => 'home'
63 $main_params['content'] = $this->load->view('catalog/index_view', $data,
65 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
66 $this->load->view('main', $main_params);
68 $this->load->view('footer');
69 $this->load->view('html_end');
72 public function test()
74 $q = $this->input->get('q');
75 $q = ($q ? $q : 'nimic');
77 $w = $this->input->get('w');
78 $w = ($w ? $w : 'nimic');
83 public function category($category_name, $ordering = 'hottest', $offset = 0)
89 $category_data = Catalog::_get_category_data($category_name);
91 // Retrieve videos summary.
92 $this->load->model('videos_model');
93 $vs_data['videos'] = $this->videos_model->get_videos_summary(
94 $category_data['category_id'], NULL, intval($offset),
95 $this->config->item('videos_per_page'), $ordering);
97 $vs_data['ordering'] = $ordering;
100 $this->load->library('pagination');
101 $pg_config['base_url'] = site_url(
102 "catalog/category/$category_name/$ordering/");
103 $pg_config['uri_segment'] = 5;
104 $pg_config['total_rows'] = $this->videos_model->get_videos_count(
105 $category_data['category_id']);
106 $pg_config['per_page'] = $this->config->item('videos_per_page');
107 $this->pagination->initialize($pg_config);
108 $vs_data['pagination'] = $this->pagination->create_links();
109 $vs_data['category_name'] = $category_data['category_name'];
110 $vs_data['title'] = $category_data['category_title'];
112 $params = array('title' =>
113 $category_data['category_title'] . ' – '
114 . $this->config->item('site_name'),
118 //'metas' => array('description'=>'','keywords'=>'')
120 $this->load->library('html_head_params', $params);
125 $this->load->view('html_begin', $this->html_head_params);
126 $this->load->view('header', array(
127 'search_category_name' => $vs_data['category_name']
130 $main_params['content'] =
131 $this->load->view('catalog/videos_summary_view', $vs_data, TRUE);
132 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
133 $this->load->view('main', $main_params);
135 $this->load->view('footer');
136 $this->load->view('html_end');
139 public function search($search_query = "", $offset = 0, $category_name = NULL)
141 $this->load->model('videos_model');
142 $this->load->library('security');
144 // Redirect to an URL which contains search string if data was passed
145 // via POST method and not via URL segments.
146 $str_post_search = $this->input->post('search');
147 $str_post_category = $this->input->post('search-category');
148 if ($search_query === "" && $str_post_search !== FALSE)
150 redirect('catalog/search/'
151 . $this->videos_model->encode_search_query($str_post_search)
153 . ($str_post_category === FALSE ? '' : "/$str_post_category"));
160 // Search query is encoded for URL and must be decoded.
161 $enc_search_query = $search_query;
162 $search_query = $this->videos_model->decode_search_query($search_query);
164 // Security filtering
165 $search_query = $this->security->xss_clean($search_query);
166 $results_data['search_query'] = $search_query;
169 $results_data = Catalog::_get_category_data($category_name);
170 if ($results_data === NULL)
171 $results_data = array('category_id' => NULL);
174 $header_data['search_query'] = $search_query;
175 if ($category_name !== NULL)
177 $header_data['search_category_name'] = $results_data['category_name'];
180 // Check if search string is valid.
181 if (strlen($search_query) === 0)
183 //$results_data['videos'] = NULL;
184 $this->error($this->lang->line('error_search_query_empty'), $header_data);
189 // Retrieve search results.
190 $results_data['count'] = $this->videos_model->search_videos(
191 $search_query, 0, 0, $results_data['category_id']);
192 $results_data['videos'] = $this->videos_model->search_videos(
193 $search_query, intval($offset), $this->config->item(
194 'search_results_per_page'),
195 $results_data['category_id']);
196 if ($results_data['videos'] === NULL)
197 $results_data['videos'] = array();
200 $this->load->library('pagination');
201 $pg_config['base_url'] = site_url("catalog/search/$enc_search_query/");
202 $pg_config['uri_segment'] = 4;
203 $pg_config['total_rows'] = $results_data['count'];
204 $pg_config['per_page'] =
205 $this->config->item('search_results_per_page');
206 $this->pagination->initialize($pg_config);
207 $results_data['pagination'] = $this->pagination->create_links();
210 // HTML head parameters
211 $params = array('title' => 'Search Results – '
212 . $this->config->item('site_name'),
217 //'metas' => array('description'=>'','keywords'=>'')
219 $this->load->library('html_head_params', $params);
224 $this->load->view('html_begin', $this->html_head_params);
225 $this->load->view('header', $header_data);
228 $main_params['content'] =
229 $this->load->view('catalog/search_results_view', $results_data,
231 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
232 $this->load->view('main', $main_params);
234 $this->load->view('footer');
235 $this->load->view('html_end');
238 public function error($msg, $header_data)
240 $params = array('title' => 'Error – '
241 . $this->config->item('site_name'),
244 //'metas' => array('description'=>'','keywords'=>'')
246 $this->load->library('html_head_params', $params);
251 $this->load->view('html_begin', $this->html_head_params);
252 $this->load->view('header', $header_data);
254 $main_params['content'] = $this->load->view('error_view', array(
255 'msg' => $msg), TRUE);
256 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
257 $this->load->view('main', $main_params);
259 $this->load->view('footer');
260 $this->load->view('html_end');
263 public static function _get_category_data($category_name)
265 $ci = & get_instance();
267 if ($category_name === NULL)
270 $categories = $ci->config->item('categories');
271 $category_id = array_search($category_name, $categories);
272 $results_data['category_name'] = $category_name;
273 $results_data['category_id'] = $category_id;
274 $results_data['category_title'] = $category_name ?
275 $ci->lang->line("ui_categ_$category_name") : $category_name;
277 return $results_data;
282 /* End of file catalog.php */
283 /* Location: ./application/controllers/catalog.php */