X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fmodels%2Fvideos_model.php;h=0d9fe7bf8585a4cd926819f633b41037c0700ff5;hb=e788f88e8475e9c87eef355c71abed3c329c4c0b;hp=1ba9e8f67bbd516f6ef4d5134d882cf5c5eebd36;hpb=954fc0210d9151cb86ca4dad6a955f59ba135915;p=living-lab-site.git diff --git a/application/models/videos_model.php b/application/models/videos_model.php index 1ba9e8f..0d9fe7b 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -16,8 +16,6 @@ class Videos_model extends CI_Model { $this->load->library('singleton_db'); $this->db = $this->singleton_db->connect(); } - - $this->load->helper('url'); } /** @@ -200,6 +198,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); + + $query = $this->db->query( + "SELECT id, name, title, duration, user_id, views, thumbs_count, + default_thumb + FROM `videos` + WHERE MATCH (title, description, tags) AGAINST (?) + ORDER BY name + LIMIT ?, ?", + array($str_search, $offset, $count)); + + if ($query->num_rows() > 0) + $videos = $query->result_array(); + else + return NULL; + + $this->load->helper('text'); + + 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 */