This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
/
QueryPlayingNowDB.php
65 lines (50 loc) · 1.58 KB
/
QueryPlayingNowDB.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
<?php
/*!
* LinnDS-jukebox
*
* Copyright (c) 2011-2015 Henrik Tolbøl, http://tolbøl.dk
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/
require_once("setup.php");
$RevNo = $_GET["RevNo"];
$db = new SQLite3($DATABASE_FILENAME);
$Queue = array();
$Queue[0] = array();
$Stmt = $db->prepare("SELECT MAX(Seq) As MaxSeq, MAX(LinnId) AS MaxLinnId FROM Sequence");
$result = $Stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
$Queue[0][MaxSeq] = $row[MaxSeq];
$Queue[0][MaxLinnId] = $row[MaxLinnId];
}
$Stmt->close();
$Stmt = $db->prepare("SELECT * FROM State");
$result = $Stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
$Queue[0][$row[Id]] = $row[Value];
}
$Stmt->close();
if ($RevNo == -1 || $Queue[0][RevNo] != $RevNo)
{
$QueueStmt = $db->prepare("SELECT S.Seq-L.Seq AS PlayState, Q.LinnId AS LinnId, S.Seq AS Seq, T.* FROM Queue Q, Sequence S, Tracks T, (SELECT S2.Seq FROM Sequence S2, (SELECT ST.value FROM State ST where ST.Id == 'LinnId') L2 WHERE S2.LinnId == L2.value) L WHERE Q.LinnId == S.LinnId AND Q.Preset == T.Preset AND Q.TrackSeq == T.TrackSeq ORDER BY S.Seq");
$result = $QueueStmt->execute();
$QueueCount = 1;
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
if ($row[PlayState] < 0)
$row[PlayState] = "Played";
else if ($row[PlayState] > 0)
$row[PlayState] = "Pending";
else
$row[PlayState] = "Playing";
$Queue[$QueueCount] = AbsoluteURL($row);
$QueueCount++;
}
$QueueStmt->close();
}
$db->close();
//print_r($Queue);
echo json_encode($Queue);
?>