minimal search feature added
authorP2P-Next Koala <p2p-next@koala.cs.pub.ro>
Fri, 2 Sep 2011 08:36:40 +0000 (11:36 +0300)
committerP2P-Next Koala <p2p-next@koala.cs.pub.ro>
Fri, 2 Sep 2011 08:36:40 +0000 (11:36 +0300)
application/controllers/catalog.php
application/models/videos_model.php
application/views/header.php

index a22a1e8..0248f9e 100644 (file)
@@ -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 '<h1>Search not yet implemented</h1>';
+               // 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 &laquo;$str_search&raquo;";
+
+               // 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');
+
        }
 }
 
index 1ba9e8f..c887b70 100644 (file)
@@ -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 */
index d6cb618..7659482 100644 (file)
@@ -28,8 +28,8 @@ endif ?>
 <div id="header">
        <!-- TODO: resize logo image-->
        <a href="<?php echo site_url() ?>" id="logo"><img src="<?php echo site_url('img/p2p-next--big.png') ?>" alt="P2P-Next" width="119" height="48" /></a>
-       <form id="quick-search">
+       <form id="quick-search" action="<?php echo site_url('catalog/search') ?>" method="POST">
                <label for="quick-search-box"><?php echo $this->lang->line('ui_search') . ': ' ?></label>
-               <input type="text" id="quick-search-box" name="quick-search-box" disabled="disabled" value="not yet implemented" />
+               <input type="text" id="search" name="search" value="" />
        </form>
-</div>
\ No newline at end of file
+</div>