source: Dev/branches/jos-branch/server/classes/models/ResearchToolObject.php @ 287

Last change on this file since 287 was 287, checked in by jkraaijeveld, 13 years ago

[Server] ApplicationInstance? now properly works with Resource links to Application. SPARQL query has been edited to make this work. Still has to be done for all other models.

File size: 4.6 KB
Line 
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
8require_once 'rdfConstants.php';
9// Include RAP Library to write RDF files
10include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
11
12
13abstract 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 "question" : $addition = "predicates:question_code '" . $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 '" . $arguments[$key] . "'\n"; break;
66                                case "respondent" : $addition = "predicates:by_respondent '" . $arguments[$key] . "'\n"; break;
67                                case "answers" : foreach($arguments[$key] as $answer) { $addition = $addition . "predicates:given_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 '" . $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 . "'\n"; } break;
80                                case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey '" . $survey . "'\n"; } break;
81                                case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset '" . $answerset . "'\n"; } break;
82                                case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question '" . $question . "'\n"; } break;
83                                case "location" : $addition = "predicates:location '" . $arguments[$key] . "'\n"; break;
84                                case "facilitator" : $addition = "predicates:facilitator '" . $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 '" . $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                        }
92                        $argumentString = $argumentString . $addition;
93                }
94                return $argumentString;
95        }
96
97}
98
99interface ResearchToolObjectInterface {
100    function getUid();
101    static function get($arguments);
102    static function create($obj);
103    function evaluate();
104    function save();
105}
106
107?>
Note: See TracBrowser for help on using the repository browser.