1 | <?php
|
---|
2 |
|
---|
3 | class ApplicationRDFReader
|
---|
4 | {
|
---|
5 | protected $model;
|
---|
6 | protected $fileName;
|
---|
7 |
|
---|
8 | public function __construct()
|
---|
9 | {
|
---|
10 | $this->fileName = 'data/applications/applications.rdf';
|
---|
11 |
|
---|
12 | $this->reloadApplications();
|
---|
13 | }
|
---|
14 |
|
---|
15 | public function reloadApplications()
|
---|
16 | {
|
---|
17 | // Create empty MemModel
|
---|
18 | $factory = new ModelFactory();
|
---|
19 | $this->model = $factory->getDefaultModel();
|
---|
20 |
|
---|
21 | if(file_exists($this->fileName))
|
---|
22 | $this->model->load($this->fileName);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public function readApplicationInfo($applicationID)
|
---|
26 | {
|
---|
27 | $this->reloadApplications();
|
---|
28 |
|
---|
29 | $querystring = '
|
---|
30 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
31 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
32 | SELECT ?title ?description ?style
|
---|
33 | WHERE
|
---|
34 | {
|
---|
35 | _application predicates:resource_type resources:application ;
|
---|
36 | predicates:uid "' . $applicationID . '" ;
|
---|
37 | predicates:title ?title ;
|
---|
38 | predicates:description ?description ;
|
---|
39 | predicates:style ?style
|
---|
40 | }';
|
---|
41 |
|
---|
42 | $result = $this->model->sparqlQuery($querystring);
|
---|
43 |
|
---|
44 | return $result;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public function readAllApplications()
|
---|
48 | {
|
---|
49 | $result = array();
|
---|
50 | $result[] = $this->readApplicationIDs();
|
---|
51 | $result[] = $this->readApplicationTitles();
|
---|
52 | $result[] = $this->readApplicationDescriptions();
|
---|
53 | $result[] = $this->readApplicationStyles();
|
---|
54 |
|
---|
55 | return $result;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public function readApplicationIDs()
|
---|
59 | {
|
---|
60 | $querystring = '
|
---|
61 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
62 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
63 | SELECT ?uid
|
---|
64 | WHERE
|
---|
65 | {
|
---|
66 | _application predicates:resource_type resources:application ;
|
---|
67 | predicates:uid ?uid
|
---|
68 | }';
|
---|
69 |
|
---|
70 | $result = $this->model->sparqlQuery($querystring);
|
---|
71 |
|
---|
72 | return $result;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public function readApplicationTitles()
|
---|
76 | {
|
---|
77 | $querystring = '
|
---|
78 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
79 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
80 | SELECT ?title
|
---|
81 | WHERE
|
---|
82 | {
|
---|
83 | _application predicates:resource_type resources:application ;
|
---|
84 | predicates:title ?title
|
---|
85 | }';
|
---|
86 |
|
---|
87 | $result = $this->model->sparqlQuery($querystring);
|
---|
88 |
|
---|
89 | return $result;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public function readApplicationDescriptions()
|
---|
93 | {
|
---|
94 | $querystring = '
|
---|
95 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
96 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
97 | SELECT ?description
|
---|
98 | WHERE
|
---|
99 | {
|
---|
100 | _application predicates:resource_type resources:application ;
|
---|
101 | predicates:description ?description
|
---|
102 | }';
|
---|
103 |
|
---|
104 | $result = $this->model->sparqlQuery($querystring);
|
---|
105 |
|
---|
106 | return $result;
|
---|
107 | }
|
---|
108 |
|
---|
109 | public function readApplicationStyles()
|
---|
110 | {
|
---|
111 | $querystring = '
|
---|
112 | PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
|
---|
113 | PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
|
---|
114 | SELECT ?style
|
---|
115 | WHERE
|
---|
116 | {
|
---|
117 | _application predicates:resource_type resources:application ;
|
---|
118 | predicates:style ?style
|
---|
119 | }';
|
---|
120 |
|
---|
121 | $result = $this->model->sparqlQuery($querystring);
|
---|
122 |
|
---|
123 | return $result;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | ?> |
---|