homepage, categories pages; javascript and stylesheets renamed to js and css resp.
[living-lab-site.git] / application / controllers / catalog.php
index e6d2c0d..3447167 100644 (file)
@@ -8,15 +8,25 @@
  */
 class Catalog extends CI_Controller {
        
+       public function __construct()
+       {
+               parent::__construct();
+       }       
+       
        public function index()
        {
                // Retrieve videos summary.
+               $data['categories'] = $this->config->item('categories');
                $this->load->model('videos_model');
-               $data['videos'] = $this->videos_model->get_videos_summary();
+               foreach ($data['categories'] as $id => $name)
+               {
+                       $data['videos'][$id] = $this->videos_model->get_videos_summary(
+                               $id, 0, $this->config->item('videos_per_row'));
+               }
                
                $params = array(        'title' => $this->config->item('site_name'),
-                                                       //'stylesheets' => array(),
-                                                       //'javascripts' => array(),
+                                                       'css' => array('catalog.css'),
+                                                       //'js' => array(),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
                $this->load->library('html_head_params', $params);
@@ -29,25 +39,41 @@ class Catalog extends CI_Controller {
                $this->load->view('html_end');
        }
        
-       public function test()
+       public function test($page = 0)
        {
                $this->load->helper('url');
+               $this->load->library('pagination');
                
-               echo '<a href="/">link</a>';
+               $config['base_url'] = site_url('catalog/test/');
+               $config['total_rows'] = '160';
+               $this->pagination->initialize($config);
+               echo $this->pagination->create_links();
        }
        
-       public function category($category_id)
+       public function category($category_id, $offset = 0)
        {
                // Retrieve videos summary.
                $this->load->model('videos_model');
-               $data['videos'] = $this->videos_model->get_videos_summary($category_id);
+               $data['videos'] = $this->videos_model->get_videos_summary(
+                       $category_id, intval($offset),
+                       $this->config->item('videos_per_page'));
                $categories = $this->config->item('categories');
                $data['category'] = $categories[$category_id];
                $data['category_id'] = $category_id;
                
+               // Pagination
+               $this->load->library('pagination');
+               $pg_config['base_url'] = site_url("catalog/category/$category_id/");
+               $pg_config['uri_segment'] = 4;
+               $pg_config['total_rows'] = $this->videos_model->get_videos_count(
+                       $category_id);
+               $pg_config['per_page'] = $this->config->item('videos_per_page');
+               $this->pagination->initialize($pg_config);
+               $data['pagination'] = $this->pagination->create_links();
+               
                $params = array(        'title' => $this->config->item('site_name'),
-                                                       'stylesheets' => array('catalog.css'),
-                                                       //'javascripts' => array(),
+                                                       'css' => array('catalog.css'),
+                                                       //'js' => array(),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
                $this->load->library('html_head_params', $params);