public function setValue($key, $value)
 {
     switch ($key) {
         case "prefix":
             $this->prefix = trim($prefix, " _") . "_";
             break;
         case "database":
             if (is_string($value)) {
                 if (is_class($value)) {
                     $this->database = call_user_func(array($value, "getInstance"));
                 } else {
                     if (function_exists($value)) {
                         $this->database = call_user_func($value);
                     }
                 }
             } else {
                 if (is_array($value) && count($value) > 2 && is_class($value[0]) && method_exists($value[0], $value[1])) {
                     $this->database = call_user_func(array($value[0], $value[1]));
                 } else {
                     if (is_object($value)) {
                         $this->database = $value;
                     }
                 }
             }
             break;
         default:
             $value = false;
             break;
     }
     return $value;
 }
 public static function setThrottleCache($cache)
 {
     if (sfCore::$strict) {
         if (!is_class($cache, 'fCache')) {
             throw new sfProgrammerException('sfSecurity::throttle requires a fCache object.');
         }
     }
     static::$throttle_cache = $cache;
 }
 public function set_item_data($user_id, $canceled = FALSE)
 {
     if (is_class($user_id, 'User')) {
         $user_id = $user_id->get_id();
     }
     if (isset($this->index_object) && is_int($user_id) && $this->index_object->get_field('user_id') == $user_id) {
         //不允許跟標註使用者相同的使用者新增
         handle_error('annotation_like_collection.deny_annotation_author.exception');
         return $this;
     }
     return parent::set_item_data($user_id, array('canceled' => $canceled));
 }
 public function testSpec()
 {
     $this->specs->add('f|foo:', 'option require value');
     $this->specs->add('b|bar+', 'option with multiple value');
     $this->specs->add('z|zoo?', 'option with optional value');
     $this->specs->add('v|verbose', 'verbose message');
     $this->specs->add('d|debug', 'debug message');
     $spec = $this->specs->get('foo');
     $this->assertTrue($spec->isRequired());
     $spec = $this->specs->get('bar');
     $this->assertTrue($spec->isMultiple());
     $spec = $this->specs->get('zoo');
     $this->assertTrue($spec->isOptional());
     $spec = $this->specs->get('debug');
     $this->assertNotNull($spec);
     is_class('GetOptionKit\\Option', $spec);
     is('debug', $spec->long);
     is('d', $spec->short);
     $this->assertTrue($spec->isFlag());
 }
 function testSpec()
 {
     $opt = new \GetOptionKit\GetOptionKit();
     ok($opt);
     $opt->add('f|foo:', 'option require value');
     $opt->add('b|bar+', 'option with multiple value');
     $opt->add('z|zoo?', 'option with optional value');
     $opt->add('v|verbose', 'verbose message');
     $opt->add('d|debug', 'debug message');
     $spec = $opt->get('foo');
     ok($spec->isAttributeRequire());
     $spec = $opt->get('bar');
     ok($spec->isAttributeMultiple());
     $spec = $opt->get('zoo');
     ok($spec->isAttributeOptional());
     $spec = $opt->get('debug');
     ok($spec);
     is_class('GetOptionKit\\OptionSpec', $spec);
     is('debug', $spec->long);
     is('d', $spec->short);
     ok($spec->isAttributeFlag());
 }
 /**
  * 設定合集內成員
  * @param integer|Generic_object|array|Generic_collection $coll
  * 可以輸入Generic_object的ID(int)、Generic_object本身、包含Generic_object的陣列(array)、或是Generic_collection
  * @return Generic_collection
  */
 public function set_members($coll)
 {
     if (is_int($coll) && isset($this->index_object)) {
         $coll = $this->index_object->filter_object($coll);
     }
     if (is_class($coll, $this->class_name)) {
         $coll = array($coll);
     }
     $this->members = array();
     foreach ($coll as $item) {
         $this->members[] = $item;
     }
     $this->modified = TRUE;
     $this->is_loaded = TRUE;
     return $this;
 }
 /**
  * 過濾取得物件
  *
  * 省去檢查該物件到底是物件還是ID的輔助函數
  * @param int|Generic_object $go
  * @return Generic_object
  */
 public function filter_object($go)
 {
     //if (FALSE === is_object($go))
     if (FALSE === is_class($go, $this) && (is_int($go) or is_string($go))) {
         $class_name = get_class($this);
         $go = new $class_name($go);
     }
     return $go;
 }
 function renderMailTemplate($newsletter_id = 0)
 {
     if (!is_class($this->mail_template)) {
     }
     // return the composed result of the mail template
     return $this->mail_template->show(true);
 }
