/** * Action範例 * * @param Array $data 由KALS_controller傳入的資料,組成是關連式的陣列 * * [Controller的JSON格式] * _data = { * "field": "value" * }; * * //取用範例 * _data["field]; //回傳value * * [Model的Array格式] * $data = array( * "field" => "value" * ); * * $data["field"]; //回傳value * * @return Array 要回傳給KALS_controller的資料 * 一樣是以關聯式陣列組成 * */ public function open($data) { // ----------------------- // 從現在的網頁來計算標註跟使用者 $webpage = $this->get_current_webpage(); $data["annotation_count"] = $webpage->get_written_annotations_count(); $data["user_count"] = $webpage->get_written_users_count(); // ------------------ // 取出最近的標註 $search = new Search_annotation_collection(); $search->set_target_webpage($webpage->get_id()); $search->set_check_authorize(FALSE); $limit = 5; $search->set_limit($limit); $order_type_id = 6; $desc = TRUE; $search->add_order($order_type_id, $desc); $data["last_annotation"] = array(); foreach ($search as $index => $annotation) { //$json = $annotation->export_data(); $json = $annotation; if ($index == 0) { //$last_annotation = $json; $data["last_annotation_id"] = $annotation->get_id(); $data["last_annotation_timestamp"] = $annotation->get_update_timestamp(); } // 一一加入標註 $data["last_annotation"][] = $json; } // 也可以最後一口氣取出所有標註 $data["last_annotation"] = $search; // ------------------- // 依照標註數量來判斷熱門程度 $activity = "bad"; if ($data["annotation_count"] > 20) { $activity = "good"; } else { if ($data["annotation_count"] > 5) { $activity = "normal"; } } $data["activity"] = "Good"; return $data; }
/** * 讀取RSS * * 範例:http://localhost/kals/web_apps/rss/webpage/1573 */ public function webpage($webpage_id = NULL) { if (is_null($webpage_id)) { $webpage = get_context_webpage(); $webpage_id = $webpage->get_id(); redirect("/web_apps/rss/webpage/" . $webpage_id); return; } $this->load->library('kals_resource/Webpage'); $this->load->library('kals_resource/Annotation'); $this->load->library('search/Search_annotation_collection'); $this->lang->load('kals_web_apps'); //語系 //echo $webpage_id; $webpage = new Webpage($webpage_id); //$search = $webpage->get_search_annotation(); $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_id); $search->set_limit(10); $order_type_id = 6; $desc = TRUE; $search->add_order($order_type_id, $desc); // ------------------------------ // 以下開始建立RSS清單 // // 請使用php-rss-writer來建立 // // 專案首頁:https://github.com/suin/php-rss-writer // 程式碼位置:https://github.com/suin/php-rss-writer/tree/master/Source/Suin/RSSWriter // ------------------------------ $this->load->library("web_apps/Suin/RSSWriter/Feed"); $this->load->library("web_apps/Suin/RSSWriter/Channel"); $this->load->library("web_apps/Suin/RSSWriter/Item"); $feed = new Feed(); $webpage_title = $webpage->get_title(); //$webpage_topics_path = '/mobile_apps/annotation_topics/webpade_id/'.$webpage_id; //$webpage_topics_url = get_kals_base_url($webpage_topics_path); //$webpage_topics_url = site_url('/mobile_apps/annotation_topics/webpade_id/'.$webpage_id); //$webpage_topics_url = $webpage->get_url() . "#mobile=true"; $webpage_topics_url = get_kals_base_url("mobile_apps/redirect/load/" . $webpage_id); $channel = new Channel(); $channel->title($webpage_title)->description("Channel Description")->url($webpage_topics_url)->appendTo($feed); foreach ($search as $annotation) { $item = new Item(); $type = $annotation->get_type(); $type_name = $type->get_name(); $type_show; if ($type_name != 'annotation.type.custom') { //自定標註顯示 $type_show = $this->lang->line("web_apps." . $type_name); } else { $type_show = $type->get_custom_name(); } // anchor text // user name // date // annotation type // note $annotation_id = $annotation->get_id(); if (isset($annotation_id)) { //$topic_array = $this->db->query("SELECT topic_id // FROM annotation // WHERE annotation_id ='".$annotation_id."'"); $topic_array = $this->db->select("topic_id")->from("annotation")->where("annotation_id", $annotation_id)->where("deleted", "false")->get(); } foreach ($topic_array->result_array() as $row) { $topic_id = $row['topic_id']; } /** * @author Pulipuli Chen 20140429 * 要記得沒有topic的標註啊…… */ $topic_id = trim($topic_id); if ($topic_id == "") { $topic_id = $annotation_id; } //$item_url = 'http://140.119.61.137/kals/mobile/annotation_thread/'.$topic_id.'#annotation_'.$annotation_id; //$annotation_thread_path = "mobile_apps/annotation_thread/topic_id/".$topic_id."#annotation_".$annotation_id; //$item_url = site_url($annotation_thread_path); //$item_url = get_kals_base_url($annotation_thread_path); //$item_url = $webpage->get_url() . "#mobile=true&topic_id=" . $topic_id . "&annotation_id=" . $annotation_id; $item_url = get_kals_base_url("mobile_apps/redirect/load/" . $webpage_id . "/" . $topic_id . "/" . $annotation_id); //$item_url = $_SERVER["HTTP_HOST"] //test_msg($_SERVER["HTTP_HOST"]); $item->title("[" . $type_show . "] " . '"' . $annotation->get_anchor_text() . '"')->description("<div> " . $this->lang->line("web_apps.window.content.search.field.author") . ": " . $annotation->get_user()->get_name() . " </div>" . "<div> " . $this->lang->line("web_apps.window.content.search.field.author") . ": " . $annotation->get_user()->get_name() . " </div>" . "<div>" . $annotation->get_note() . " </div> \n ")->url($item_url)->appendTo($channel); } echo $feed; }
/** * Action範例 * * @param Array $data 由KALS_controller傳入的資料,組成是關連式的陣列 * * [Controller的JSON格式] * _data = { * "field": "value" * }; * * //取用範例 * _data["field]; //回傳value * * [Model的Array格式] * $data = array( * "field" => "value" * ); * * $data["field"]; //回傳value * * @return Array 要回傳給KALS_controller的資料 * 一樣是以關聯式陣列組成 * */ public function get_heading_annotation($data) { $structure = $data["structure"]; // [14, 56, 70] $current_type = $data["current_type"]; //test_msg($data); // 1. 搜尋指定類型的標註 $search = new Search_annotation_collection(); // 1.1. 指定現在的網頁 $webpage = $this->get_current_webpage(); $search->set_target_webpage($webpage->get_id()); // 1.2. 指定現在要搜尋的標註類型 //test_msg("current_type", $current_type); //$current_type = intval($current_type); $search->set_target_type($current_type); // 2. 取得一個Annotation_collection $annotation_collection = $search; //test_msg("Data found?", $search->length() ); // 2.1. 準備一下待會要儲存標題與標註數量的陣列 $heading_list = array(); if (isset($data["order_by_article"]) && $data["order_by_article"] !== TRUE) { } else { for ($i = 0; $i < count($structure); $i++) { $heading_list[$i] = 0; } } // 3. 迴圈,一一檢查每一個Annotation $total_count = 0; foreach ($search as $index => $annotation) { // 4. 取出Annotation的位置,找出from_index $scope_coll = $annotation->get_scopes(); $from_index = $scope_coll->get_first_index(); //test_msg($from_index); // 5. 判斷他是位於哪一個章節 // [14, 56, 70] $current_heading_number = 0; foreach ($structure as $heading_number => $last_index) { //test_msg("foreach", array($from_index, $last_index, $heading_number)); if ($from_index < $last_index) { $current_heading_number = $heading_number; break; } } // 6. 組成回傳的資料 $count = 1; if (key_exists($current_heading_number, $heading_list) === TRUE) { $count = $heading_list[$current_heading_number]; $count = $count + 1; } //test_msg("heading_list", array($current_heading_number, $count)); $heading_list[$current_heading_number] = $count; $total_count++; } // array( // 1 => 4, // 5 => 9, // 12 => 1 // ) // 7. 排序 if (isset($data["order_by_article"]) && $data["order_by_article"] !== TRUE) { arsort($heading_list); } // array( // 5 => 9, // 1 => 4, // 12 => 1 // ) // 7.1. 排序之後,輸出成JavaScript要的data形式 $heading_data = array(); if (is_array($heading_list)) { foreach ($heading_list as $heading_number => $count) { $item = array("heading_number" => $heading_number, "type_count" => $count); //test_msg("item", $item); //$return_data[] = $item; array_push($heading_data, $item); } } $return_data = array('heading_data' => $heading_data, 'total_count' => $total_count); // 8. 回傳 //test_msg($return_data); return $return_data; //test_msg($data); //return $heading_list; }
function search_without_context() { $user_found = new User(225); $user_not_found = new User(9999); $url_nf = 'http://www.plurk.com/p/6c5cdt#response-1777726347'; $webpage_nf = $this->webpage->create($url_nf); $url_f = 'http://www.plurk.com/p/67k6st'; $webpage_f = $this->webpage->create($url_f); $text = '話說回來,其實本篇主題是要講,目前階段是Search,加入了Collection概念,並強化應用Active Record的方式之後,應該是更強大,卻也複雜到一種境界。'; $target_scope_nf = new Annotation_scope_collection(); $target_scope_nf->add_scope($this->annotation_scope->create_scope(18, 33, $text, $webpage_f)); $target_scope_f = new Annotation_scope_collection(); $target_scope_f->add_scope($this->annotation_scope->create_scope(3, 20, $text, $webpage_f)); $target_scope_f->add_scope($this->annotation_scope->create_scope(26, 40, $text, $webpage_f)); $overlap_scope_nf = new Annotation_scope_collection(); $overlap_scope_nf->add_scope($this->annotation_scope->create_scope(23, 25, $text, $webpage_f)); $overlap_scope_f = new Annotation_scope_collection(); $overlap_scope_f->add_scope($this->annotation_scope->create_scope(23, 25, $text, $webpage_f)); $overlap_scope_f->add_scope($this->annotation_scope->create_scope(39, 40, $text, $webpage_f)); //----------------------------------------------------------- $search = new Search_annotation_collection(); $search->set_target_user($user_not_found); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤user_id,看length()'); $search = new Search_annotation_collection(); $search->set_target_user($user_found); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的user_id,看length()'); $search = new Search_annotation_id_collection(); $search->set_target_user($user_found); $this->unit->run($search->length(), 2, 'Search_annotation_id_collection,搜尋正確的user_id,看length(),耗費時間應該比Search_annotation_collection還短'); $this->unit->run($search->get_item(0), 'is_string', 'Search_annotation_id_collection,搜尋正確的user_id,get_item(),值應該是id'); //---- $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的webpage,看length()'); $this->unit->run($webpage_f->get_id(), 138, '先檢查webpage正確的id'); $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_f); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋正確的webpage,看length()'); //---- $search = new Search_annotation_collection(); $search->set_target_scope($target_scope_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的target_scope,看length()'); $this->unit->run($target_scope_f->length(), 2, '先確定一下target_scope_f的數量沒錯'); $search = new Search_annotation_collection(); $search->set_target_scope($target_scope_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的target_scope,看length()'); //---- $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_scope,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'order scope之前'); $this->unit->run($search->get_item(0)->get_user()->get_name(), 'puddingchen.35', 'order scope之前,查看一下user name'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(2, TRUE); $this->unit->run($search->get_item(0)->get_id(), 1017, 'order scope desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(3); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order like desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(4); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order respond desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(5, TRUE); $this->unit->run($search->get_item(0)->get_user()->get_name(), 'pulipuli', 'order author desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(6); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order update desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_nf); $search->add_order(7); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order update desc之後'); $search = new Search_annotation_collection(); $search->set_exclude_scope($target_scope_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的exclude_scope,看length(),應該是跟上上個測試剛好是相反地'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的exclude_scope,get_item(0)並檢查id,應該是指定的784才對'); //---- $search = new Search_annotation_collection(); $search->set_overlap_scope($overlap_scope_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的overlap_scope,看length()'); $search = new Search_annotation_collection(); $search->set_overlap_scope($overlap_scope_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的overlay_scope,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的overlay_scope,get_item() get_id()看看'); //---- $type_id_nf = 3; $type_id_f = 2; //$search = new Search_scope_collection(); $search = new Search_annotation_collection(); $search->set_target_type($type_id_nf); $this->unit->run($search->length(), 0, 'Search_annotation_collection,搜尋錯誤的target_id,看length()'); $search = new Search_annotation_collection(); $search->set_target_type($type_id_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的target_id,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的type_id,get_item() get_id()看看'); //---- $search = new Search_annotation_collection(); $search->set_exclude_user($user_not_found); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_user_id,看length()'); $search = new Search_annotation_collection(); $search->set_exclude_user($user_found); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的exclude_user_id,看length()'); //---- $annotation_id_nf = 9999; $annotation_id_f = 1017; $search = new Search_annotation_collection(); $search->set_exclude_annotation($annotation_id_nf); $this->unit->run($search->length(), 3, 'Search_annotation_collection,搜尋錯誤的exclude_annotation_id,看length()'); $search = new Search_annotation_collection(); $search->set_exclude_annotation($annotation_id_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的exclude_annotation_id,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的exclude_annotation_id,get_item get_id'); //---- $note_nf = '搜尋錯誤'; $note_f = '變項回歸'; $search = new Search_annotation_id_collection(); $search->set_search_note($note_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的search_note,看length()'); $search = new Search_annotation_collection(); $search->set_search_note($note_f); $search->add_order(8); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的search_note,看length()'); $this->unit->run($search->get_item(0)->get_id(), 783, 'Search_annotation_collection,搜尋正確的search_note,get_item get_id'); //---- $anchor_text_f = '冷氣電扇被子'; $search = new Search_scope_collection(); $search->set_search_anchor_text($note_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的search_anchor_text,看length()'); $search = new Search_annotation_collection(); $search->set_search_anchor_text($note_f); $search->add_order(9); $this->unit->run($search->length(), 2, 'Search_annotation_collection,搜尋正確的search_anchor_text,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'Search_annotation_collection,搜尋正確的search_anchor_text,get_item get_id'); $search = new Search_annotation_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $this->unit->run($search->length(), 2, 'Search_annotation_collection,並關掉權限檢查,搜尋正確的search_anchor_text,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1017, 'order score之前'); $search = new Search_annotation_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $search->add_order(1); $this->unit->run($search->get_item(0)->get_id(), 1018, 'order score之後'); $search = new Search_scope_collection(); $search->set_check_authorize(FALSE); $search->set_search_anchor_text($note_f); $this->unit->run($search->get_scope_length(), 20 - 3 + 1 + 40 - 26 + 1, 'Search_scope_collection,並關掉權限檢查,搜尋正確的search_anchor_text,看get_scope_length()'); //---- $score_over_nf = 3; $score_over_f = 2.1214435; $search = new Search_scope_collection(); $search->set_target_over_score($score_over_nf); $this->unit->run($search->length(), 0, 'Search_annotation_id_collection,搜尋錯誤的target_over_score,看length()'); $search = new Search_annotation_collection(); $search->set_target_over_score($score_over_f); $this->unit->run($search->length(), 1, 'Search_annotation_collection,搜尋正確的target_over_score,看length()'); $this->unit->run($search->get_item(0)->get_id(), 1018, 'Search_annotation_collection,搜尋正確的target_over_score,get_item get_id'); $search = new Search_annotation_user_collection(); $search->set_target_over_score($score_over_f); $this->unit->run($search->length(), 1, 'Search_annotation_user_collection,搜尋正確的target_over_score,length'); $this->unit->run($search->get_item(0)->get_id(), 225, 'Search_annotation_user_collection,搜尋正確的target_over_score,get_item get_id'); // //-------------------------------------------------------------------------------- // $search = new Search_annotation_collection(); // $search->set_check_authorize(FALSE); // $search->set_target_user($user_not_found); // $this->unit->run($search->length() // , 0 // , 'Search_annotation_collection,取消auth,搜尋錯誤user_id,看length()'); // // $search = new Search_annotation_collection(); // $search->set_check_authorize(FALSE); // $search->set_target_user($user_found); // $this->unit->run($search->length() // , 4 // , 'Search_annotation_collection,取消auth,搜尋正確的user_id,看length()'); // $this->unit->run($test_result // , $expected_result // , $test_name); // $this->unit->run($test_result // , $expected_result // , $test_name); //context_complete(); unit_test_report($this); }
/** * * @param Search_order $order 排序設定,留空等於預設排序 * @return \Search_annotation_collection */ public function get_appended_annotation($order = NULL, $desc = NULL) { $this->_CI_load('library', 'search/Search_annotation_collection', 'search_annotation_collection'); $search = new Search_annotation_collection(); $search->set_target_webpage($this->get_id()); $search->set_check_authorize(FALSE); // 設定colllection的排序 if (isset($order)) { $search->add_order($order, $desc); } $search->disable_limit(); $search->disable_offset(); return $search; }
/** * 回傳所有標註的範圍,以句子切割 * * @param Array $data 傳入sentence_structure * @return Array 要回傳給KALS_controller的資料 * 一樣是以關聯式陣列組成 */ public function whole_annotations_by_sentence($data) { $sentence_structure = $data["sentence_structure"]; $sentence_scopes = $this->_create_division_scopes($sentence_structure); // ------------------------- $webpage = $this->get_current_webpage(); $search = new Search_annotation_collection(); $search->set_target_webpage($webpage->get_id()); //$limit = 5; //$search->set_limit($limit); $order_type_id = 6; $desc = FALSE; $search->add_order($order_type_id, $desc); $is_topic = true; $search->set_target_topic($is_topic); //print_r($data["sentence_structure"]); // --------------------------- $from_index_array = array(); $steps = array(); foreach ($search as $index => $annotation) { $scopes = $annotation->get_scopes(); $from_index = $scopes->get_first_index(); $scope = $this->_match_division_scope_by_from_index($sentence_scopes, $from_index); $from_index_array[] = $from_index; // 比對是否跟上一個scope相同 if ($this->_match_last_scope($steps, $scope) === FALSE) { $steps[] = $scope; } } $data = array(); $data["steps"] = $steps; $data["from_index_array"] = $from_index_array; //$data["steps"] = $sentence_scopes; return $data; }
function list_annotation($json, $callback = NULL) { $enable_profiler = FALSE; if ($enable_profiler === TRUE) { $this->output->enable_profiler(TRUE); } if (is_string($json)) { $data = json_to_object($json); } else { $data = $json; } $user = get_context_user(); $url = $this->url; $search = new Search_annotation_collection(); $search_id = null; if (isset($data->limit)) { $search_id = new Search_annotation_id_collection(); } // 1 [ topic id ] if (isset($data->topic_id) && isset($data->target_topic) && $data->target_topic === TRUE) { $annotation = new Annotation($data->topic_id); $output_data = array('annotation_collection' => array($annotation->export_data()), 'totally_loaded' => true); return $this->_display_jsonp($output_data, $callback); } else { if (isset($data->topic_id) && isset($data->target_topic) && $data->target_topic === FALSE) { $search->set_target_topic_id($data->topic_id); if (isset($search_id)) { $search_id->set_target_topic_id($data->topic_id); } } } // 2 [ scope ] //test_msg('2 [ scope ]', is_null($data->scope)); //如果沒有設定範圍,則直接回傳空值 //if (is_null($data->scope)) //{ // //return $this->_create_null_list($callback); //} if (isset($data->scope)) { $scope_coll_data = $data->scope; //test_msg('2 [ scope ] 2', is_null($data->scope)); $scope_coll = $this->annotation_scope_collection->import_webpage_search_data($url, $scope_coll_data); //test_msg($scope_coll->export_json()); $search->set_overlap_scope($scope_coll); if (isset($search_id)) { $search_id->set_overlap_scope($scope_coll); } //test_msg('2 [ scope ] 3', is_null($data->scope)); } // 3 [ target like ] // 4 [ target my ] //test_msg('3 [ target like ] 4 [ target my ]'); if ((isset($data->target_like) or isset($data->target_my)) && is_null($user)) { return $this->_create_null_list($callback); } if (isset($data->target_like)) { $search->set_target_like($data->target_like, $user); if (isset($search_id)) { $search_id->set_target_like($data->target_like, $user); } } if (isset($data->target_my)) { if ($data->target_my === TRUE) { $search->set_target_user($user); if (isset($search_id)) { $search_id->set_target_user($user); } } else { $search->set_exclude_user($user); if (isset($search_id)) { $search_id->set_exclude_user($user); } } } // 5 [ target_topic ] if (isset($data->target_topic)) { $search->set_target_topic($data->target_topic); if (isset($search_id)) { $search_id->set_target_topic($data->target_topic); } } // 6 [ order by ] // 6 [ is_desc] //test_msg('6 [ order by ]', isset($data->order_by)); //test_msg('6 [ order by ] direction', $data->direction); $order_id = 1; $default_direction = TRUE; if (isset($data->order_by)) { if ($data->order_by == 'update') { $order_id = 6; $default_direction = TRUE; } else { if ($data->order_by == 'create') { $order_id = 7; $default_direction = TRUE; } else { // 依照分數排序 $order_id = 1; $default_direction = TRUE; } } } if (isset($data->direction) && $data->direction == 'asc') { $default_direction = FALSE; } /* if (isset($data->order_by) === FALSE OR $data->order_by != 'update') { $order_id = 6; $default_is_desc = TRUE; } */ //test_msg('6 [ order by ] add_oder', array($order_id, $default_is_desc)); $search->add_order($order_id, $default_direction); // if (isset($search_id)) { // $search_id->add_order ($order_id, $default_direction); // } // 7 [ offset ] //test_msg('7 [ offset ]', isset($data->offset)); if (isset($data->offset)) { $search->set_offset($data->offset); // if (isset($search_id)) { // $search_id->set_offset($data->offset); // } } // 8 [ limit ] //test_msg('8 [ limit ]', array(isset($data->limit),$data->limit)); if (isset($data->limit)) { $search->set_limit($data->limit); //$search_id在此不作設限 } $search->set_target_webpage(get_context_webpage()); //輸出 $totally_loaded = TRUE; if (isset($search_id)) { $totally_loaded = FALSE; } //不作limit的情況下讀完,表示完全讀取 if (isset($search_id) && ($search->length() == $search_id->length() || $search->length() == 0)) { $totally_loaded = TRUE; } $annotation_collection = array(); //test_msg('Search Length', $search->length()); foreach ($search as $search_annotation) { $annotation_data = $search_annotation->export_webpage_data($url); if (isset($data->target_topic) && $data->target_topic === TRUE) { $search_data = json_to_object('{}'); $search_data->target_topic = FALSE; $search_data->topic_id = $search_annotation->get_id(); if (isset($data->respond_limit)) { $search_data->limit = $data->respond_limit; } //$search_data->is_like = NULL; $search_data->order_by = 'create'; if (isset($data->respond_direction)) { $search_data->direction = $data->respond_direction; } else { //$search_data->direction = "asc"; } $search_data->show_total_count = TRUE; $search_result = $this->list_annotation($search_data); //test_msg($search_result); if (count($search_result['annotation_collection']) > 0) { $annotation_data['respond_list'] = $search_result; } } array_push($annotation_collection, $annotation_data); } $output_data = array('annotation_collection' => $annotation_collection, 'totally_loaded' => $totally_loaded); if (isset($data->show_total_count) && $data->show_total_count === TRUE) { if (count($annotation_collection) === 0) { $output_data['total_count'] = 0; } else { if (isset($search_id)) { $output_data['total_count'] = $search_id->length(); } else { $output_data['total_count'] = count($annotation_collection); } } } //log區 $array_data = NULL; if (is_string($json)) { $array_data = json_to_array($json); } else { $array_data = (array) $json; } $user_id = NULL; if (isset($user)) { $user_id = $user->get_id(); } $action = 12; if (isset($data->topic_id) && isset($data->target_topic) && $data->target_topic === FALSE && isset($data->limit) == FALSE) { $action = 16; } $do_log = TRUE; if (isset($data->limit) && $data->limit == 5) { $do_log = FALSE; } if (isset($data->target_my)) { if ($data->target_my == FALSE) { $do_log = FALSE; } } else { if ($user_id == NULL) { $action = 17; if (isset($data->topic_id) && isset($data->target_topic) && $data->target_topic === FALSE && isset($data->limit) == FALSE) { $action = 18; } } } if ($do_log) { kals_log($this->db, $action, array('memo' => $array_data, 'user_id' => $user_id)); } context_complete(); if ($enable_profiler != TRUE) { return $this->_display_jsonp($output_data, $callback); } }