minimal search feature added
[living-lab-site.git] / application / controllers / catalog.php
1 <?php
2
3 /**
4  * Class Catalog controls video hierarchy and searching
5  *
6  * @category    Controller
7  * @author              Călin-Andrei Burloiu
8  */
9 class Catalog extends CI_Controller {
10         
11         public function __construct()
12         {
13                 parent::__construct();
14                 
15                 //$this->lang->load('catalog');
16         }       
17         
18         public function index()
19         {
20                 // **
21                 // ** LOADING MODEL
22                 // **
23                 // Retrieve videos summary.
24                 $this->load->model('videos_model');
25                 foreach ($this->config->item('categories') as $id => $name)
26                 {
27                         // Videos
28                         $vs_data['videos'] = $this->videos_model->get_videos_summary(
29                                 $id, 0, $this->config->item('videos_per_row'));
30                         
31                         // Category
32                         $vs_data['category_name'] = $name;
33                         $vs_data['category_title'] = $name ?
34                                 $this->lang->line("ui_categ_$name") : $name;
35                         $vs_data['category_id'] = $id;
36                         
37                         // Pagination (not required)
38                         $vs_data['pagination'] = '';
39                         
40                         $data['videos_summaries'][] = 
41                                 $this->load->view('catalog/videos_summary_view', 
42                                 $vs_data, TRUE);
43                 }
44                 
45                 $params = array(        'title' => $this->config->item('site_name'),
46                                                         'css' => array(
47                                                                 'catalog.css'
48                                                         ),
49                                                         //'js' => array(),
50                                                         //'metas' => array('description'=>'','keywords'=>'')
51                                                         );
52                 $this->load->library('html_head_params', $params);
53                 
54                 // **
55                 // ** LOADING VIEWS
56                 // **
57                 $this->load->view('html_begin', $this->html_head_params);
58                 $this->load->view('header', array('selected_menu' => 'home'));
59                 
60                 $main_params['content'] = $this->load->view('catalog/index_view', $data, TRUE);
61                 $main_params['side'] = $this->load->view('side_default.php', NULL, TRUE);
62                 $this->load->view('main', $main_params);
63                 
64                 $this->load->view('footer');
65                 $this->load->view('html_end');
66         }
67         
68         public function test($page = 0)
69         {
70                 $params = array(        'title' => 'Test - '. $this->config->item('site_name'),
71                                                         //'css' => array(),
72                                                         //'js' => array(),
73                                                         //'metas' => array('description'=>'','keywords'=>'')
74                         );
75                 $this->load->library('html_head_params', $params);
76                 
77                 // **
78                 // ** LOADING VIEWS
79                 // **
80                 $this->load->view('html_begin', $this->html_head_params);
81                 $this->load->view('header', array('selected_menu' => 'home'));
82                 
83                 $this->load->view('echo', array('output'=>'Test Page', 'clear'=>TRUE));
84                 
85                 $this->load->view('footer');
86                 $this->load->view('html_end');
87         }
88         
89         public function category($category_name, $offset = 0)
90         {
91                 // **
92                 // ** LOADING MODEL
93                 // **
94                 // Video Category
95                 $categories = $this->config->item('categories');
96                 $category_id = array_search($category_name, $categories);
97                 $vs_data['category_name'] = $category_name;
98                 $vs_data['category_id'] = $category_id;
99                 $vs_data['category_title'] = $category_name ?
100                 $this->lang->line("ui_categ_$category_name") : $category_name;          
101                 
102                 // Retrieve videos summary.
103                 $this->load->model('videos_model');
104                 $vs_data['videos'] = $this->videos_model->get_videos_summary(
105                         $vs_data['category_id'], intval($offset),
106                         $this->config->item('videos_per_page'));
107                 
108                 // Pagination
109                 $this->load->library('pagination');
110                 $pg_config['base_url'] = site_url("catalog/category/$category_name/");
111                 $pg_config['uri_segment'] = 4;
112                 $pg_config['total_rows'] = $this->videos_model->get_videos_count(
113                         $category_id);
114                 $pg_config['per_page'] = $this->config->item('videos_per_page');
115                 $this->pagination->initialize($pg_config);
116                 $vs_data['pagination'] = $this->pagination->create_links();
117                 
118                 // Video Summary
119                 $data['video_summary'] = $this->load->view('catalog/videos_summary_view',
120                         $vs_data, TRUE);
121                 
122                 $params = array(        'title' => $this->config->item('site_name'),
123                                                         'css' => array(
124                                                                 'catalog.css'
125                                                         ),
126                                                         //'js' => array(),
127                                                         //'metas' => array('description'=>'','keywords'=>'')
128                                                         );
129                 $this->load->library('html_head_params', $params);
130                 
131                 // **
132                 // ** LOADING VIEWS
133                 // **
134                 $this->load->view('html_begin', $this->html_head_params);
135                 $this->load->view('header');
136                 
137                 $main_params['content'] = $this->load->view('catalog/category_view', $data, TRUE);
138                 $main_params['side'] = $this->load->view('side_default.php', NULL, TRUE);
139                 $this->load->view('main', $main_params);
140                 
141                 $this->load->view('footer');
142                 $this->load->view('html_end');
143         }
144         
145         public function search($str_search = "")
146         {
147                 // TODO get query string from URL.
148                 $str_search = $this->input->post('search', TRUE);
149
150                 // **
151                 // ** LOADING MODEL
152                 // **
153                 // Video Category
154                 $vs_data['category_name'] = "";
155                 $vs_data['category_title'] = "Search Results for &laquo;$str_search&raquo;";
156
157                 // Retrieve videos summary.
158                 $this->load->model('videos_model');
159                 $vs_data['videos'] = $this->videos_model->search_videos(
160                         $str_search);
161                 if ($vs_data['videos'] === NULL)
162                         $vs_data['videos'] = array();
163
164                 $vs_data['pagination'] = '';
165                 
166                 // Video Summary
167                 $data['video_summary'] = $this->load->view('catalog/videos_summary_view',
168                         $vs_data, TRUE);
169                 
170                 $params = array(        'title' => $this->config->item('site_name'),
171                                                         'css' => array(
172                                                                 'catalog.css'
173                                                         ),
174                                                         //'js' => array(),
175                                                         //'metas' => array('description'=>'','keywords'=>'')
176                                                         );
177                 $this->load->library('html_head_params', $params);
178                 
179                 // **
180                 // ** LOADING VIEWS
181                 // **
182                 $this->load->view('html_begin', $this->html_head_params);
183                 $this->load->view('header');
184                 
185                 $main_params['content'] = $this->load->view('catalog/category_view', $data, TRUE);
186                 $main_params['side'] = $this->load->view('side_default.php', NULL, TRUE);
187                 $this->load->view('main', $main_params);
188                 
189                 $this->load->view('footer');
190                 $this->load->view('html_end');
191
192         }
193 }
194
195 /* End of file catalog.php */
196 /* Location: ./application/controllers/catalog.php */