-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
105 lines (89 loc) · 2.86 KB
/
search.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
<!DOCTYPE html>
<html>
<head>
<!-- Include Style Sheets -->
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php include 'searchbar.php' ?>
<div class="main">
<?php
require_once 'vendor/autoload.php';
require_once 'backend/artistgraph.php';
require_once 'backend/db.php';
/** Responsible for creating an artist listing
* @param Artist $artist
*
* @return [type]
*/
function display_artist(Artist $artist)
{
$image_url = $artist->get_smallest_image()['url'];
echo <<<EOL
<div class="artist-result" id="$artist->id">
<div class="artist_img-container">
<img class="artist_img" src="$image_url">
</div>
<div class="artist_info-container">
<div class="artist-name">
<a href="/artist.php?id=$artist->id"><b>$artist->name</b></a>
</div>
<i>Popularity: $artist->popularity</i><br>
EOL;
// print out genres here
echo "<i>";
$i = 0;
foreach ($artist->genres as $genre) {
echo $genre;
// formatting the commas
$i++;
if ($i < sizeof($artist->genres)) {
echo ", ";
}
}
echo "</i>";
// print out the artists button
echo <<<EOL
</div>
<br>
</div>
EOL;
}
/** Parent function which creates the main artist lists
* @param array $artists
*
* @return [type]
*/
function display_artist_list(array $artists)
{
echo "<ul class='artist_list'>";
foreach ($artists as $artist) {
echo "<li classname='artist_entry'>";
display_artist($artist);
echo "</li>";
}
echo "</ul>";
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// get the artist_name from the url
$artistname = urldecode($_GET['artist_name']);
$artistGraph = init_graph();
$artist = $artistGraph->get_artist($artistname);
// display_artist($artist);
if ($artist == null)
{
echo "<b>Artist not found :(</b>";
}
else {
$related = $artistGraph->get_related_artists($artist);
// add first result to the related
$related = array_merge([$artist,], $related);
display_artist_list($related);
}
?>
</div>
</body>
</html>