Return a human readable view of the query result.
This method is intended to be a debugging aid and will return a pretty-print view of the query result.
bool $html Set to true to format the dump using HTML:
public function dump($html = true) {
if ($this->type == 'bindings') {
$result = '';
if ($html) {
$result .= "<table class='sparql-results' style='border-collapse:collapse'>";
$result .= "<tr>";
foreach ($this->fields as $field) {
$result .= "<th style='border:solid 1px #000;padding:4px;" . "vertical-align:top;background-color:#eee;'>" . "?{$field}</th>";
}
$result .= "</tr>";
foreach ($this as $row) {
$result .= "<tr>";
foreach ($this->fields as $field) {
$result .= "<td style='border:solid 1px #000;padding:4px;" . "vertical-align:top'>" . $row->{$field}
->dumpValue($html) . "</td>";
}
$result .= "</tr>";
}
$result .= "</table>";
}
else {
// First calculate the width of each comment
$colWidths = array();
foreach ($this->fields as $field) {
$colWidths[$field] = strlen($field);
}
$textData = array();
foreach ($this as $row) {
$textRow = array();
foreach ($row as $k => $v) {
$textRow[$k] = $v
->dumpValue(false);
$width = strlen($textRow[$k]);
if ($colWidths[$k] < $width) {
$colWidths[$k] = $width;
}
}
$textData[] = $textRow;
}
// Create a horizontal rule
$hr = "+";
foreach ($colWidths as $k => $v) {
$hr .= "-" . str_repeat('-', $v) . '-+';
}
// Output the field names
$result .= "{$hr}\n|";
foreach ($this->fields as $field) {
$result .= ' ' . str_pad("?{$field}", $colWidths[$field]) . ' |';
}
// Output each of the rows
$result .= "\n{$hr}\n";
foreach ($textData as $textRow) {
$result .= '|';
foreach ($textRow as $k => $v) {
$result .= ' ' . str_pad($v, $colWidths[$k]) . ' |';
}
$result .= "\n";
}
$result .= "{$hr}\n";
}
return $result;
}
elseif ($this->type == 'boolean') {
$str = $this->boolean ? 'true' : 'false';
if ($html) {
return "<p>Result: <span style='font-weight:bold'>{$str}</span></p>";
}
else {
return "Result: {$str}";
}
}
else {
throw new EasyRdf_Exception("Failed to dump SPARQL Query Results format, unknown type: " . $this->type);
}
}