[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']; |
---|
[110] | 32 | $qCategory = $question['questionCategory']; |
---|
[105] | 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 { |
---|
[110] | 48 | $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qCode,$qCategory,$qAnswers); |
---|
[107] | 49 | $this->questionRDFWriter->saveQuestions(); |
---|
[105] | 50 | return 'Question saved'; |
---|
[107] | 51 | } |
---|
[105] | 52 | } |
---|
| 53 | |
---|
| 54 | public function getQuestionInfo($qCode) |
---|
| 55 | { |
---|
| 56 | $questionInfo - array(); |
---|
| 57 | |
---|
| 58 | $questionTitleObject = $this->questionRDFReader->readQuestionTitle($qCode); |
---|
| 59 | $questionInfo['questionTitle'] = $questionTitleObject[0]['?questionTitle']->label; |
---|
| 60 | |
---|
| 61 | $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($qCode); |
---|
| 62 | $questionInfo['questionDescription'] = $questionDescriptionObject[0]['?questionDescription']->label; |
---|
| 63 | |
---|
| 64 | $questionTypeObject = $this->questionRDFReader->readQuestionType($qCode); |
---|
| 65 | $questionInfo['questionType'] = $questionTypeObject[0]['?questionType']->label; |
---|
[110] | 66 | |
---|
| 67 | $questionCategoryObject = $this->questionRDFReader->readQuestionCategory($qCode); |
---|
| 68 | $questionInfo['questionCategory'] = $questionTypeObject[0]['?questionCategory']->label; |
---|
[105] | 69 | |
---|
| 70 | $resultAnswers = $this->questionRDFReader->readQuestionAnswers($qCode); |
---|
| 71 | |
---|
| 72 | if ($resultAnswers != null) |
---|
| 73 | { |
---|
| 74 | for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++) |
---|
| 75 | { |
---|
| 76 | $questionInfo['ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | public function getExistingQuestions() |
---|
| 82 | { |
---|
| 83 | $questions = array(); |
---|
| 84 | |
---|
| 85 | $resultQuestions = $this->questionRDFReader->readQuestionCodes(); |
---|
[109] | 86 | $this->questionRDFReader->reloadQuestions(); |
---|
[106] | 87 | if ($resultQuestions != null) |
---|
[105] | 88 | { |
---|
[106] | 89 | foreach ($resultQuestions as $questionCodeObject) |
---|
| 90 | { |
---|
[109] | 91 | $questionCode = $questionCodeObject['?questionCode']->label; |
---|
[106] | 92 | $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode); |
---|
| 93 | $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label; |
---|
| 94 | } |
---|
[105] | 95 | } |
---|
| 96 | |
---|
| 97 | return $questions; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public function checkQuestionCodeExists($qCode) |
---|
| 101 | { |
---|
| 102 | $result = false; |
---|
| 103 | |
---|
| 104 | $questionCodes = $this->questionRDFReader->readQuestionCodes(); |
---|
| 105 | |
---|
| 106 | if ($questionCodes != null) |
---|
| 107 | { |
---|
| 108 | foreach($questionCodes as $questionCode) |
---|
| 109 | { |
---|
| 110 | $code = $questionCode['?questionCode']->label; |
---|
| 111 | if(!strcmp($code ,$qCode)) |
---|
| 112 | { |
---|
| 113 | $result = true; |
---|
| 114 | break; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return $result; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | ?> |
---|