function smarty_function_input($params, $template)
{
    // TODO: Maybe we can let the field configure the formatter even not in readonly state?
    $attr = get_attr($params, $template);
    if (is_class($template->block_data, "FormField")) {
        $f = $template->block_data;
        if ($f->state == 'readonly') {
            // We are in readonly format
            if (isset($f->formatter)) {
                return call_user_func($f->formatter, $attr);
            } else {
                return create_tag('span', array('class' => array('form-element', 'input', 'readonly')), array(), $attr['value']);
            }
        }
    }
    return form_input($attr);
}
Exemple #10
0
<?php

if (!is_class('Opl_Class')) {
    throw new RuntimeException('Cannot load %%library%%: OPL core not found');
}
__halt_compiler();
?>
Exemple #11
0
 function setViewClass($className)
 {
     if (is_class($className)) {
         $this->view = $className;
     }
 }
Exemple #12
0
 function combine_url($host = NULL, $uri = NULL)
 {
     if ($host == NULL) {
         return NULL;
     }
     if (is_class($host, 'Domain')) {
         $host = $host->get_host();
     }
     if (substr($host, -1, 1) != "/") {
         $host = $host . '/';
     }
     $url = $host;
     if ($uri != NULL) {
         if (is_class($uri, 'Webpage')) {
             $uri = $uri->get_uri();
         }
         if (substr($uri, 0, 1) == '/') {
             $uri = substr($uri, 1);
         }
         $url = $url . $uri;
     }
     return $url;
 }
 public function set_scopes($scopes)
 {
     //$scopes = self::sort_scopes($scopes);
     if (is_class($scopes, 'Annotation_scope')) {
         $scopes = array($scopes);
     }
     $this->members = $scopes;
     $this->modified = TRUE;
     $this->sorted = FALSE;
     return $this;
 }
Exemple #14
0
 public function export_webpage_recommend_data($url)
 {
     $data = array();
     //$data['class'] = get_class($this);
     $data['annotation_id'] = $this->get_id();
     $note = $this->get_note();
     if (isset($note)) {
         $data['note'] = $this->get_note();
     }
     $data['user'] = $this->get_user()->export_simple_data();
     $data['type'] = $this->get_type()->export_data();
     $data['scope'] = $this->get_scopes()->export_webpage_data($url);
     $current_user = get_context_user();
     $is_my_annotation = FALSE;
     if (isset($current_user) && $this->get_user()->equals($current_user)) {
         $is_my_annotation = TRUE;
     }
     if ($this->is_respond() === FALSE) {
         if (is_class($current_user, 'User') && $is_my_annotation === FALSE) {
             $data['is_like'] = $this->is_liked($current_user);
         }
         $data['like_count'] = $this->get_like_count();
     }
     return $data;
 }
 /**
  * 更新前動作
  * @abstract 將更新的資料插入$type_id跟$name。
  * 注意:子類別覆寫時請務必引用此方法。
  * @param array $data 原本要更新的資料
  * @return array 更新後的資料
  */
 protected function _pre_update($data)
 {
     if (isset($this->type_field) && FALSE === isset($data[$this->type_field])) {
         $type_id = $this->get_type_id();
         if (is_class($this, 'Annotation_like')) {
             test_msg('Generic_attribute_object::_pre_update() ', $type_id . '?');
         }
         if (isset($type_id)) {
             $data[$this->type_field] = $type_id;
             $this->set_field($this->type_field, $type_id);
         }
     }
     if (isset($this->name_field) && FALSE === isset($data[$this->name_field])) {
         $name = $this->get_name();
         $data[$this->name_field] = $name;
         $this->set_field($this->name_field, $name);
     }
     return $data;
 }
