-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_show.php
138 lines (129 loc) · 3.82 KB
/
search_show.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
// This file is part of Music Match.
// Copyright (C) 2022 David P. Anderson
//
// Music Match is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Music Match is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Music Match. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------
// rerun a search and display results, highlighting new results
require_once("../inc/util.inc");
require_once("../inc/mm.inc");
require_once("../inc/cp_profile.inc");
require_once("../inc/tech.inc");
require_once("../inc/ensemble.inc");
require_once("../inc/teacher.inc");
require_once("../inc/search.inc");
// $item is either a profile or an ensemble
//
function show_item($item, $role) {
switch ($role) {
case COMPOSER:
case PERFORMER:
cp_profile_summary_row($item, $role);
break;
case TECHNICIAN:
tech_summary_row($item);
break;
case ENSEMBLE:
ens_profile_summary_row($item);
break;
case TEACHER:
teacher_profile_summary_row($item);
break;
}
}
function show_search($search, $user) {
$params = json_decode($search->params);
$role = $params->role;
$args = add_missing_args($params->args, $role);
$view_results = json_decode($search->view_results);
page_head(sprintf("%s search results", role_name($role)));
switch ($role) {
case COMPOSER:
case PERFORMER:
$results = cp_search($role, $args, $user);
break;
case TECHNICIAN:
$results = tech_search($args, $user);
break;
case ENSEMBLE:
$results = ens_search($args, $user);
break;
case TEACHER:
$results = teacher_search($args, $user);
break;
}
if (!$results) {
echo "No results found.";
page_tail();
return;
}
start_table();
switch ($role) {
case COMPOSER:
case PERFORMER:
cp_profile_summary_header($role);
break;
case TECHNICIAN:
tech_summary_header();
break;
case ENSEMBLE:
ens_profile_summary_header();
break;
case TEACHER:
teacher_profile_summary_header();
break;
}
// see if have new results; if so, show them first
//
$have_new = false;
foreach ($results as $id=>$profile) {
if (!in_array($id, $view_results)) {
$have_new = true;
break;
}
}
if ($have_new) {
row1("New results", 99, 'success');
foreach ($results as $id=>$profile) {
if (!in_array($id, $view_results)) {
show_item($profile, $role);
}
}
row1("Previous results", 99, 'success');
}
foreach ($results as $id=>$profile) {
if (in_array($id, $view_results)) {
show_item($profile, $role);
}
}
end_table();
page_tail();
// update search record
//
$cur_results = [];
foreach ($results as $id=>$profile) {
$cur_results[] = $id;
}
$search->update(sprintf(
"view_results='%s', view_time=%d, rerun_time=0, rerun_nnew=0",
json_encode($cur_results), time()
));
}
$user = get_logged_in_user();
update_visit_time($user);
$search = Search::lookup_id(get_int('search_id'));
if (!$search) error_page('search not found');
if ($search->user_id != $user->id) error_page('not your search');
show_search($search, $user);
?>