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
|
<?php
/**
* GForge Search Engine
*
* Copyright 2004 (c) Dominik Haas, GForge Team
*
* http://gforge.org
*
* @version $Id: FrsSearchQuery.class 5270 2006-02-05 17:12:19Z tperdue $
*/
require_once('common/search/SearchQuery.class');
class FrsSearchQuery 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
*/
function FrsSearchQuery($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) {
$nonPublic = 'false';
$sections = '';
if ($this->showNonPublic) {
$nonPublic = 'true';
}
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sections = $this->sections;
}
$sql = "SELECT * FROM frs_search('".$this->getFormattedWords()."', ".$this->groupId.", '$sections', $nonPublic)";
} else {
$sql = 'SELECT frs_package.name as package_name, frs_release.name as release_name, frs_release.release_date, frs_release.release_id, users.realname'
. ' FROM frs_file, frs_release, users, frs_package'
. ' WHERE frs_release.released_by = users.user_id'
. ' AND frs_package.package_id = frs_release.package_id'
. ' AND frs_file.release_id=frs_release.release_id'
. ' AND frs_package.group_id='.$this->groupId;
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sql .= ' AND frs_package.package_id IN ('.$this->sections.') ';
}
if(!$this->showNonPublic) {
$sql .= ' AND is_public=1';
}
$sql .= ' AND (('.$this->getIlikeCondition('frs_release.changes', $this->words).')'
. ' OR ('.$this->getIlikeCondition('frs_release.notes', $this->words).')'
. ' OR ('.$this->getIlikeCondition('frs_release.name', $this->words).')'
. ' OR ('.$this->getIlikeCondition('frs_file.filename', $this->words).'))'
. ' ORDER BY frs_package.name, frs_release.name';
}
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) {
$sql = 'SELECT package_id, name FROM frs_package WHERE group_id = \''.$groupId.'\' ORDER BY name';
if(!$showNonPublic) {
$sql .= ' AND is_public=1';
}
$sql .= ' ORDER BY name';
$sections = array();
$res = db_query($sql);
while($data = db_fetch_array($res)) {
$sections[$data['package_id']] = $data['name'];
}
return $sections;
}
}
?>
|