3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'search/SearchQuery.class.php';
28 class TasksSearchQuery extends SearchQuery {
38 * flag if non public items are returned
40 * @var boolean $showNonPublic
47 * @param string $words words we are searching for
48 * @param int $offset offset
49 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
50 * @param int $groupId group id
51 * @param array $sections sections to search in
52 * @param boolean $showNonPublic flag if private sections are searched too
54 function TasksSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
55 $this->groupId = $groupId;
56 $this->showNonPublic = $showNonPublic;
58 $this->SearchQuery($words, $offset, $isExact);
60 $this->setSections($sections);
64 * getQuery - get the query built to get the search results
66 * @return array query+params array
71 $qpa = db_construct_qpa () ;
74 if (count ($this->words)) {
75 $words = $this->getFormattedWords();
77 $qpa = db_construct_qpa ($qpa,
78 'SELECT project_task.project_task_id, project_task.percent_complete, headline(project_task.summary, q) AS summary, project_task.start_date,project_task.end_date,users.firstname||$1||users.lastname AS realname, project_group_list.project_name, project_group_list.group_project_id FROM project_task, users, project_group_list, to_tsquery($2) AS q, project_task_idx WHERE project_task.created_by = users.user_id AND project_task.project_task_id = project_task_idx.project_task_id AND project_task.group_project_id = project_group_list.group_project_id AND project_group_list.group_id=$3 ',
83 $qpa = db_construct_qpa ($qpa,
84 'SELECT project_task.project_task_id, project_task.percent_complete, summary, project_task.start_date,project_task.end_date,users.firstname||$1||users.lastname AS realname, project_group_list.project_name, project_group_list.group_project_id FROM project_task, users, project_group_list WHERE project_task.created_by = users.user_id AND project_task.group_project_id = project_group_list.group_project_id AND project_group_list.group_id = $2 ',
88 if ($this->sections != SEARCH__ALL_SECTIONS) {
89 $qpa = db_construct_qpa ($qpa,
90 'AND project_group_list.group_project_id = ANY ($1) ',
91 db_int_array_to_any_clause ($this->sections)) ;
93 if (!$this->showNonPublic) {
94 $qpa = db_construct_qpa ($qpa,
95 'AND project_group_list.is_public = 1 ') ;
97 if (count($this->phrases)) {
98 if (count ($this->words)) {
99 $qpa = db_construct_qpa ($qpa,
100 'AND (vectors @@ q AND (') ;
102 $qpa = db_construct_qpa ($qpa,
105 $qpa = $this->addMatchCondition($qpa, 'summary');
106 $qpa = db_construct_qpa ($qpa,
108 $qpa = $this->addMatchCondition($qpa, 'details');
109 $qpa = db_construct_qpa ($qpa,
112 if (count ($this->words)) {
113 $qpa = db_construct_qpa ($qpa,
114 'ORDER BY project_group_list.project_name, rank(vectors, q) DESC, project_task.project_task_id') ;
116 $qpa = db_construct_qpa ($qpa,
117 'ORDER BY project_group_list.project_name, project_task.project_task_id') ;
120 $qpa = db_construct_qpa ($qpa,
121 'SELECT project_task.project_task_id, project_task.summary, project_task.percent_complete, project_task.start_date, project_task.end_date, users.firstname||$1||users.lastname AS realname, project_group_list.project_name, project_group_list.group_project_id FROM project_task, users, project_group_list WHERE project_task.created_by = users.user_id AND project_task.group_project_id = project_group_list.group_project_id AND project_group_list.group_id = $2 ',
124 if ($this->sections != SEARCH__ALL_SECTIONS) {
125 $qpa = db_construct_qpa ($qpa,
126 'AND project_group_list.group_project_id = ANY ($1) ',
127 db_int_array_to_any_clause ($this->sections)) ;
129 if (!$this->showNonPublic) {
130 $qpa = db_construct_qpa ($qpa,
131 'AND project_group_list.is_public = 1 ') ;
133 $qpa = db_construct_qpa ($qpa,
135 $qpa = $this->addIlikeCondition ($qpa, 'summary') ;
136 $qpa = db_construct_qpa ($qpa,
138 $qpa = $this->addIlikeCondition ($qpa, 'details') ;
139 $qpa = db_construct_qpa ($qpa,
140 ') ORDER BY project_group_list.project_name, project_task.project_task_id') ;
146 * getSections - returns the list of available subprojects
148 * @param $groupId int group id
149 * @param $showNonPublic boolean if we should consider non public sections
151 function getSections($groupId, $showNonPublic=false) {
152 $sql = 'SELECT group_project_id, project_name FROM project_group_list WHERE group_id=$1' ;
153 if (!$showNonPublic) {
154 $sql .= ' AND is_public = 1';
156 $sql .= ' ORDER BY project_name';
159 $res = db_query_params ($sql,
161 while($data = db_fetch_array($res)) {
162 $sections[$data['group_project_id']] = $data['project_name'];
170 // c-file-style: "bsd"