/** * webpage_list * @param Int $page 頁數 */ public function webpage_list($page = 1) { $this->load->library('kals_resource/Webpage'); $this->load->library('kals_resource/Domain'); $user = get_context_user(); $user_id = $user->get_id(); // get domain's all pages $data = array(); //$webpage_list = Domain::get_all_domain_webpages(); //$domain = new Domain(); //$all_webpages = $domain->get_all_domain_webpages(); //array $all_webpages = Webpage::get_all_webpages_order_by_read($user_id, $page - 1); //test_msg("all_webpage", count($all_webpages)); //echo $all_webpages; $data['all_webpages'] = array(); $webpage_array = array(); //換頁 $webpage_count = Webpage::get_all_webpages_count(); $page_count = ceil($webpage_count / 10); $next_page = $page + 1; $prev_page = -1; if ($page > 1 && $page < $page_count) { $next_page = $page + 1; $prev_page = $page - 1; } else { if ($page == $page_count) { $next_page = -1; $prev_page = $page - 1; } } $data['page'] = $page; $data['next_page'] = $next_page; $data['prev_page'] = $prev_page; //test_msg( 'context_id = '.get_context_user()->get_id() ); //test_msg( '$user->get_id = '.$user_id.'//' ); //test_msg( $this->session->userdata('logged_in') ); //test_msg( 'session_user_id ='.$this->session->userdata('user_id') ); if ($user_id !== 0) { $unread_search = $this->db->query("SELECT DISTINCT topic_annotation.webpage_id, count(topic_annotation.is_topic_id) AS unread\nFROM \n(SELECT webpage2annotation.webpage_id, annotation_id AS is_topic_id,\n MAX(CASE WHEN res.update_timestamp IS NULL THEN annotation.update_timestamp\n ELSE res.update_timestamp\n END)AS annotation_timestamp\nFROM annotation JOIN webpage2annotation using (annotation_id) \n LEFT JOIN ( \n SELECT webpage_id, annotation_id AS res_id, annotation.topic_id AS res_topic_id, annotation.update_timestamp\n FROM annotation JOIN webpage2annotation using (annotation_id) \n WHERE topic_id IS NOT NULL ) AS res ON (annotation.annotation_id = res.res_topic_id)\nWHERE annotation.topic_id IS NULL \nGROUP BY webpage2annotation.webpage_id, is_topic_id) AS topic_annotation\n\nLEFT JOIN\n\n(select \nuser_id, webpage_id, note, max(log_timestamp) AS log_timestamp\n from log\nwhere\nuser_id = '" . $user_id . "' and\n( action = '16' OR action = '40') \ngroup by user_id, webpage_id, note) AS log_view_thread\n\nON log_view_thread.note like concat('%\"topic_id\":' , topic_annotation.is_topic_id , '%')\n\nGROUP BY topic_annotation.webpage_id, annotation_timestamp, topic_annotation.is_topic_id\nHAVING max(log_timestamp) < annotation_timestamp OR max(log_timestamp) IS NULL"); $unread_array = array(); foreach ($unread_search->result_array() as $row) { $webpage_id = $row['webpage_id']; $unread = $row['unread']; // TST MSG //echo $webpage_id . " - " . $unread_count . " / <br />"; $unread_array[$webpage_id] = $unread; } } // array:$all_webpages value:array array中為webpage_id foreach ($all_webpages as $webpage) { // get page's title and id $webpage_id = $webpage->get_id(); $webpage_array['webpage_id'] = $webpage_id; //test_msg($webpage_id); //continue; //$webpage = new Webpage($webpage_id); $webpage_title = $webpage->get_title(); //echo 'msg= '.$webpage_title.'<br>'; //msg $webpage_array['webpage_title'] = $webpage_title; // get page's annotation count $annotation_count = $webpage->get_written_annotations_count(); //$annotation_count = 0; $webpage_array['annotation_count'] = $annotation_count; // 判斷有無read if ($user_id !== 0) { if (isset($unread_array[$webpage_id])) { $webpage_array['is_unread'] = 'inline'; } else { $webpage_array['is_unread'] = 'none'; } } else { $webpage_array['is_unread'] = 'none'; } $data['all_webpages'][] = $webpage_array; } // session test msg /*echo $this->session->userdata('user_id').'/'; echo $this->session->userdata('user_name').'/'; echo $this->session->userdata('logged_in');*/ $this->load->view('mobile/mobile_views_header'); $this->load->view('mobile/webpage_list_view', $data); $this->load->view('mobile/mobile_views_footer'); }