3 * FusionForge search engine
5 * Copyright 2004, Dominik Haas
6 * Copyright 2009, Roland Mas
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'search/SearchQuery.class.php';
27 class TasksSearchQuery extends SearchQuery {
37 * flag if non public items are returned
39 * @var boolean $showNonPublic
46 * @param string $words words we are searching for
47 * @param int $offset offset
48 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
49 * @param int $groupId group id
50 * @param array $sections sections to search in
51 * @param boolean $showNonPublic flag if private sections are searched too
53 function TasksSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
54 $this->groupId = $groupId;
55 $this->showNonPublic = $showNonPublic;
57 $this->SearchQuery($words, $offset, $isExact);
59 $this->setSections($sections);
63 * getQuery - get the query built to get the search results
65 * @return array query+params array
70 $qpa = db_construct_qpa () ;
72 if (forge_get_config('use_fti')) {
73 if (count ($this->words)) {
74 $words = $this->getFormattedWords();
76 $qpa = db_construct_qpa ($qpa,
77 '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 ',
82 $qpa = db_construct_qpa ($qpa,
83 '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 ',
87 if ($this->sections != SEARCH__ALL_SECTIONS) {
88 $qpa = db_construct_qpa ($qpa,
89 'AND project_group_list.group_project_id = ANY ($1) ',
90 db_int_array_to_any_clause ($this->sections)) ;
92 if (!$this->showNonPublic) {
93 $qpa = db_construct_qpa ($qpa,
94 'AND project_group_list.is_public = 1 ') ;
96 if (count($this->phrases)) {
97 if (count ($this->words)) {
98 $qpa = db_construct_qpa ($qpa,
99 'AND (vectors @@ q AND (') ;
101 $qpa = db_construct_qpa ($qpa,
104 $qpa = $this->addMatchCondition($qpa, 'summary');
105 $qpa = db_construct_qpa ($qpa,
107 $qpa = $this->addMatchCondition($qpa, 'details');
108 $qpa = db_construct_qpa ($qpa,
111 if (count ($this->words)) {
112 $qpa = db_construct_qpa ($qpa,
113 'ORDER BY project_group_list.project_name, rank(vectors, q) DESC, project_task.project_task_id') ;
115 $qpa = db_construct_qpa ($qpa,
116 'ORDER BY project_group_list.project_name, project_task.project_task_id') ;
119 $qpa = db_construct_qpa ($qpa,
120 '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 ',
123 if ($this->sections != SEARCH__ALL_SECTIONS) {
124 $qpa = db_construct_qpa ($qpa,
125 'AND project_group_list.group_project_id = ANY ($1) ',
126 db_int_array_to_any_clause ($this->sections)) ;
128 if (!$this->showNonPublic) {
129 $qpa = db_construct_qpa ($qpa,
130 'AND project_group_list.is_public = 1 ') ;
132 $qpa = db_construct_qpa ($qpa,
134 $qpa = $this->addIlikeCondition ($qpa, 'summary') ;
135 $qpa = db_construct_qpa ($qpa,
137 $qpa = $this->addIlikeCondition ($qpa, 'details') ;
138 $qpa = db_construct_qpa ($qpa,
139 ')) ORDER BY project_group_list.project_name, project_task.project_task_id') ;
145 * getSections - returns the list of available subprojects
147 * @param $groupId int group id
148 * @param $showNonPublic boolean if we should consider non public sections
150 static function getSections($groupId, $showNonPublic=false) {
151 $sql = 'SELECT group_project_id, project_name FROM project_group_list WHERE group_id=$1' ;
152 if (!$showNonPublic) {
153 $sql .= ' AND is_public = 1';
155 $sql .= ' ORDER BY project_name';
158 $res = db_query_params ($sql,
160 while($data = db_fetch_array($res)) {
161 $sections[$data['group_project_id']] = $data['project_name'];
169 // c-file-style: "bsd"