5 * Copyright 2004 (c) Dominik Haas, GForge Team
12 require_once('common/search/SearchQuery.class');
14 class ForumsSearchQuery extends SearchQuery {
24 * flag if non public items are returned
26 * @var boolean $showNonPublic
33 * @param string $words words we are searching for
34 * @param int $offset offset
35 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
36 * @param int $groupId group id
37 * @param array $sections sections to search in
38 * @param boolean $showNonPublic flag if private sections are searched too
40 function ForumsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
41 $this->groupId = $groupId;
42 $this->showNonPublic = $showNonPublic;
44 $this->SearchQuery($words, $offset, $isExact);
46 $this->setSections($sections);
50 * getQuery - get the sql query built to get the search results
52 * @return string sql query to execute
59 if ($this->showNonPublic) {
62 if ($this->sections != SEARCH__ALL_SECTIONS) {
63 $sections = $this->sections;
65 $sql = 'SELECT forum.msg_id, headline(forum.subject, q) AS subject, forum.post_date, users.realname, forum_group_list.forum_name '
66 . 'FROM forum, users, forum_group_list, forum_idx, to_tsquery(\''.
67 $this->getFormattedWords().'\') as q '
68 . 'WHERE users.user_id = forum.posted_by '
69 . 'AND vectors @@ q AND forum.msg_id = forum_idx.msg_id '
70 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
71 . 'AND forum_group_list.is_public <> 9 '
72 . 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
73 if ($this->sections != SEARCH__ALL_SECTIONS) {
74 $sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
76 if (!$this->showNonPublic) {
77 $sql .= 'AND forum_group_list.is_public = 1 ';
79 $sql .= 'ORDER BY forum_group_list.forum_name ASC, forum.msg_id ASC, rank(vectors, q) DESC';
81 $sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname, forum_group_list.forum_name '
82 . 'FROM forum, users, forum_group_list '
83 . 'WHERE users.user_id = forum.posted_by '
84 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
85 . 'AND forum_group_list.is_public <> 9 '
86 . 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
87 if ($this->sections != SEARCH__ALL_SECTIONS) {
88 $sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
90 if (!$this->showNonPublic) {
91 $sql .= 'AND forum_group_list.is_public = 1 ';
93 $sql .= 'AND (('.$this->getIlikeCondition('forum.body', $this->words).') '
94 . 'OR ('.$this->getIlikeCondition('forum.subject', $this->words).')) '
95 . 'ORDER BY forum_group_list.forum_name, forum.msg_id';
101 * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
103 * @return string sql query to execute
105 function getSearchByIdQuery() {
106 $sql = 'SELECT msg_id '
107 . 'FROM forum, forum_group_list '
108 . 'WHERE msg_id=\''.$this->searchId.'\' '
109 . 'AND forum_group_list.group_forum_id = forum.group_forum_id '
110 . 'AND group_forum_id=\''.$this->forumId.'\'';
111 if (!$this->showNonPublic) {
112 $sql .= ' AND forum_group_list.is_public = 1';
119 * getSections - returns the list of available forums
121 * @param $groupId int group id
122 * @param $showNonPublic boolean if we should consider non public sections
124 function getSections($groupId, $showNonPublic=false) {
125 $sql = 'SELECT group_forum_id, forum_name FROM forum_group_list WHERE group_id = '.$groupId.' AND is_public <> 9';
126 if (!$showNonPublic) {
127 $sql .= ' AND is_public = 1';
129 $sql .= ' ORDER BY forum_name';
132 $res = db_query($sql);
133 while($data = db_fetch_array($res)) {
134 $sections[$data['group_forum_id']] = $data['forum_name'];