source: Dev/trunk/classes/QuestionCreationDatabaseInterface.php @ 110

Last change on this file since 110 was 110, checked in by basvannuland, 14 years ago

category added

File size: 3.8 KB
Line 
1<?php
2
3
4// Survey database interface class as intermediate for storing data from the site to the RDF database
5require_once 'rdfConstants.php';
6
7// Include RAP Library to write RDF files
8include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
9
10/**
11 * Description of QuestionCreationDatabaseInterface
12 *
13 * @author basvannuland
14 */
15class 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        $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;
66       
67        $questionCategoryObject = $this->questionRDFReader->readQuestionCategory($qCode);
68        $questionInfo['questionCategory'] = $questionTypeObject[0]['?questionCategory']->label;
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();
86        $this->questionRDFReader->reloadQuestions();
87        if ($resultQuestions != null)
88        {
89            foreach ($resultQuestions as $questionCodeObject)
90            {
91                $questionCode = $questionCodeObject['?questionCode']->label;
92                $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode);
93                $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label;
94            }
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?>
Note: See TracBrowser for help on using the repository browser.