<?php
/* Include ARC2 classes. */
include_once("arc/ARC2.php");

/* Configure the app to use DBTune. */
$dbtconfig = array(
  "remote_store_endpoint" => "http://dbtune.org/musicbrainz/sparql",
);

/* Create the 'remote store' */
$dbtune = ARC2::getRemoteStore($dbtconfig);

/* Let's start with some artist (Brian Eno). */
$mbid = "ff95eb47-41c4-4f7f-a104-cdc30f02e872";
if ($_GET['mbid']) {
  $mbid = $_GET['mbid'];
}
$uri = "http://dbtune.org/musicbrainz/resource/artist/$mbid";

/* Let's get some MusicBrainz data about the artist. */
$q = "
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX vocab: <http://dbtune.org/musicbrainz/resource/vocab/>
PREFIX mo: <http://purl.org/ontology/mo/>

SELECT ?name ?sortname ?musicbrainz
WHERE
 { <$uri> rdfs:label ?name ;
          vocab:sortname ?sortname ;
          mo:musicbrainz ?musicbrainz . }
";
$artist = $dbtune->query($q, 'row');

/* And let's pull up his records. */
$q = "
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX vocab: <http://dbtune.org/musicbrainz/resource/vocab/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>

SELECT DISTINCT ?name ?amazon ?coverarturl ?date ?trackcount ?musicbrainz
WHERE
 { ?record foaf:maker <$uri> ;
           dc:title ?name ;
           mo:amazon_asin ?amazon ;
           vocab:albummeta_coverarturl ?coverarturl ;
           dc:date ?date ;
           vocab:tracks ?trackcount ;
           mo:musicbrainz ?musicbrainz . } 
ORDER BY ?date
";
$albums = $dbtune->query($q, 'rows');
?>
<html>
<head>
<title>Artist: <?=$artist['name']?></title>
</head>
<body>
<h1><?=$artist['name']?></h1>
<p>(<?=$artist['sortname']?>)</p>
<p>(<a href="<?=$artist['musicbrainz']?>">MusicBrainz</a>)</p>
<table>
<thead>
<tr>
<th></th>
<th>Album</th>
<th>Release</th>
<th>Tracks</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($albums as $album) {
?>
<tr>
<td><img src="<?=$album['coverarturl']?>" style="width: 72px; height: 72px;"/></td>
<td><?=$album['name']?></td>
<td><?=$album['date']?></td>
<td><?=$album['trackcount']?></td>
<td><a href="<?=$album['musicbrainz']?>">MusicBrainz</a></td>
<td><a href="<?=$album['amazon']?>">Amazon</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>