<?php
include_once("includes/base.inc");

$page = new Page("/");
$page->event = "groups";
$page->name = "Food Groups";
$page->title = "Food Groups";
$page->body = "<h2>Food Groups</h2>";
$page->body .= "<p>Food group information is extracted from the USDA's National Nutrient Database, Standard Release 23. Each food group represents a class of foods with different characteristics. The database contains the following food groups:</p><ul>";

$doc = new DOMDocument();
$doc->load("http://localhost:2020/books?query=".urlencode("PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX nndsr: <http://semanticdiet.com/schema/usda/nndsr/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?s ?label WHERE { ?s a nndsr:FoodGroup . ?s rdfs:label ?label } ORDER BY ?label"));
$results = $doc->getElementsByTagName("result");
$len = $results->length;
for($i=0;$i<$len;$i++) {
  $uri = ""; $label = "";
  $bindings = $results->item($i)->getElementsByTagName("binding");
  $blen = $bindings->length;
  for($j=0;$j<$blen;$j++) {
    $binding = $bindings->item($j);
    if($binding->getAttribute("name")=="s") {
      $uri = $binding->textContent;
    }
    if($binding->getAttribute("name")=="label") {
      $label = $binding->textContent;
    }
  }
  $page->body .= "<li><a href=\"$uri\">$label</a></li>";
}

$page->body .= "</ul>";

$currentTheme->render($page);

?>
