1 | <?php |
---|
2 | |
---|
3 | |
---|
4 | // Survey database interface class as intermediate for storing data from the site to the RDF database |
---|
5 | require_once 'rdfConstants.php'; |
---|
6 | |
---|
7 | // Include RAP Library to write RDF files |
---|
8 | include(RDFAPI_INCLUDE_DIR . "RDFAPI.php"); |
---|
9 | |
---|
10 | /** |
---|
11 | * Description of QuestionCreationDatabaseInterface |
---|
12 | * |
---|
13 | * @author basvannuland |
---|
14 | */ |
---|
15 | class QuestionCreationDatabaseInterface { |
---|
16 | |
---|
17 | protected $questionRDFWriter; |
---|
18 | protected $questionRDFReader; |
---|
19 | |
---|
20 | public function __construct() |
---|
21 | { |
---|
22 | $this->questionRDFWriter = new QuestionRDFWriter(); |
---|
23 | $this->questionRDFReader = new QuestionRDFReader(); |
---|
24 | } |
---|
25 | |
---|
26 | public function setQuestionInfo($question) |
---|
27 | { |
---|
28 | $qCode = $question['questionCode']; |
---|
29 | $qTitle = $question['questionTitle']; |
---|
30 | $qDescription = $question['questionDescription']; |
---|
31 | $qType = $question['questionType']; |
---|
32 | $qCategory = $question['questionCategory']; |
---|
33 | |
---|
34 | $qAnswers = array(); |
---|
35 | $aNumber = 1; |
---|
36 | while (isset($question['ans'.$aNumber])) |
---|
37 | { |
---|
38 | $qAnswers[] = $question['ans'.$aNumber]; |
---|
39 | |
---|
40 | $aNumber++; |
---|
41 | } |
---|
42 | |
---|
43 | if($this->checkQuestionCodeExists($qCode)) |
---|
44 | { |
---|
45 | return 'Question code (' . $qCode . ') already in use. Please try a new code.'; |
---|
46 | } |
---|
47 | else { |
---|
48 | $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qCode,$qCategory,$qAnswers); |
---|
49 | $this->questionRDFWriter->saveQuestions(); |
---|
50 | return 'Question saved'; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | public function getQuestionInfo($qCode) |
---|
55 | { |
---|
56 | $questionInfo = array(); |
---|
57 | |
---|
58 | $question = $this->questionRDFReader->readQuestionByCode($qCode); |
---|
59 | |
---|
60 | $questionInfo['questionTitle'] = $question['title'][0]['?questionTitle']->label; |
---|
61 | $questionInfo['questionDescription'] = $question['description'][0]['?questionDescription']->label; |
---|
62 | $questionInfo['questionType'] = $question['type'][0]['?questionType']->label; |
---|
63 | $questionInfo['questionCategory'] = $question['category'][0]['?questionCategory']->label; |
---|
64 | if ($question['answers'] != null) |
---|
65 | { |
---|
66 | for($aNumber = 1;$aNumber<=sizeof($question['answers']);$aNumber++) |
---|
67 | { |
---|
68 | $questionInfo['ans'.$aNumber] = $question['answers'][$aNumber-1]['?answerDescription']->label; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return $questionInfo; |
---|
73 | } |
---|
74 | |
---|
75 | public function getExistingQuestions() |
---|
76 | { |
---|
77 | $questions = array(); |
---|
78 | |
---|
79 | $resultQuestions = $this->questionRDFReader->readQuestionCodes(); |
---|
80 | $this->questionRDFReader->reloadQuestions(); |
---|
81 | if ($resultQuestions != null) |
---|
82 | { |
---|
83 | foreach ($resultQuestions as $questionCodeObject) |
---|
84 | { |
---|
85 | $questionCode = $questionCodeObject['?questionCode']->label; |
---|
86 | $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode); |
---|
87 | $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | return $questions; |
---|
92 | } |
---|
93 | |
---|
94 | public function checkQuestionCodeExists($qCode) |
---|
95 | { |
---|
96 | $result = false; |
---|
97 | |
---|
98 | $questionCodes = $this->questionRDFReader->readQuestionCodes(); |
---|
99 | |
---|
100 | if ($questionCodes != null) |
---|
101 | { |
---|
102 | foreach($questionCodes as $questionCode) |
---|
103 | { |
---|
104 | $code = $questionCode['?questionCode']->label; |
---|
105 | if(!strcmp($code ,$qCode)) |
---|
106 | { |
---|
107 | $result = true; |
---|
108 | break; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | return $result; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | ?> |
---|