1 | <?php |
---|
2 | |
---|
3 | class SurveyRDFWriter |
---|
4 | { |
---|
5 | protected $model; |
---|
6 | |
---|
7 | protected $resourceDashboard; |
---|
8 | protected $dashboardID; |
---|
9 | |
---|
10 | protected $filePath; |
---|
11 | |
---|
12 | public function __construct($dashboardID) |
---|
13 | { |
---|
14 | // Create empty MemModel |
---|
15 | $factory = new ModelFactory(); |
---|
16 | $this->model = $factory->getDefaultModel(); |
---|
17 | |
---|
18 | $this->dashboardID = $dashboardID; |
---|
19 | $this->filePath = 'data/dashboards/'; |
---|
20 | if (!is_dir($this->filePath)) |
---|
21 | mkdir($this->filePath); |
---|
22 | } |
---|
23 | |
---|
24 | public function saveDashboard() |
---|
25 | { |
---|
26 | $this->model->saveAs($this->filePath.'dashboard_'.$this->dashboardID.'.rdf','rdf'); |
---|
27 | } |
---|
28 | |
---|
29 | public function createDashboard($dTitle, $dDescription,$dRespondentGroup) |
---|
30 | { |
---|
31 | $this->resourceDashboard = new Resource(DASHBOARD.'/'.$this->dashboardID); |
---|
32 | |
---|
33 | $resourceDashboardType = new Resource(DASHBOARD); |
---|
34 | $predicateRType = new Resource(RTYPE); |
---|
35 | $this->model->add(new Statement($this->resourceDashboard,$predicateRType,$resourceDashboardType)); |
---|
36 | |
---|
37 | $literalDashboardID = new Literal($this->dashboardID); |
---|
38 | $predicateUniqueID = new Resource(UID); |
---|
39 | $this->model->add(new Statement($this->resourceDashboard,$predicateUniqueID,$literalDashboardID)); |
---|
40 | |
---|
41 | $predicateTitle = new Resource(TITLE); |
---|
42 | $dashboardTitle = new Literal($dTitle); |
---|
43 | $this->model->add(new Statement($this->resourceDashboard,$predicateTitle,$dashboardTitle)); |
---|
44 | |
---|
45 | $predicateDescription = new Resource(DESCRIPTION); |
---|
46 | $dashboardDescription = new Literal($dDescription); |
---|
47 | $this->model->add(new Statement($this->resourceDashboard,$predicateDescription,$dashboardDescription)); |
---|
48 | } |
---|
49 | |
---|
50 | public function addGraph($gTitle,$gDescription,$gTypes,$gData) |
---|
51 | { |
---|
52 | $resourceGraph = new Resource(GRAPH); |
---|
53 | |
---|
54 | $predicateTitle = new Resource(TITLE); |
---|
55 | $graphTitle = new Literal($gTitle); |
---|
56 | $this->model->add(new Statement($resourceGraph,$predicateTitle,$graphTitle)); |
---|
57 | |
---|
58 | $predicateDescription = new Resource(DESCRIPTION); |
---|
59 | $graphDescription = new Literal($gDescription); |
---|
60 | $this->model->add(new Statement($resourceGraph,$predicateDescription,$graphDescription)); |
---|
61 | |
---|
62 | $predicateGraphType = new Resource(GRAPH_TYPE); |
---|
63 | foreach($gTypes as $gType) |
---|
64 | { |
---|
65 | $graphType = new Literal($gType); |
---|
66 | $this->model->add(new Statement($resourceGraph,$predicateGraphType,$gType)); |
---|
67 | } |
---|
68 | |
---|
69 | $predicateData = new Resource(DATA); |
---|
70 | foreach($gData as $gThis) |
---|
71 | { |
---|
72 | $graphData = new Literal($gThis); |
---|
73 | $this->model->add(new Statement($resourceGraph,$predicateData,$graphData)); |
---|
74 | } |
---|
75 | |
---|
76 | $predicateHasGraph = new Resource(HAS_GRAPH); |
---|
77 | $this->model->add(new Statement($this->resourceDashboard,$predicateHasGraph,$resourceGraph)); |
---|
78 | } |
---|
79 | } |
---|
80 | ?> |
---|