5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2004 (c) Guillaume Smet / Open Wide
7 * Copyright 2013, French Ministry of National Education
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfwww.'search/include/renderers/HtmlSearchRenderer.class.php';
27 require_once $gfcommon.'search/ProjectSearchQuery.class.php';
29 class ProjectHtmlSearchRenderer extends HtmlSearchRenderer {
32 * @param string $words words we are searching for
33 * @param int $offset offset
34 * @param bool $isExact if we want to search for all the words or if only one matching the query is sufficient
36 function __construct($words, $offset, $isExact) {
38 $searchQuery = new ProjectSearchQuery($words, $offset, $isExact);
40 parent::__construct(SEARCH__TYPE_IS_SOFTWARE, $words, $isExact, $searchQuery);
42 $this->tableHeaders = array(
49 * writeHeader - write the header of the output
51 function writeHeader() {
52 $GLOBALS['HTML']->header(array('title'=>_('Project Search'), 'pagename'=>'search'));
53 parent::writeHeader();
57 * getRows - get the html output for result rows
59 * @return string html output
62 $result = $this->searchQuery->getData($this->searchQuery->getRowsPerPage(),$this->searchQuery->getOffset());
67 foreach ($result as $row) {
70 .'<td style="width: 30%"><a href="'.util_make_url('/projects/'.$row['unix_group_name'].'/').'">'
71 .html_image('ic/msg.png', 10, 12)
72 .' '.$this->highlightTargetWords($row['group_name']).'</a></td>'
73 .'<td style="width: 70%">'.$this->highlightTargetWords($row['short_description']).'</td></tr>';
80 * redirectToResult - redirect the user directly to the result when there is only one matching result
82 function redirectToResult() {
83 $result = $this->searchQuery->getData(1)[0];
84 $project_name = $result['unix_group_name'];
85 $project_id = $result['group_id'];
87 $project_name = str_replace('<b>', '', $project_name);
88 $project_name = str_replace('</b>', '', $project_name);
90 if (forge_check_perm('project_read', $project_id)) {
91 header('Location: '.util_make_url_g($project_name,$project_id));
94 $html = '<h2>'.sprintf(_('Search results for ā%sā'), $project_name).'</h2>';
95 $html .= '<p><strong>'.sprintf(_('No matches found for ā%sā'), $project_name).'</strong></p>';