public function profile($username, $videos_offset = 0) { // TODO handle user not found $user_id = $this->session->userdata('user_id'); if ($user_id) { if (intval($user_id) & USER_ROLE_ADMIN) { $allow_unactivated = TRUE; } else { $allow_unactivated = FALSE; } } else { $allow_unactivated = FALSE; } $this->load->config('localization'); $this->load->helper('date'); $this->lang->load('date'); // ** // ** LOADING MODEL // ** // Logged in user time zone $time_zone = $this->session->userdata('time_zone'); // User data $userdata = $this->users_model->get_userdata($username); $userdata['roles'] = Users_model::roles_to_string($userdata['roles']); $country_list = $this->config->item('country_list'); $userdata['country_name'] = $country_list[$userdata['country']]; $userdata['last_login'] = human_gmt_to_human_local($userdata['last_login'], $time_zone); $userdata['time_zone'] = $this->lang->line($userdata['time_zone']); // User's videos $this->load->model('videos_model'); $vs_data['videos'] = $this->videos_model->get_videos_summary(NULL, $username, intval($videos_offset), $this->config->item('videos_per_page'), 'hottest', $allow_unactivated); // Pagination $this->load->library('pagination'); $pg_config['base_url'] = site_url("user/profile/{$username}/"); $pg_config['uri_segment'] = 4; $pg_config['total_rows'] = $this->videos_model->get_videos_count(NULL, $username, $allow_unactivated); $pg_config['per_page'] = $this->config->item('videos_per_page'); $this->pagination->initialize($pg_config); $vs_data['pagination'] = $this->pagination->create_links(); $vs_data['title'] = NULL; $vs_data['category_name'] = ''; // TODO videos_summary with AJAX $params = array('title' => $this->lang->line('user_appelation') . ' ' . $username . ' – ' . $this->config->item('site_name'), 'css' => array('catalog.css'), 'js' => array('jquery.ui.thumbs.js')); $this->load->library('html_head_params', $params); // Current user profile tab $tab = !$videos_offset ? 0 : 1; // ** // ** LOADING VIEWS // ** $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', array()); $vs = $this->load->view('catalog/videos_summary_view', $vs_data, TRUE); $main_params['content'] = $this->load->view('user/profile_view', array('userdata' => $userdata, 'videos_summary' => $vs, 'tab' => $tab), TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); $this->load->view('footer'); $this->load->view('html_end'); }
/** * Retrieves comments for a video. * * @param int $video_id * @param int $offset * @param int $count * @param string $ordering control comments ording by these possibilities: * <ul> * <li><strong>'hottest':</strong> newest most appreciated first. An * appreciated comment is one which has a bigger * score = likes - dislikes.</li> * <li><strong>'newest':</strong> newest first.</li> * </ul> * @return array an array with comments */ public function get_video_comments($video_id, $offset, $count, $ordering = 'newest') { $this->load->helper('date'); $cond_hottest = ''; // Ordering switch ($ordering) { case 'newest': $order_statement = "ORDER BY time DESC"; break; case 'hottest': $order_statement = "ORDER BY score DESC, time DESC"; $cond_hottest = "AND c.likes + c.dislikes > 0"; break; default: $order_statement = ""; } $query = $this->db->query("SELECT c.*, u.username, u.time_zone, (c.likes + c.dislikes) AS score\n\t\t\t\tFROM `videos_comments` c, `users` u\n\t\t\t\tWHERE c.user_id = u.id AND video_id = {$video_id} {$cond_hottest}\n\t\t\t\t{$order_statement}\n\t\t\t\tLIMIT {$offset}, {$count}"); if ($query->num_rows() == 0) { return array(); } $comments = $query->result_array(); foreach ($comments as &$comment) { $comment['local_time'] = human_gmt_to_human_local($comment['time'], $comment['time_zone']); } return $comments; }