1 | <?php |
---|
2 | /** |
---|
3 | * Description of ResearchToolObject |
---|
4 | * |
---|
5 | * @author jkraaijeveld |
---|
6 | */ |
---|
7 | // Survey database interface class as intermediate for storing data from the site to the RDF database |
---|
8 | require_once 'rdfConstants.php'; |
---|
9 | // Include RAP Library to write RDF files |
---|
10 | include(RDFAPI_INCLUDE_DIR . "RDFAPI.php"); |
---|
11 | |
---|
12 | |
---|
13 | abstract class ResearchToolObject implements ResearchToolObjectInterface { |
---|
14 | |
---|
15 | public $uid = null; |
---|
16 | |
---|
17 | public function getUid() { |
---|
18 | return $this->uid; |
---|
19 | } |
---|
20 | |
---|
21 | public function evaluate() |
---|
22 | { |
---|
23 | return true; |
---|
24 | } |
---|
25 | |
---|
26 | public static function load($filename) |
---|
27 | { |
---|
28 | $model = ModelFactory::getDefaultModel(); |
---|
29 | if(file_exists($filename)) |
---|
30 | $model->load($filename); |
---|
31 | return $model; |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * function stripUri($inString) |
---|
36 | * @param type $inString |
---|
37 | * Takes a URI and creates a new array which contains the type and the uid of the object |
---|
38 | */ |
---|
39 | public static function stripUri($inString) |
---|
40 | { |
---|
41 | $exp = explode('/', $inString); |
---|
42 | if(sizeof($exp) < 7) |
---|
43 | return null; |
---|
44 | else |
---|
45 | return array("type" => $exp[5], "uid" => $exp[6]); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * function createArguments() |
---|
50 | * @param type $arguments |
---|
51 | * Creates the arguments to be used in the query based on the |
---|
52 | * arguments specified in the incoming array. |
---|
53 | */ |
---|
54 | public static function createArguments($arguments) |
---|
55 | { |
---|
56 | $argumentString = ""; |
---|
57 | foreach(array_keys($arguments) as $key) |
---|
58 | { |
---|
59 | $addition = ""; |
---|
60 | switch($key) |
---|
61 | { |
---|
62 | case "uid" : $addition = "predicates:uid '" . $arguments[$key] . "'\n"; break; |
---|
63 | case "to_question" : $addition = "predicates:to_question <" . QUESTION . '/' . $arguments[$key] . ">\n"; break; |
---|
64 | case "values": foreach($arguments[$key] as $value) { $addition = $addition . "predicates:answered '" . $value . "'\n"; } break; |
---|
65 | case "survey" : $addition = "predicates:for_survey <" . SURVEY . '/' . $arguments[$key] . ">\n"; break; |
---|
66 | case "respondent" : $addition = "predicates:by_respondent <" . RESPONDENT . '/' . $arguments[$key] . ">\n"; break; |
---|
67 | case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_answer <" . ANSWER . '/' . $answer . ">\n"; } break; |
---|
68 | case "title" : $addition = "predicates:title '" . $arguments[$key] . "'\n"; break; |
---|
69 | case "description" : $addition = "predicates:description '" . $arguments[$key] . "'\n"; break; |
---|
70 | case "style" : $addition = "predicates:style '" . $arguments[$key] . "'\n"; break; |
---|
71 | case "code" : $addition = "predicates:question_code '" . $arguments[$key] . "'\n";break; |
---|
72 | case "type" : $addition = "predicates:question_type '" . $arguments[$key] . "'\n"; break; |
---|
73 | case "category" : $addition = "predicates:question_category '" . $arguments[$key] . "'\n"; |
---|
74 | case "definedanswers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:has_answer '" . $answer . "'\n"; } break; |
---|
75 | case "email" : $addition = "predicates:email '" . $arguments[$key] . "'\n"; break; |
---|
76 | case "password" : $addition = "predicates:password '" . $arguments[$key] . "'\n"; break; |
---|
77 | case "creator" : $addition = "predicates:creator <" . USER . '/' . $arguments[$key] . ">\n"; break; |
---|
78 | case "creationdate" : $addition = "predicates:creationdate '" . $arguments[$key] . "'\n"; break; |
---|
79 | case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application <" . APPLICATION . '/' . $application . ">\n"; } break; |
---|
80 | case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey <" . SURVEY . '/' . $survey . ">\n"; } break; |
---|
81 | case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset <" . ANSWERSET . '/' . $answerset . ">\n"; } break; |
---|
82 | case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question <" . QUESTION . '/' . $question . ">\n"; } break; |
---|
83 | case "location" : $addition = "predicates:location '" . $arguments[$key] . "'\n"; break; |
---|
84 | case "facilitator" : $addition = "predicates:facilitator <" . USER . '/' . $arguments[$key] . ">\n"; break; |
---|
85 | case "starttime" : $addition = "predicates:starttime '" . $arguments[$key] . "'\n"; break; |
---|
86 | case "endtime" : $addition = "predicates:endtime '" . $arguments[$key] . "'\n"; break; |
---|
87 | case "session" : $addition = "predicates:of_session <" . SURVEY . '/' . $arguments[$key] . ">\n"; break; |
---|
88 | case "resultset" : $addition = "predicates:has_resultset '" . $arguments[$key] . "'\n"; break; |
---|
89 | case "of_application" : $addition = "predicates:of_application <" . APPLICATION . '/' . $arguments[$key] . ">\n"; break; |
---|
90 | case "open" : $addition = "predicates:open '" . $arguments[$key] . "\n"; break; |
---|
91 | case "applicationinstances" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_applicationinstance <" . APPLICATIONINSTANCE . '/' . $instance . ">\n"; } break; |
---|
92 | case "has_surveyinstance" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:has_surveyinstance <" . SURVEYINSTANCE . '/' . $instance . ">\n"; } break; |
---|
93 | case "preset_answers" : foreach($arguments[$key] as $instance) { $addition = $addition . "predicates:preset_answer <" . ANSWER . '/' . $instance . ">\n"; } break; |
---|
94 | } |
---|
95 | $argumentString = $argumentString . $addition; |
---|
96 | } |
---|
97 | return $argumentString; |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | interface ResearchToolObjectInterface { |
---|
103 | function getUid(); |
---|
104 | static function get($arguments); |
---|
105 | static function create($obj); |
---|
106 | function evaluate(); |
---|
107 | function save(); |
---|
108 | } |
---|
109 | |
---|
110 | ?> |
---|