Exemple #16
0
 public function setup_search()
 {
     //--------------------------------------------------
     // 先取得設定,再進行查詢
     //------------------------------------
     //第一關 check auth * 設定
     $annotation_type_id = NULL;
     $action_id = NULL;
     $current_user_id = NULL;
     $current_user_type_id = NULL;
     $current_group_id_list = array();
     $current_group_type_id = NULL;
     if ($this->check_auth === TRUE) {
         //SELECT *
         //FROM annotation
         //LEFT JOIN policy
         //  ON policy.resource_id = annotation.annotation_id
         //  AND policy.resource_type_id = 3
         //  AND policy.action_id = 5
         //LEFT JOIN policy2actor
         //  ON policy.policy_id = policy2actor.policy_id
         //	AND policy2actor.actor_type_id = 1
         //WHERE
         //	(policy2actor.actor_id IS NULL OR
         //      policy2actor.actor_id = 123)
         $this->_CI_load('library', 'kals_resource/Annotation', 'annotation');
         $annotation_type_id = $this->CI->annotation->get_type_id();
         $this->_CI_load('library', 'policy/Action_annotation_read', 'action_annotation_read');
         $action_id = $this->CI->action_annotation_read->get_id();
         $current_user = get_context_user();
         if (is_class($current_user, 'User')) {
             $current_user_id = $current_user->get_id();
             $current_user_type_id = $current_user->get_type_id();
             $groups = $current_user->get_parent_groups();
             foreach ($groups as $group) {
                 if (is_null($current_group_type_id)) {
                     $current_group_type_id = $group->get_type_id();
                 }
                 $current_group_id_list[] = $group->get_id();
             }
         }
     }
     //if ($this->check_auth)
     //-------------------------------------
     //第三關 target_scope * 設定
     $target_scope_in_sql = NULL;
     if (isset($this->target_scope) && $this->target_scope->length() > 0) {
         //SELECT annotation.annotation_id
         //FROM annotation
         //JOIN
         //  (SELECT distinct a2s.annotation_id
         //  FROM annotation
         //  JOIN annotation2scope AS a2s
         //      ON a2s.annotation_id = annotation.annotation_id
         //  LEFT OUTER JOIN scope AS s1
         //      ON s1.scope_id = a2s.scope_id
         //      AND s1.from_index = 3
         //      AND s1.to_index = 20
         //  LEFT OUTER JOIN scope AS s2
         //      ON s2.scope_id = a2s.scope_id
         //      AND s2.from_index = 26
         //      AND s2.to_index = 40
         //  GROUP BY a2s.annotation_id
         //  HAVING count(a2s.annotation_id) >= 2 )
         //AS target_scope ON annotation.annotation_id = target_scope.annotation_id
         $in_sql = 'SELECT DISTINCT a2s.annotation_id ' . ' FROM annotation2scope AS a2s ';
         $where = '';
         foreach ($this->target_scope as $key => $scope) {
             $from = $scope->get_from_index();
             $to = $scope->get_to_index();
             $webpage_id = $scope->get_webpage_id();
             $table_name = 's' . $key;
             $in_sql = $in_sql . ' LEFT JOIN scope AS ' . $table_name . ' ON ' . $table_name . '.scope_id = a2s.scope_id' . ' AND ' . $table_name . '.webpage_id = ' . $webpage_id . ' AND ' . $table_name . '.from_index = ' . $from . ' AND ' . $table_name . '.to_index = ' . $to;
             if ($where != '') {
                 $where .= ' OR ';
             }
             $where .= $table_name . '.scope_id IS NOT NULL ';
         }
         $in_sql = $in_sql . ' WHERE ' . $where . ' GROUP BY a2s.annotation_id ' . ' HAVING count(a2s.annotation_id) = ' . $this->target_scope->length();
         $target_scope_in_sql = $in_sql;
     }
     //------------------------------------------------------
     // 第四關 exclude_scope * 設定
     $exclude_scope_in_sql = NULL;
     if (isset($this->exclude_scope) && $this->exclude_scope->length() > 0) {
         $in_sql = 'SELECT DISTINCT a2s.annotation_id ' . ' FROM annotation2scope AS a2s ';
         $where = '';
         foreach ($this->exclude_scope as $key => $scope) {
             $from = $scope->get_from_index();
             $to = $scope->get_to_index();
             $webpage_id = $scope->get_webpage_id();
             $table_name = 's' . $key;
             $in_sql = $in_sql . ' LEFT JOIN scope AS ' . $table_name . ' ON ' . $table_name . '.scope_id = a2s.scope_id' . ' AND ' . $table_name . '.webpage_id = ' . $webpage_id . ' AND ' . $table_name . '.from_index = ' . $from . ' AND ' . $table_name . '.to_index = ' . $to;
             if ($where != '') {
                 $where .= ' OR ';
             }
             $where .= $table_name . '.scope_id IS NOT NULL ';
         }
         $in_sql = $in_sql . ' WHERE ' . $where . ' GROUP BY a2s.annotation_id ' . ' HAVING count(a2s.annotation_id) = ' . $this->exclude_scope->length();
         //減去現有的查詢
         $in_sql = 'SELECT annotation.annotation_id FROM annotation EXCEPT ' . $in_sql;
         $exclude_scope_in_sql = $in_sql;
     }
     //if (isset($this->exclude_scope))
     //------------------------------------------------
     // 第五關 overlap_scope * 設定
     $overlap_scope_where = NULL;
     $overlap_scope_join = array();
     if (isset($this->overlap_scope) && $this->overlap_scope->length()) {
         //SELECT distinct annotation.annotation_id
         //FROM annotation
         //JOIN annotation2scope AS a2s
         //	ON a2s.annotation_id = annotation.annotation_id
         //JOIN scope AS s1
         //	ON s1.scope_id = a2s.scope_id
         //	AND ( (s1.from_index >= 23 AND s1.from_index <= 44)
         //	  OR (s1.to_index >= 23 AND s1.to_index <= 44)
         //	  OR (s1.from_index <= 23 AND s1.to_index >= 44))
         $where = '';
         $join_scopes = array();
         foreach ($this->overlap_scope as $key => $scope) {
             $webpage_id = $scope->get_webpage_id();
             $from = $scope->get_from_index();
             $to = $scope->get_to_index();
             $table = 'overlap_scope_' . $key;
             $join_scopes[] = array('webpage_id' => $webpage_id, 'from' => $from, 'to' => $to, 'table' => $table);
             if ($where != '') {
                 $where .= ' OR ';
             }
             $where .= $table . '.scope_id IS NOT NULL ';
         }
         $overlap_scope_where = $where;
         $overlap_scope_join = $join_scopes;
     }
     //------------------------------------------------
     //第十關 search_note * 設定
     //test_msg($this->search_note);    //this->search_note空值
     $search_note_query = NULL;
     if (isset($this->search_note)) {
         $query = $this->search_note;
         $query_with_segment = TRUE;
         if ($query_with_segment) {
             if (is_null($this->segmentor)) {
                 $this->_CI_load('library', 'scope/Segmentor_factory', 'segmentor_factory');
                 $this->segmentor = Segmentor_factory::create_search_segmentor();
             }
             $query = $this->segmentor->text_to_query($query);
         } else {
             $this->_CI_load('library', 'scope/Segmentor', 'segmentor');
             $query = Segmentor::segment_to_query($query);
         }
         $search_note_query = $query;
     }
     //------------------------------------------------
     // 第十二關 search_anchor_text * 設定
     $search_anchor_text_query = NULL;
     $segmentor = $this->CI->config->item('segmentor.default');
     if ($segmentor !== "segmentor.disable" && isset($this->search_anchor_text)) {
         $query = $this->search_anchor_text;
         $query_with_segment = TRUE;
         if ($query_with_segment) {
             if (is_null($this->segmentor)) {
                 $this->_CI_load('library', 'scope/Segmentor_factory', 'segmentor_factory');
                 $this->segmentor = Segmentor_factory::create_search_segmentor();
             }
             $query = $this->segmentor->text_to_query($query);
         } else {
             $this->_CI_load('library', 'scope/Segmentor', 'segmentor');
             $query = Segmentor::segment_to_query($query);
         }
         $search_anchor_text_query = $query;
     }
     //if (isset($this->search_anchor_text))
     //------------------------------------------------
     // 第十三關 target_over_score * 設定
     $target_over_score_type_id = NULL;
     if (isset($this->target_over_score) && $this->target_over_score > 0) {
         $this->_CI_load('library', 'score/Annotation_score_integrated', 'annotation_score_integrated');
         $score_type_id = $this->CI->annotation_score_integrated->get_type_id();
         $target_over_score_type_id = $score_type_id;
     }
     //-----------------------------------------------
     //接著才是進入查詢
     $db = $this->db;
     //$db->from('annotation');
     $db->where('annotation.deleted', 'FALSE');
     if (isset($this->limit)) {
         $db->limit($this->limit);
     }
     if (isset($this->offset)) {
         $db->offset($this->offset);
     }
     //------------------------------------
     //第一關 check auth * 查詢
     if ($this->check_auth === TRUE) {
         $db->join('policy', 'policy.resource_id = annotation.annotation_id ' . 'AND policy.resource_type_id = ' . $annotation_type_id . ' ' . 'AND policy.action_id = ' . $action_id, 'left');
         $db->join('policy2actor', 'policy.policy_id = policy2actor.policy_id ', 'left');
         if (isset($current_user_id)) {
             $where = '(policy2actor.actor_id IS NULL ' . 'OR (policy2actor.actor_type_id = ' . $current_user_type_id . ' AND policy2actor.actor_id = ' . $current_user_id . ')';
             foreach ($current_group_id_list as $group_id) {
                 $where .= ' OR (policy2actor.actor_type_id = ' . $current_group_type_id . 'AND policy2actor.actor_id = ' . $group_id . ' )';
             }
             $where .= ')';
             $db->where($where);
         } else {
             $db->where('policy2actor.actor_id IS NULL');
         }
     }
     //if ($this->check_auth)
     //-------------------------------------
     // 第二關 設定webpage_id(取得目前的webpage_id資料)
     if (isset($this->target_webpage_id)) {
         $db->join('webpage2annotation', 'webpage2annotation.annotation_id = annotation.annotation_id ' . ' AND webpage2annotation.webpage_id = ' . $this->target_webpage_id);
     }
     //if (isset($this->webpage_id))
     //-------------------------------------
     //第三關 target_scope * 查詢
     if (isset($target_scope_in_sql)) {
         $db->join('(' . $target_scope_in_sql . ') AS target_scope', 'target_scope.annotation_id = annotation.annotation_id');
     }
     //if (isset($this->target_scope))
     //------------------------------------------------------
     // 第四關 exclude_scope * 查詢
     if (isset($exclude_scope_in_sql)) {
         $db->join('(' . $exclude_scope_in_sql . ') AS exclude_scope', 'annotation.annotation_id = exclude_scope.annotation_id');
     }
     //if (isset($this->exclude_scope))
     //------------------------------------------------
     // 第五關 overlap_scope * 查詢
     if (isset($overlap_scope_where)) {
         $db->join('annotation2scope AS overlap_scope_annotation2scope', 'overlap_scope_annotation2scope.annotation_id = annotation.annotation_id');
         $where = $overlap_scope_where;
         $join_scopes = $overlap_scope_join;
         foreach ($join_scopes as $scope) {
             $webpage_id = $scope['webpage_id'];
             $from = $scope['from'];
             $to = $scope['to'];
             $table = $scope['table'];
             $db->join('scope AS ' . $table, $table . '.scope_id = overlap_scope_annotation2scope.scope_id ' . ' AND ' . $table . '.webpage_id = ' . $webpage_id . ' AND (' . ' (' . $table . '.from_index >= ' . $from . ' AND ' . $table . '.from_index <= ' . $to . ') ' . ' OR (' . $table . '.to_index >= ' . $from . ' AND ' . $table . '.to_index <= ' . $to . ') ' . ' OR (' . $table . '.from_index <= ' . $from . ' AND ' . $table . '.to_index >= ' . $to . ') ' . ' ) ', 'left');
         }
         $db->where('(' . $where . ')');
     }
     //if (isset($this->overlap_scope))
     //------------------------------------------------
     // 第六關 target_type_id
     if (isset($this->target_type_id)) {
         $db->where('annotation.annotation_type_id', $this->target_type_id);
     }
     //if (isset($this->target_type_id))
     //------------------------------------------------
     // 第6.5關 exclude_type_id_list
     if (count($this->exclude_type_id_list) > 0) {
         $db->where_not_in('annotation.annotation_type_id', $this->exclude_type_id_list);
     }
     //if (isset($this->target_type_id))
     //------------------------------------------------
     // 第七關 target_user_id
     if (isset($this->target_user_id)) {
         $db->where('annotation.user_id', $this->target_user_id);
     }
     //if (isset($this->target_type_id))
     //------------------------------------------------
     // 第八關 exclude_user_id
     if (isset($this->exclude_user_id)) {
         $db->where('annotation.user_id != ' . $this->exclude_user_id);
     }
     //if (isset($this->exclude_user_id))
     //------------------------------------------------
     // 第九關 exclude_annotaiton_id
     if (isset($this->exclude_annotation_id)) {
         $db->where('annotation.annotation_id != ' . $this->exclude_annotation_id);
     }
     //if (isset($this->exclude_annotation_id))
     //------------------------------------------------
     //第十關 search_note * 查詢  -分成使用斷詞器和不使用的情況(參考search_anchor_text)
     //1.使用斷詞器
     /* if (isset($this->search_note))
        {
            test_msg($this->search_note);
        }
        else {
            $this->search_note = 0;
            echo $this->search_note;
        }*/
     if ($segmentor !== "segmentor.disable" && isset($search_note_query)) {
         $query = $search_note_query;
         //$db->from('to_tsquery(\''.$query.'\') search_note_query');
         $this->other_from[] = 'to_tsquery(\'' . $query . '\') search_note_query';
         $db->where('annotation.note_index @@ search_note_query', NULL, FALSE);
     }
     //if (isset($this->search_note))
     //2.不使用斷詞器的情況
     //test_msg(array($segmentor, $this->search_note));
     if ($segmentor === "segmentor.disable" && isset($this->search_note)) {
         $db->like('note', $this->search_note);
         // 生成: WHERE title LIKE '%match%'
         //$db->limit(10);
         //判斷this->search_note裡面有抓到值嗎?
         /*if (isset($this->search_note))
               {
                 test_msg($this->search_note);
               }
           else {
                 $this->search_note = 0;
                 echo $this->search_note;
                }*/
     }
     //------------------------------------------------
     // 第十一關 target_over_like 查詢
     if (isset($this->target_over_like_count) && $this->target_over_like_count > 0) {
         $db->join('annotation2like_count AS target_over_like', 'annotation.annotation_id = target_over_like.annotation_id ' . ' AND target_over_like.like_count > ' . $this->target_over_like_count);
     }
     //------------------------------------------------
     // 第十二關 search_anchor_text * 查詢
     if ($segmentor !== "segmentor.disable" && isset($search_anchor_text_query)) {
         $query = $this->search_anchor_text_query;
         $db->join('annotation2anchor_text AS search_anchor_text', 'search_anchor_text.annotation_id = annotation.annotation_id ' . 'AND search_anchor_text.indexed @@ to_tsquery(\'' . $query . '\')');
         $this->other_from[] = 'to_tsquery(\'' . $query . '\') search_anchor_text_query';
     }
     //如果不使用斷詞器,就直接使用$this->search_anchor_text進行查詢,不使用query,搭配第二關 target_url 查詢使用
     //test_msg(array($segmentor, $this->search_anchor_text));
     if ($segmentor === "segmentor.disable" && isset($this->search_anchor_text)) {
         $db->join('annotation2anchor_text AS search_anchor_text', 'search_anchor_text.annotation_id = annotation.annotation_id ' . "AND search_anchor_text.text like '%" . $this->search_anchor_text . "%'");
         $db->limit(5);
         //echo $this->webpage_id;
     }
     //if (isset($this->search_anchor_text))
     //------------------------------------------------
     // 第十三關 target_over_score * 查詢
     if (isset($this->target_over_score) && $this->target_over_score > 0) {
         $score_type_id = $target_over_score_type_id;
         $db->join('score AS target_over_score', 'annotation.annotation_id = target_over_score.annotation_id ' . ' AND target_over_score.score_type_id = ' . $score_type_id . ' AND target_over_score.score >= ' . $this->target_over_score);
     }
     //------------------------------------------------
     // 第十四關 target_newer_update * 查詢
     if (isset($this->target_newer_update)) {
         $db->where("annotation.update_timestamp > TIMESTAMP WITH TIME ZONE 'epoch' + " . $this->target_newer_update . " * INTERVAL '1 second'");
     }
     if (isset($this->target_newer_create)) {
         $db->where("annotation.create_timestamp > TIMESTAMP WITH TIME ZONE 'epoch' + " . $this->target_newer_create . " * INTERVAL '1 second'");
     }
     if (isset($this->target_older_create)) {
         $db->where("annotation.create_timestamp < TIMESTAMP WITH TIME ZONE 'epoch' + " . $this->target_older_create . " * INTERVAL '1 second'");
     }
     //------------------------------------------------
     // 第十五關 target_topic * 查詢
     if (isset($this->target_topic)) {
         if ($this->target_topic === TRUE) {
             $db->where("annotation.topic_id IS NULL");
         } else {
             $db->where("annotation.topic_id IS NOT NULL");
         }
     }
     //------------------------------------------------
     // 第十五.5關 target_topic_id * 查詢
     if (isset($this->target_topic_id)) {
         $db->where("annotation.topic_id", $this->target_topic_id);
     }
     //------------------------------------------------
     // 第十六關 target_like * 查詢
     if (isset($this->target_like)) {
         if ($this->target_like === TRUE) {
             $db->join('annotation2like AS target_like', 'annotation.annotation_id = target_like.annotation_id ' . ' AND target_like.user_id = ' . $this->target_like_user_id . ' AND target_like.canceled IS FALSE');
         } else {
             /*
                             $db->join('annotation2like AS target_like'
                , 'annotation.annotation_id = annotation.annotation_id '
                , 'left');
                             $db->where('((annotation.annotation_id = target_like.annotation_id '
                    . ' AND target_like.user_id = ' . $this->target_like_user_id
                    . ' AND target_like.canceled IS TRUE)'
                    . ' OR (target_like.annotation2like_id IS NULL))');
             */
             $db->join('annotation2like AS target_like', 'annotation.annotation_id = target_like.annotation_id ', 'left');
             /*
                             $db->where('( ( ( (target_like.user_id != ' . $this->target_like_user_id . ') OR'
                    . '( target_like.user_id = ' . $this->target_like_user_id . ' AND target_like.canceled IS TRUE) )'
                    . ' OR (target_like.annotation2like_id IS NULL) ) )');
             *
             */
             $db->where('( target_like.annotation_id IS NULL OR  target_like.annotation_id NOT IN (SELECT annotation_id FROM annotation2like WHERE user_id = ' . $this->target_like_user_id . ' AND canceled = FALSE) )');
         }
     }
     //------------------------------------------------
     // 第十七關 target_url 查詢
     //if (isset($this->target_url))
     //{
     //1.要把url轉成id再搜尋:先從表中用url找出webpage_id->使用filter_webpage_object來轉換url->webpage_id
     //in webpage.php
     //$this->webpage_id = $this->CI->webpage->filter_webpage_id($this->target_url);
     //2.設定search條件
     /* $db->join('webpage2annotation', 'webpage2annotation.annotation_id = annotation.annotation_id'
        . 'AND webpage2annotation.webpage_id = '.$this->webpage_id);*/
     //}
     //------------------------------------------------
     //第十八關 search_username 查詢
     if (isset($this->search_username)) {
         $db->join('user AS search_username', 'search_username.user_id = annotation.user_id ' . "AND search_username.name like '%" . $this->search_username . "%'");
         // 20131113 Pudding Chen
         // 為什麼要在這裡加limit?
         //$db->limit(15);
     }
     //------------------------------------------------
     // 大魔王 order *
     $this->order_coll->setup_order($db);
     return $db;
 }