1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
<?php
/**
* GForge Search Engine
*
* Copyright 2004 (c) Dominik Haas, GForge Team
*
* http://gforge.org
*
* @version $Id: ForumsSearchQuery.class 5273 2006-02-08 18:47:59Z danper $
*/
require_once('common/search/SearchQuery.class');
class ForumsSearchQuery extends SearchQuery {
/**
* group id
*
* @var int $groupId
*/
var $groupId;
/**
* flag if non public items are returned
*
* @var boolean $showNonPublic
*/
var $showNonPublic;
/**
* Constructor
*
* @param string $words words we are searching for
* @param int $offset offset
* @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
* @param int $groupId group id
* @param array $sections sections to search in
* @param boolean $showNonPublic flag if private sections are searched too
*/
function ForumsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
$this->groupId = $groupId;
$this->showNonPublic = $showNonPublic;
$this->SearchQuery($words, $offset, $isExact);
$this->setSections($sections);
}
/**
* getQuery - get the sql query built to get the search results
*
* @return string sql query to execute
*/
function getQuery() {
global $sys_use_fti;
if ($sys_use_fti) {
$sql = 'SELECT forum.msg_id, headline(forum.subject, q) AS subject, forum.post_date, users.realname, forum_group_list.forum_name '
. 'FROM forum, users, forum_group_list, forum_idx, to_tsquery(\''.
$this->getFormattedWords().'\') as q '
. 'WHERE users.user_id = forum.posted_by '
. 'AND vectors @@ q AND forum.msg_id = forum_idx.msg_id '
. 'AND forum_group_list.group_forum_id = forum.group_forum_id '
. 'AND forum_group_list.is_public <> 9 '
. 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
}
if (!$this->showNonPublic) {
$sql .= 'AND forum_group_list.is_public = 1 ';
}
$sql .= 'ORDER BY forum_group_list.forum_name ASC, forum.msg_id ASC, rank(vectors, q) DESC';
} else {
$sql = 'SELECT forum.msg_id, forum.subject, forum.post_date, users.realname, forum_group_list.forum_name '
. 'FROM forum, users, forum_group_list '
. 'WHERE users.user_id = forum.posted_by '
. 'AND forum_group_list.group_forum_id = forum.group_forum_id '
. 'AND forum_group_list.is_public <> 9 '
. 'AND forum.group_forum_id IN (SELECT group_forum_id FROM forum_group_list WHERE group_id = '.$this->groupId.') ';
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sql .= 'AND forum_group_list.group_forum_id IN ('.$this->sections.') ';
}
if (!$this->showNonPublic) {
$sql .= 'AND forum_group_list.is_public = 1 ';
}
$sql .= 'AND (('.$this->getIlikeCondition('forum.body', $this->words).') '
. 'OR ('.$this->getIlikeCondition('forum.subject', $this->words).')) '
. 'ORDER BY forum_group_list.forum_name, forum.msg_id';
}
return $sql;
}
/**
* getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
*
* @return string sql query to execute
*/
function getSearchByIdQuery() {
$sql = 'SELECT msg_id '
. 'FROM forum, forum_group_list '
. 'WHERE msg_id=\''.$this->searchId.'\' '
. 'AND forum_group_list.group_forum_id = forum.group_forum_id '
. 'AND group_forum_id=\''.$this->forumId.'\'';
if (!$this->showNonPublic) {
$sql .= ' AND forum_group_list.is_public = 1';
}
return $sql;
}
/**
* getSections - returns the list of available forums
*
* @param $groupId int group id
* @param $showNonPublic boolean if we should consider non public sections
*/
function getSections($groupId, $showNonPublic=false) {
$sql = 'SELECT group_forum_id, forum_name FROM forum_group_list WHERE group_id = '.$groupId.' AND is_public <> 9';
if (!$showNonPublic) {
$sql .= ' AND is_public = 1';
}
$sql .= ' ORDER BY forum_name';
$sections = array();
$res = db_query($sql);
while($data = db_fetch_array($res)) {
$sections[$data['group_forum_id']] = $data['forum_name'];
}
return $sections;
}
}
?>
|