users can add pictures to their profiles; users can like and dislike videos
[living-lab-site.git] / application / controllers / video.php
1 <?php
2
3 /**
4  * Class Video controls video items handling: watching, commenting, rating,
5  * adding etc.
6  *
7  * @category    Controller
8  * @author              Călin-Andrei Burloiu
9  */
10 class Video extends CI_Controller {
11
12         public function __construct()
13         {
14                 parent::__construct();
15                 
16                 $this->lang->load('video');
17         }
18         
19         public function index()
20         {
21                 
22         }
23         
24         /**
25          * The page used for watching a video
26          *
27          * @param       string $id      DB id of the video
28          * @param       string $name    `name` of the video from DB
29          * @param       string $plugin  video plugin ('ns-vlc', 'ns-html5'). If it's set 
30          * to NULL or 'auto', the plugin is automatically selected.
31          */
32         public function watch($id, $name = NULL, $plugin = NULL)
33         {
34                 // **
35                 // ** LOADING MODEL
36                 // **
37                 // Retrieve video information.
38                 $this->load->model('videos_model');
39                 $this->videos_model->inc_views($id);
40                 $data['video'] = $this->videos_model->get_video($id, $name);
41                 $categories = $this->config->item('categories');
42                 $data['video']['category_name'] = 
43                         $categories[ $data['video']['category_id'] ];
44                 $data['plugin_type'] = ($plugin === NULL ? 'auto' : $plugin);
45                 $data['user_id'] = $this->session->userdata('user_id');
46                 if ($data['user_id'] === FALSE)
47                         $data['user_id'] = '';
48                 
49                 // Display page.
50                 $params = array(        'title' => $data['video']['title'] . ' &ndash; '
51                                                                 . $this->config->item('site_name'),
52                                                         'css' => array(
53                                                                 'jquery.ui.nsvideo.css',
54                                                                 'video.css'
55                                                         ),
56                                                         'js' => array(
57                                                                 'jquery.ui.nsvideo.js'
58                                                         ),
59                                                         //'metas' => array('description'=>'','keywords'=>'')
60                                                         );
61                 $this->load->library('html_head_params', $params);
62                 
63                 // Preloading video plugin.
64                 // TODO plugin auto: type and format
65                 if ($data['plugin_type'] == 'auto')
66                         $data['plugin_type'] = 'ns-html5';
67                 $data['asset_index'] = 0;
68                 
69                 // TODO remove old AJAX plugin content
70 //              $data['plugin_content'] = $this->_plugin('ns-html5', 
71 //                      $data['video']['url'][0], TRUE);
72                 
73                 // **
74                 // ** LOADING VIEWS
75                 // **
76                 $this->load->view('html_begin', $this->html_head_params);
77                 $this->load->view('header');
78                 
79                 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
80                 $this->load->view('video/watch_view', $data);
81                 
82                 $this->load->view('footer');
83                 $this->load->view('html_end');
84         }
85         
86         /**
87          * Increments likes count for video with the specified id and returns to 
88          * the client as plain text the number if likes. 
89          * 
90          * @param string $action        'like' or 'dislike'
91          * @param string $video_id
92          * @param string $user_id
93          */
94         public function ajax_vote($action, $video_id, $user_id = NULL)
95         {
96                 $video_id = intval($video_id);
97                 $user_id = intval($user_id);
98                 $this->load->model('videos_model');
99                 
100                 $res = $this->videos_model->vote($video_id, $user_id, 
101                         (strcmp($action, 'like') == 0 ? TRUE : FALSE));
102                 
103                 if ($res !== -1)
104                         echo $res;
105         }
106         
107         /**
108          * AJAX page which retrieves a video plugin.
109          *
110          * The view associated with this controller should be parameter type
111          * concatenated with '_plugin_view' and must be located in
112          * 'application/views/video'.
113          *
114          * @param       string $type    'ns-vlc', 'ns-html5'
115          */
116         public function plugin($type)
117         {
118                 $url = $this->input->post('url', TRUE);
119                 
120                 $this->_plugin($type, $url);
121         }
122         
123         /**
124          * Video plugin controller
125          *
126          * See plugin function for details. If the second parameter is TRUE
127          * the output is return instead of being displayed (used in preloading).
128          */
129         public function _plugin($type, $url, $return_output=FALSE)
130         {       
131                 if ($type == 'ns-html5')
132                         $data['url'] = 'tribe://' . $url;
133                 else if ($type == 'ns-vlc')
134                         $data['url'] = $url;
135                 
136                 $output = $this->load->view('video/'. $type . '_plugin_view', $data, 
137                         $return_output);
138                 
139                 if ($return_output)
140                         return $output;
141         }
142         
143 }
144
145 /* End of file video.php */
146 /* Location: ./application/controllers/video.php */