Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f1cdc00
fix escape single quotes in kml
hannesvdvreken May 2, 2013
98b631e
Merge pull request #4 from hannesvdvreken/development
coreation May 2, 2013
7d23ee4
CSV formatter will now also publish non arrays
pietercolpaert May 7, 2013
00ecdf7
best effort formatter added for triples when method not implemented
pietercolpaert May 7, 2013
32a3540
best effort formatter added for triples when method not implemented
pietercolpaert May 7, 2013
f837cb9
use right http error code
pietercolpaert May 7, 2013
395a35a
Header first, then body
pietercolpaert May 8, 2013
967af4c
XML formatter now works for wrongfully passed rootnames.
coreation May 8, 2013
edfec30
Merge branch 'development' of github.com:tdt/formatters into development
coreation May 8, 2013
6a5875c
Small fixes in Map formatter, added Graph output for KML
pietercolpaert May 9, 2013
c4a4c3d
Requesting a map with https should no longer form a problem.
coreation May 10, 2013
464237a
Merge branch 'master' of github.com:tdt/formatters into development
May 12, 2013
d9f402c
added support for the page generator instead of using our own HTML ge…
May 12, 2013
fd880d2
JSON encode forward slashes not escaped
pietercolpaert May 15, 2013
338819f
Issue #7.
coreation May 17, 2013
6924eeb
performed string replace on forwarded slashes instead
pietercolpaert May 17, 2013
176115e
Merge branch 'development' of github.com:tdt/formatters into development
pietercolpaert May 17, 2013
47fbf19
Fixed #9: next page is now indicated
pietercolpaert May 17, 2013
a09597b
corrected #9
pietercolpaert May 17, 2013
0d79070
corrected #9
pietercolpaert May 17, 2013
d47d5a7
corrected #9
pietercolpaert May 17, 2013
028dc7e
corrected #9
pietercolpaert May 17, 2013
95b170c
corrected #9
pietercolpaert May 17, 2013
c67072f
Issue #28.
coreation May 17, 2013
d215c69
Merge branch 'development' of github.com:tdt/formatters into development
coreation May 17, 2013
a7ec073
predicate object in right order
pietercolpaert May 17, 2013
a2a0fa8
Merge branch 'development' of github.com:tdt/formatters into development
pietercolpaert May 17, 2013
65f70e3
Adde graph formatter
May 24, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"require": {
"tdt/negotiators" : "dev-master",
"tdt/exceptions" : "dev-master"
"tdt/exceptions" : "dev-master",
"tdt/pages" : "dev-master",
"mustache/mustache" : "dev-master"
},
"minimum-stability" : "dev",
"autoload": {
Expand Down
16 changes: 0 additions & 16 deletions example/easy.php

This file was deleted.

24 changes: 24 additions & 0 deletions example/graph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

require "../vendor/autoload.php";
use \tdt\formatters\Formatter;

// Test the bar formatter by adding "?values=cash,stocks" to the URI

// Create data
$data = new stdClass();
$data->chart = array();

for($i = 0; $i<20; $i++){
$item = new stdClass();
$item->cash = round(rand(0, 1000));
$item->stocks = round(rand(0, 1000));
array_push($data->chart, $item);
}

// Pass the format strategy as argument, when left empty, the content negotiator will be enabled
$f = new Formatter("GRAPH");
// The formatter will choose a strategy based on the the format strategy and based on the input.

// On execution, the formatter will detect $a is a stdClass and will format the output accordingly.
$f->execute("chart", $data);
1 change: 1 addition & 0 deletions includes/js/flot.min.js

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions includes/templates/graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<style>
#graph{
width: 100%;
min-height: 350px;
}

.choice{
float:left;
margin-left: 30px;
margin-top: 5px;
margin-bottom: 5px;

input{
display:inline-block;
}
}
</style>

<h4>{{title}}</h4>
<br/>
<div id="graph"></div>
<br/>
<h5>Toggle dataseries</h5>
<div id="choices"></div>


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
{{&flotjs}}


var datasets = [{{{data}}}];

// insert checkboxes
var choiceContainer = $("#choices");
$.each(datasets, function(key, val) {
choiceContainer.append("<div class='choice'><input type='checkbox' name='" + key +
"' checked='checked' id='id" + key + "'></input>" +
"<label for='id" + key + "'>" + val.label + "</label></div>");
});
choiceContainer.find("input").click(plotAccordingToChoices);

function plotAccordingToChoices() {
var data = [];

choiceContainer.find("input:checked").each(function () {
var key = $(this).attr("name");
if (key && datasets[key]) {
data.push(datasets[key]);
}
});

if (data.length > 0) {
$.plot("#graph", data, {
series: {
hoverable: true,
clickable: true,
stack: true,
{{type}}: {
show: true,
fill: true
}
}
});
}
}
plotAccordingToChoices();
</script>
37 changes: 34 additions & 3 deletions src/tdt/formatters/AStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
namespace tdt\formatters;
use tdt\exceptions\TDTException;

