Exemplo n.º 1
0
 /**
  * 用跟my一樣的方式回傳範圍,只是這次不限制只有my
  * @author Pulipuli Chen <*****@*****.**> 20151101
  * @return array(0=> "basic", 1=> "custom")
  */
 function other($json = NULL, $callback = NULL)
 {
     $check_time = NULL;
     if (isset($callback)) {
         $check_time = json_to_object($json);
     } else {
         $callback = $json;
     }
     //login_require(true);
     if (login_require(FALSE) === FALSE) {
         $output_data = array('basic' => array(), 'custom' => array());
         return $this->_display_jsonp($output_data, $callback);
     }
     $user = get_context_user();
     $type_scope_colls = array();
     /**
      * @var array 自訂的類型
      */
     $custom_type_scope_colls = array();
     $search = new Search_annotation_collection();
     $search->set_target_topic(TRUE);
     $search->set_target_referer_webpage();
     if (isset($check_time)) {
         $search->set_target_newer_update($check_time);
     }
     // 按照時間排序
     $search->add_order(6, FALSE);
     //test_msg('準備要取得資料嚕');
     //取得搜尋結果
     foreach ($search as $annotation) {
         $annotation_type = $annotation->get_type();
         $annotation_type_id = $annotation_type->get_type_id();
         $annotation_type_name = $annotation_type->get_custom_name();
         $is_basic = $annotation_type->is_basic();
         //test_msg('is_basic', array($is_basic, $annotation_type_id, $annotation->get_id()) );
         $annotation_scope_coll = $annotation->get_scopes();
         if ($is_basic == true) {
             if (isset($type_scope_colls[$annotation_type_id]) === false) {
                 $type_scope_colls[$annotation_type_id] = new Annotation_scope_collection();
             }
             foreach ($type_scope_colls as $type_id => $scope_coll) {
                 if ($annotation_type_id === $type_id) {
                     foreach ($annotation_scope_coll as $scope) {
                         $scope_coll->add_scope($scope);
                     }
                 } else {
                     foreach ($annotation_scope_coll as $scope) {
                         $scope_coll->exclude_scope($scope);
                     }
                 }
             }
         } else {
             if (isset($custom_type_scope_colls[$annotation_type_name]) === false) {
                 //test_msg($annotation_type_name);
                 $custom_type_scope_colls[$annotation_type_name] = new Annotation_scope_collection();
             }
             foreach ($custom_type_scope_colls as $type_name => $scope_coll) {
                 if ($annotation_type_name === $type_name) {
                     foreach ($annotation_scope_coll as $scope) {
                         $scope_coll->add_scope($scope);
                     }
                 } else {
                     foreach ($annotation_scope_coll as $scope) {
                         $scope_coll->exclude_scope($scope);
                     }
                 }
             }
         }
         // else {
         //test_msg('標註3', array($annotation_type_id, $annotation));
     }
     //test_msg('完成取得標註');
     $output_data = array('basic' => array(), 'custom' => array());
     foreach ($type_scope_colls as $type_id => $scope_coll) {
         //這是給basic的!
         $output_data['basic'][$type_id] = $scope_coll->export_webpage_data($this->url);
     }
     foreach ($custom_type_scope_colls as $type_id => $scope_coll) {
         //這是給custom的!
         $output_data['custom'][$type_id] = $scope_coll->export_webpage_data($this->url);
     }
     return $this->_display_jsonp($output_data, $callback);
 }