Beispiel #1
0
 /**
  * annotation_topics
  * @param Int $webpage_id 不可以是空值
  */
 public function annotation_topics($webpage_id)
 {
     //$topic_id = NULL
     $this->load->library('kals_resource/Webpage');
     $this->load->library('kals_resource/Annotation');
     $data = array();
     $webpage = new Webpage($webpage_id);
     // 取得文章標題
     $title = $webpage->get_title();
     $data['title'] = $title;
     // 取得網頁中所有的標註並設定collection的排序方式
     $annotation_order = 10;
     $annotation_desc = TRUE;
     $written_annotations = $webpage->get_written_annotations($annotation_order, $annotation_desc);
     $data['written_annotations'] = array();
     $array = array();
     // rss->user_id
     /*$session_user = $this->session->userdata('user_id'); 
       if (isset($session_user)) {
           $user_id = get_context_user()->get_id();
       }
       else {
           $user_id = 0;       
       }*/
     $user = get_context_user();
     //echo 'get_context_user ='******'//';
     //echo $this->session->userdata('logged_in').'//';
     //echo 'session_user_id ='.$this->session->userdata('user_id');
     // 查詢未讀過的annotation
     //if ( $user_id !== 0 ){
     if (isset($user)) {
         $user_id = $user->get_id();
         $unread_annotation = $this->db->query("SELECT topic_annotation.webpage_id, topic_annotation.is_topic_id, annotation_timestamp, max(log_timestamp) as log_timestamp\n                                                FROM \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 \n                                                      FROM 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 AND webpage_id = '" . $webpage_id . "') AS res ON (annotation.annotation_id = res.res_topic_id)\n                                                      WHERE annotation.topic_id IS NULL AND webpage2annotation.webpage_id = '" . $webpage_id . "'  \n                                                      GROUP BY webpage2annotation.webpage_id, is_topic_id) AS topic_annotation\n                                                LEFT JOIN\n                                                      (SELECT user_id, webpage_id, note, max(log_timestamp) AS log_timestamp\n                                                       FROM log\n                                                       WHERE user_id = '" . $user_id . "' AND webpage_id = '" . $webpage_id . "' AND (action = '16' OR action = '41') \n                                                       GROUP BY user_id, webpage_id, note) AS log_view_thread\n                                                             ON log_view_thread.note like concat('%\"topic_id\":' , topic_annotation.is_topic_id , '%')\n                                                GROUP BY topic_annotation.webpage_id, is_topic_id, annotation_timestamp\n                                                HAVING max(log_timestamp) < annotation_timestamp OR max(log_timestamp) IS NULL");
         $unread_array = array();
         // 存放unread topic id(topic and res)
         foreach ($unread_annotation->result_array() as $row) {
             $unread_id = $row['is_topic_id'];
             $unread_array[$unread_id] = $row['is_topic_id'];
         }
     }
     //if (isset($user)) {
     foreach ($written_annotations as $annotation) {
         $anchor_text = $annotation->get_anchor_text();
         //topic
         //$array['note'] = $annotation->get_note(); //note
         // get annotation id
         $annotation_id = $annotation->get_id();
         $array['annotation_id'] = $annotation_id;
         // 控制anchor text顯示長度
         $anchor_length = $annotation->get_scope_length();
         if ($anchor_length > 10) {
             $array['anchor_text'] = mb_substr($anchor_text, 0, 8, "utf-8");
         } else {
             $array['anchor_text'] = $anchor_text;
         }
         $respond_collection = $annotation->get_topic_respond_length();
         //response
         $array['respond_count'] = $respond_collection;
         //取得長度(only res)
         // get last response timestamp
         if ($array['respond_count'] != 0) {
             $last_respond = $annotation->get_last_respond();
             $last_respond_id = $last_respond->get_id();
             $last_item = new $annotation($last_respond_id);
             $last_timestamp = $last_item->get_create_timestamp();
         } else {
             $last_timestamp = $annotation->get_create_timestamp();
         }
         $last_short_timestamp = substr($last_timestamp, 0, 10);
         $array['timestamp'] = $last_short_timestamp;
         //是否為訪客
         //if ( $user_id !== 0 ){
         if (isset($user)) {
             $user_id = $user->get_id();
             // 判斷有無unread annotation
             if (isset($unread_array[$annotation_id])) {
                 $array['is_unread'] = 'inline';
                 //echo $annotation_id;
                 //echo 'Y <br>';
             } else {
                 $array['is_unread'] = 'none';
                 //echo $annotation_id;
                 //echo 'N <br>';
             }
         } else {
             $array['is_unread'] = 'none';
         }
         //else {
         $data['written_annotations'][] = $array;
     }
     // log區 -使用mobile裝置瀏覽topic list- action = 40
     $this->_log_annotation_thread($webpage_id);
     // 把語系檔存入變數中,傳入view
     $data['lang'] = $this->lang;
     $this->load->view('mobile/mobile_views_header');
     $this->load->view('mobile/annotation_topic_view', $data);
     $this->load->view('mobile/mobile_views_footer');
 }