|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Enalean, 2014. All Rights Reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is a part of Tuleap. |
|
6
|
|
|
* |
|
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
class Search_SearchTrackerV3 { |
|
22
|
|
|
const NAME = 'tracker'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ArtifactDao |
|
26
|
|
|
*/ |
|
27
|
|
|
private $dao; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function __construct(ArtifactDao $dao) { |
|
31
|
|
|
$this->dao = $dao; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function search(Search_SearchQuery $query, Search_SearchResults $search_results) { |
|
35
|
|
|
include_once('www/tracker/include/ArtifactTypeHtml.class.php'); |
|
36
|
|
|
include_once('www/tracker/include/ArtifactHtml.class.php'); |
|
37
|
|
|
|
|
38
|
|
|
$project = $query->getProject(); |
|
39
|
|
|
if ($project->isError()) { |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
$group_id = $project->getId(); |
|
43
|
|
|
$words = $query->getWords(); |
|
44
|
|
|
$exact = $query->getExact(); |
|
45
|
|
|
$offset = $query->getOffset(); |
|
46
|
|
|
$atid = $query->getTrackerV3Id(); |
|
47
|
|
|
|
|
48
|
|
|
ob_start(); |
|
49
|
|
|
// |
|
50
|
|
|
// Create the ArtifactType object |
|
51
|
|
|
// |
|
52
|
|
|
$ath = new ArtifactTypeHtml($project, $atid); |
|
53
|
|
|
if (!$ath || !is_object($ath)) { |
|
54
|
|
|
exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error')); |
|
55
|
|
|
} |
|
56
|
|
|
if ($ath->isError()) { |
|
57
|
|
|
exit_error($GLOBALS['Language']->getText('global', 'error'), $ath->getErrorMessage()); |
|
58
|
|
|
} |
|
59
|
|
|
// Check if this tracker is valid (not deleted) |
|
60
|
|
|
if (!$ath->isValid()) { |
|
61
|
|
|
exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$results = $this->dao->searchGlobalPaginated($words, $exact, $offset, $atid, UserManager::instance()->getCurrentUser()->getUgroups($group_id, $atid), $query->getNumberOfResults()); |
|
65
|
|
|
$rows_returned = $this->dao->foundRows(); |
|
66
|
|
|
|
|
67
|
|
|
$art_displayed = 0; |
|
68
|
|
|
if ($rows_returned < 1) { |
|
69
|
|
|
echo '<H2>' . $GLOBALS['Language']->getText('search_index', 'no_match_found', htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8')) . '</H2>'; |
|
70
|
|
|
} else { |
|
71
|
|
|
// Create field factory |
|
72
|
|
|
$art_field_fact = new ArtifactFieldFactory($ath); |
|
73
|
|
|
|
|
74
|
|
|
echo '<H3>' . $GLOBALS['Language']->getText('search_index', 'search_res', array(htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8'), $rows_returned)) . "</H3><P>\n"; |
|
75
|
|
|
|
|
76
|
|
|
$title_arr = array(); |
|
77
|
|
|
|
|
78
|
|
|
$summary_field = $art_field_fact->getFieldFromName("summary"); |
|
79
|
|
|
if ($summary_field->userCanRead($group_id, $atid)) |
|
80
|
|
|
$title_arr[] = $GLOBALS['Language']->getText('search_index', 'artifact_summary'); |
|
81
|
|
|
$submitted_field = $art_field_fact->getFieldFromName("submitted_by"); |
|
82
|
|
|
if ($submitted_field->userCanRead($group_id, $atid)) |
|
83
|
|
|
$title_arr[] = $GLOBALS['Language']->getText('search_index', 'submitted_by'); |
|
84
|
|
|
$date_field = $art_field_fact->getFieldFromName("open_date"); |
|
85
|
|
|
if ($date_field->userCanRead($group_id, $atid)) |
|
86
|
|
|
$title_arr[] = $GLOBALS['Language']->getText('search_index', 'date'); |
|
87
|
|
|
$status_field = $art_field_fact->getFieldFromName("status_id"); |
|
88
|
|
|
if ($status_field->userCanRead($group_id, $atid)) |
|
89
|
|
|
$title_arr[] = $GLOBALS['Language']->getText('global', 'status'); |
|
90
|
|
|
|
|
91
|
|
|
echo html_build_list_table_top($title_arr); |
|
92
|
|
|
|
|
93
|
|
|
echo "\n"; |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
$rows = 0; |
|
97
|
|
|
foreach ($results as $arr) { |
|
|
|
|
|
|
98
|
|
|
$rows++; |
|
99
|
|
|
$curArtifact = new Artifact($ath, $arr['artifact_id']); |
|
100
|
|
|
if ($curArtifact->isStatusClosed($curArtifact->getStatusID())) { |
|
101
|
|
|
$status = $GLOBALS['Language']->getText('global', 'closed'); |
|
102
|
|
|
} else { |
|
103
|
|
|
$status = $GLOBALS['Language']->getText('global', 'open'); |
|
104
|
|
|
} |
|
105
|
|
|
// Only display artifacts that the user is allowed to see |
|
106
|
|
|
if ($curArtifact->userCanView(user_getid())) { |
|
107
|
|
|
print "\n<TR class=\"" . html_get_alt_row_color($art_displayed) . "\">"; |
|
108
|
|
|
if ($summary_field->userCanRead($group_id, $atid)) |
|
109
|
|
|
print "<TD><A HREF=\"/tracker/?group_id=$group_id&func=detail&atid=$atid&aid=" |
|
110
|
|
|
. $arr['artifact_id'] . "\"><IMG SRC=\"" . util_get_image_theme('msg.png') . "\" BORDER=0 HEIGHT=12 WIDTH=10> " |
|
111
|
|
|
. $arr['summary'] . "</A></TD>"; |
|
112
|
|
|
if ($submitted_field->userCanRead($group_id, $atid)) |
|
113
|
|
|
print "<TD>" . $arr['user_name'] . "</TD>"; |
|
114
|
|
|
if ($date_field->userCanRead($group_id, $atid)) |
|
115
|
|
|
print "<TD>" . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $arr['open_date']) . "</TD>"; |
|
116
|
|
|
if ($status_field->userCanRead($group_id, $atid)) |
|
117
|
|
|
print "<TD>" . $status . "</TD>"; |
|
118
|
|
|
print "</TR>"; |
|
119
|
|
|
$art_displayed++; |
|
120
|
|
|
if ($art_displayed > $query->getNumberOfResults()) { |
|
121
|
|
|
break; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
echo "</TABLE>\n"; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$maybe_more_results = ($art_displayed < $query->getNumberOfResults()) ? false : true; |
|
129
|
|
|
$search_results->setCountResults($art_displayed) |
|
130
|
|
|
->setHasMore($maybe_more_results); |
|
131
|
|
|
|
|
132
|
|
|
return new Search_SearchTrackerV3ResultPresenter(ob_get_clean()); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getFacets(Project $project) { |
|
136
|
|
|
$trackers_v3 = $this->getTrackersV3ForProject($project); |
|
137
|
|
|
$facets = array(); |
|
138
|
|
|
|
|
139
|
|
|
foreach ($trackers_v3 as $tracker_v3) { |
|
|
|
|
|
|
140
|
|
|
$facets[] = array( |
|
141
|
|
|
'title' => $tracker_v3->getName(), |
|
142
|
|
|
'extra-parameters' => array( |
|
143
|
|
|
'key' => 'data-atid', |
|
144
|
|
|
'value' => $tracker_v3->getID() |
|
145
|
|
|
) |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return new Search_SearchTypePresenter( |
|
150
|
|
|
Search_SearchTrackerV3::NAME, |
|
151
|
|
|
$GLOBALS['Language']->getText('project_admin_editservice', 'service_tracker_lbl_key'), |
|
152
|
|
|
$facets |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
private function getTrackersv3ForProject(Project $project) { |
|
157
|
|
|
$artifact_type_factory = new ArtifactTypeFactory($project); |
|
158
|
|
|
|
|
159
|
|
|
return $artifact_type_factory->getArtifactTypes(); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.