5 * Copyright 2004 (c) Dominik Haas, GForge Team
6 * Copyright 2011, Franck Villaume - Capgemini
7 * Copyright 2013, French Ministry of National Education
8 * Copyright 2013,2015, Franck Villaume - TrivialDev
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfwww.'search/include/renderers/HtmlSearchRenderer.class.php';
28 require_once $gfcommon.'search/DocsSearchQuery.class.php';
29 require_once $gfcommon.'docman/Document.class.php';
31 class DocsAllHtmlSearchRenderer extends HtmlSearchRenderer {
34 * @param string $words words we are searching for
35 * @param int $offset offset
36 * @param bool $isExact if we want to search for all the words or if only one matching the query is sufficient
37 * @param array|string $sections array of all sections to search in (array of strings)
39 function __construct($words, $offset, $isExact, $sections = SEARCH__ALL_SECTIONS) {
40 $groupIdValidArr = array();
42 if (session_loggedin()) {
43 $u =& session_get_user();
44 $listGroups = $u->getGroups();
45 if (count($listGroups) > 0) {
46 foreach ($listGroups as $group) {
47 if (forge_check_perm('docman', $group->getID(), 'read')) {
48 $groupIdValidArr[] = $group->getID();
53 $searchQuery = new DocsSearchQuery($words, $offset, $isExact, $groupIdValidArr, $sections);
54 parent::__construct(SEARCH__TYPE_IS_ALLDOCS, $words, $isExact, $searchQuery);
55 $this->tableHeaders = array(
65 * writeHeader - write the header of the output
67 function writeHeader() {
68 $GLOBALS['HTML']->header(array('title'=>_('Search for documents')));
69 parent::writeHeader();
73 * getRows - get the html output for result rows
75 * @return string html output
79 $result = $this->searchQuery->getData($this->searchQuery->getRowsPerPage(),$this->searchQuery->getOffset());
80 $rowsCount = count($result);
85 $lastDocGroupID = null;
89 foreach ($result as $row) {
91 $document = document_get_object($row['docid'], $row['group_id']);
92 $currentDocGroup = $row['project_name'];
93 if ($lastGroupID != $document->Group->getID()) {
94 $cells[] = array(html_image('ic/home16b.png', 10, 12).html_e('strong', array(), util_make_link('/docman/?group_id='.$document->Group->getID(),$currentDocGroup)), 'colspan' => 4);
95 $lastGroupID = $document->Group->getID();
97 $return .= $HTML->multiTableRow(array(), $cells);
100 $cells[][] = ' ';
101 if ($lastDocGroupID != $document->getDocGroupID()) {
102 $cells[][] = html_image('ic/folder.png', 22, 22).util_make_link('/docman/?group_id='.$document->Group->getID().'&view=listfile&dirid='.$document->getDocGroupID(),$row['groupname']);
103 $lastDocGroupID = $document->getDocGroupID();
105 $cells[][] = ' ';
107 if ($document->isURL()) {
108 $cells[][] = util_make_link($document->getFileName(), html_image($document->getFileTypeImage(), 22, 22), array('title' => _('Visit this link')), true);
110 $cells[][] = util_make_link('/docman/view.php/'.$row['group_id'] . '/'.$row['docid'].'/'.$row['filename'], html_image($document->getFileTypeImage(), 22, 22), array('title' => _('View this document')));
112 $cells[][] = $row['title'];
113 $cells[][] = $row['description'];
114 $return .= $HTML->multiTableRow(array(), $cells);