use tdt\pages\Generator;
abstract class AStrategy {
protected $rootname;
protected $objectToPrint;
Expand Down Expand Up @@ -50,6 +50,10 @@ public function execute() {
* This function checks wether the object to print is an RDF graph or not
*/
protected function isObjectAGraph() {

if($this->objectToPrint instanceof \ARC2_RDFXMLParser)
return true;

foreach ($this->objectToPrint as $prop)
return ($prop instanceof \ARC2_RDFParser);

Expand All @@ -70,7 +74,34 @@ abstract public function printBody();
* This function will print the body of the responsemessage when the object is a graph.
*/
public function printGraph(){
throw new TDTException(453);
set_error_header(453, "RDF not supported");
$generator = new Generator($this->rootname . " - formatter cannot process RDF");
$body ="";
$body .= "<h1>Formatter doesn't support RDF</h1>";

$body .= "<p>We don't have a triple output for this formatter yet. This is a best effort in HTML.</p>";
$body .= "<p>There are plenty of RDF formatters which do work however. Check .ttl or .json for instance.</p>";
$rn = $this->rootname;
$body .= "<table border=3>";
$body .= "<tr><td>subject</td><td>predicate</td><td>object</td></tr>";
foreach($this->objectToPrint->$rn->triples as $triple){
$body .= "<tr><td>". $triple["s"] ."</td>";
$body .= "<td>". $triple["p"] ."</td>";
$body .= "<td>". $triple["o"] ."</td>";

$body .= "</tr>";
}
$body .= "</table>";
$h = headers_list();
$i = 0;
$matches = array();
while($i < sizeof($h) && !preg_match( "/Link: (.+);rel=next.*/" , $h[$i], $matches)){
$i++;
}
if($i < sizeof($h)){
$body .= "<p class='nextpage'><a href='". $matches[1] ."'>Next page</a></p>";
}
$generator->generate($body);
}

}
}
106 changes: 0 additions & 106 deletions src/tdt/formatters/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,109 +82,12 @@ private function formatExists($format) {
public function execute($rootname, $thing) {
$format = "\\tdt\\formatters\\strategies\\" . $this->format;
$strategy = new $format($rootname, $thing);

//Didn't really make sense to split the formats up, so for the moment this is commented
/**
* Check if which formatter we're dealing with (normal object formatter or ARC grap formatter)
* According to the result of this control check, convert (if necessary the object to the appropriate object structure e.g. from graph to php object or vice versa)
*/
/*if (!$this->isObjectAGraph($thing)) {
if (array_key_exists('tdt\\formatters\\interfaces\\iSemanticFormatter', class_implements($strategy))) {
$thing = $this->convertPHPObjectToARC($thing);
}
} else {
if (!array_key_exists('tdt\\formatters\\interfaces\\iSemanticFormatter', class_implements($strategy))) {
$thing = $this->convertARCToPHPObject($thing);
}
}*/

// remake the formatting strategy
//$strategy = new $format($rootname, $thing);
$strategy->execute();
}

//This logic has moved to AStrategy and will probably stay there. For now, keep it commented.

// protected function isObjectAGraph($object) {
// foreach ($object as $class => $prop)
// return ($prop instanceof \ARC2_RDFParser);
//
// return false;
// }
//
// protected function convertPHPObjectToARC($object) {
// //REWRITE
//// //Unwrap the object
//// foreach ($this->objectToPrint as $class => $prop){
//// if (is_a($prop,"MemModel")){
//// $this->objectToPrint = $prop;
//// break;
//// }
//// }
//// //When the objectToPrint has a MemModel, it is already an RDF model and is ready for serialisation.
//// //Else it's retrieved data of which we need to build an rdf output
//// if (!is_a($this->objectToPrint,"MemModel")) {
//// $outputter = new RDFOutput();
//// $this->objectToPrint = $outputter->buildRdfOutput($this->objectToPrint);
//// }
////
//// // Import Package Syntax
//// include_once(RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3);
////
//// $ser = new N3Serializer();
////
//// $rdf = $ser->serialize($this->objectToPrint);
//
// throw new \Exception("This resource does not contain semantic information");
//
//
// return $object;
// }
//
// protected function convertARCToPHPObject($graph) {
// foreach ($graph as $class => &$prop) {
// //$graph->$class = $object;
// $index = $prop->getSimpleIndex();
//
// //$result = $this->stripObject($index);
// $result = $index;
// $graph->$class = $result;
// return $graph;
// }
// return $graph;
// }
//
// private function stripObject($obj, $result = array()) {
//
// foreach ($obj as $key => $value) {
//
// $new_key = $this->stripURI($key);
// $result[$new_key] = array();
//
// if (is_array($value))
// $result[$new_key] = $this->stripObject($value, $result[$new_key]);
// else
// $result[$new_key] = $this->stripURI($value);
// }
//
// return $result;
// }
//
// private function stripURI($uri) {
// $pos = strrpos($uri, "#");
//
// if (!$pos)
// $pos = strrpos($uri, "/");
//
//
// if (!$pos)
// $pos = strrpos($uri, ":");
//
// if (!$pos)
// return $uri;
//
// return substr($uri, $pos+1);
// }

/**
* Returns the format that has been set by the request
Expand All @@ -209,15 +112,6 @@ public function getFormatterDocumentation() {

if (is_subclass_of($classname, "tdt\\formatters\\AStrategy")) {

/*
* Get the name without Formatter as $formattername
*/
/* $matches = array();
preg_match('/(.*)Formatter.*', $classname, $matches);
if (isset($matches[1])) {
$formattername = $matches[1];
} */

/*
* Remove the namespace if present from the formattername
*/
Expand Down
Loading