[105] | 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 | { |
---|
[107] | 28 | $qCode = $question['questionCode']; |
---|
| 29 | $qTitle = $question['questionTitle']; |
---|
| 30 | $qDescription = $question['questionDescription']; |
---|
| 31 | $qType = $question['questionType']; |
---|
[105] | 32 | |
---|
| 33 | $qAnswers = array(); |
---|
| 34 | $aNumber = 1; |
---|
| 35 | while (isset($question['ans'.$aNumber])) |
---|
| 36 | { |
---|
| 37 | $qAnswers[] = $question['ans'.$aNumber]; |
---|
| 38 | |
---|
| 39 | $aNumber++; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | if($this->checkQuestionCodeExists($qCode)) |
---|
| 43 | { |
---|
| 44 | return 'Question code (' . $qCode . ') already in use. Please try a new code.'; |
---|
| 45 | } |
---|
| 46 | else { |
---|
| 47 | $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qCode,"null",$qAnswers); |
---|
[107] | 48 | $this->questionRDFWriter->saveQuestions(); |
---|
[105] | 49 | return 'Question saved'; |
---|
[107] | 50 | } |
---|
[105] | 51 | } |
---|
| 52 | |
---|
| 53 | public function getQuestionInfo($qCode) |
---|
| 54 | { |
---|
| 55 | $questionInfo - array(); |
---|
| 56 | |
---|
| 57 | $questionTitleObject = $this->questionRDFReader->readQuestionTitle($qCode); |
---|
| 58 | $questionInfo['questionTitle'] = $questionTitleObject[0]['?questionTitle']->label; |
---|
| 59 | |
---|
| 60 | $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($qCode); |
---|
| 61 | $questionInfo['questionDescription'] = $questionDescriptionObject[0]['?questionDescription']->label; |
---|
| 62 | |
---|
| 63 | $questionTypeObject = $this->questionRDFReader->readQuestionType($qCode); |
---|
| 64 | $questionInfo['questionType'] = $questionTypeObject[0]['?questionType']->label; |
---|
| 65 | |
---|
| 66 | $resultAnswers = $this->questionRDFReader->readQuestionAnswers($qCode); |
---|
| 67 | |
---|
| 68 | if ($resultAnswers != null) |
---|
| 69 | { |
---|
| 70 | for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++) |
---|
| 71 | { |
---|
| 72 | $questionInfo['ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | public function getExistingQuestions() |
---|
| 78 | { |
---|
| 79 | $questions = array(); |
---|
| 80 | |
---|
| 81 | $resultQuestions = $this->questionRDFReader->readQuestionCodes(); |
---|
[106] | 82 | if ($resultQuestions != null) |
---|
[105] | 83 | { |
---|
[106] | 84 | foreach ($resultQuestions as $questionCodeObject) |
---|
| 85 | { |
---|
| 86 | $questionCode = $questionCodeObject[0]['?questionCode']->label; |
---|
| 87 | $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode); |
---|
| 88 | $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label; |
---|
| 89 | } |
---|
[105] | 90 | } |
---|
| 91 | |
---|
| 92 | return $questions; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | public function checkQuestionCodeExists($qCode) |
---|
| 96 | { |
---|
| 97 | $result = false; |
---|
| 98 | |
---|
| 99 | $questionCodes = $this->questionRDFReader->readQuestionCodes(); |
---|
| 100 | |
---|
| 101 | if ($questionCodes != null) |
---|
| 102 | { |
---|
| 103 | foreach($questionCodes as $questionCode) |
---|
| 104 | { |
---|
| 105 | $code = $questionCode['?questionCode']->label; |
---|
| 106 | if(!strcmp($code ,$qCode)) |
---|
| 107 | { |
---|
| 108 | $result = true; |
---|
| 109 | break; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | return $result; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | ?> |
---|