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

Last change on this file since 112 was 112, checked in by fpvanagthoven, 14 years ago

Code to get questions and put them in objects

File size: 3.9 KB
RevLine 
[105]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    {
[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    {
[112]56        $questionInfo = array();
[105]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        }
[112]79       
80        return $questionInfo;
[105]81    }
82   
83    public function getExistingQuestions()
84    {
85        $questions = array();
86
87        $resultQuestions = $this->questionRDFReader->readQuestionCodes();
[109]88        $this->questionRDFReader->reloadQuestions();
[106]89        if ($resultQuestions != null)
[105]90        {
[106]91            foreach ($resultQuestions as $questionCodeObject)
92            {
[109]93                $questionCode = $questionCodeObject['?questionCode']->label;
[106]94                $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode);
95                $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label;
96            }
[105]97        }
98
99        return $questions;
100    }
101   
102    public function checkQuestionCodeExists($qCode)
103    {
104        $result = false;
105
106        $questionCodes = $this->questionRDFReader->readQuestionCodes();
107       
108        if ($questionCodes != null)
109        {
110            foreach($questionCodes as $questionCode)
111            {
112                $code = $questionCode['?questionCode']->label;
113                if(!strcmp($code ,$qCode))
114                {
115                    $result = true;
116                    break;
117                }
118            }
119        }
120
121        return $result;
122    }
123}
124
125?>
Note: See TracBrowser for help on using the repository browser.