-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
167 lines (134 loc) · 4.08 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
include("includes/includedFiles.php");
if (isset($_GET['term'])) {
$term = urldecode($_GET['term']);
} else {
$term = "";
}
?>
<div class="search-container">
<h4>Search</h4>
<input type="text" class="search" value="<?php echo $term; ?>" placeholder="Artist, Album or Song" onfocus="this.value = this.value">
</div>
<script>
$(".search").focus();
$(function() {
$(".search").keyup(function() {
clearTimeout(timer);
timer = setTimeout(function() {
var val = $(".search").val()
openPage("search.php?term=" + val)
}, 2000);
})
})
</script>
<?php if ($term == "") exit(); ?>
<!--
Song List
-->
<div class="track-section border-bottom">
<h2> Songs </h2>
<ul class="track-list">
<?php
$songQuery = ("SELECT id FROM songs WHERE title LIKE '$term%' LIMIT 10");
$songs = $pdo->prepare($songQuery);
$songs->execute();
$results = $songs->fetchAll(PDO::FETCH_ASSOC);
$rowCount = $songs->rowCount();
if($rowCount == 0) {
echo " <span class='no-results'> No matching songs results for " . $term . "</span>";
}
$songArray = array();
$i = 1; // To count track
foreach ($results as $songId) {
$albumSong = new Song($pdo, $songId["id"]);
$albumList = $albumSong->getArtist();
if ($i > 15) {
break;
}
array_push($songArray, $songId);
echo "<li class='track-item'>
<div class='track-count'>
<i class='fa fa-play-circle-o' aria-hidden='true' onclick='setTrack( {id: " . $albumSong->getId() ."}, tempPlayList, true)'></i>
<span class='track-number'>$i</span>
</div>
<div class='track-info'>
<span id='track-name'>" . $albumSong->getTitle() . "</span>
<span id='artist-name'>" . $albumList->getName() . "</span>
</div>
<div class='track-options'>
<input type='hidden' class='song-id' value='" . $albumSong->getId() . "'>
<i id='options-button' class='fa fa-caret-down' aria-hidden='true' onclick='showOptionsMenu(this)'></i>
</div>
<div class='track-duration'>
<span class='duration'>" . $albumSong->getDuration() . "</span>
</div>
</li>";
$i++; // To count track
}
?>
<script>
var tempSongsIds = '<?php echo json_encode($songArray); ?>';
tempPlayList = JSON.parse(tempSongsIds);
</script>
</ul> <!-- track-list"-->
</div> <!-- track-section -->
<!--
Artist List
-->
<div class="artist-section border-bottom">
<h2> Artists </h2>
<?php
$artistQuery = ("SELECT id FROM artists WHERE name LIKE '$term%' LIMIT 10");
$artists = $pdo->prepare($artistQuery);
$artists->execute();
$results = $artists->fetchAll(PDO::FETCH_ASSOC);
$rowCount = $artists->rowCount();
if ($rowCount == 0) {
echo "<span class='no-results'> No matching artist results for " . $term . "</span>";
}
foreach ($results as $artistId) {
$artistFound = new Artist($pdo, $artistId['id']);
echo "<div class='search-result-row'>
<div id='artist-name'>
<span role='link' tabindex='0' onclick='openPage(\"artist.php?id=" . $artistFound->getId() ."\")'>
"
. $artistFound->getName() .
"
</span>
</div>
</div>";
}
?>
</div>
<!--
Album List
-->
<div class="album-container container">
<h2>Albums</h2>
<div class="row">
<?php
$albumQuery = ("SELECT * FROM albums WHERE title LIKE '$term%' LIMIT 10");
$albumQueries = $pdo->prepare($albumQuery, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$albumQueries->execute();
$rowCount = $albumQueries->rowCount();
if($rowCount == 0) {
echo " <span class='no-results'> No matching albums results for " . $term . "</span>";
}
foreach ($albumQueries as $album) {
echo "<div class='card-view'>
<span onclick='openPage(\"album.php?id=" . $album['id'] . "\")' tabindex='0'>
<img src='". $album['artworkPath'] . "'>
<div class='album-caption'>"
. $album['title'] .
"</div>
</span>
</div>";
}
?>
</div>
</div> <!-- album-container -->
<nav class="options-menu">
<input type="hidden" class="song-id">
<?php echo Playlist::getPlaylistsDropdown($pdo, $userLoggedIn->getUserName()); ?>
</nav>