Index: Dev/trunk/classes/SurveyAnswerDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 82)
+++ Dev/trunk/classes/SurveyAnswerDatabaseInterface.php	(revision 83)
@@ -8,171 +8,30 @@
 
 
-class SurveyDatabaseInterface
-{		
-    protected $surveyRDFWriter;
-    protected $surveyRDFReader;
-    protected $questionRDFWriter;
-    protected $questionRDFReader;
-
-    public function __construct($surveyID)
+class SurveyAnswerDatabaseInterface extends SurveyCreationDatabaseInterface
+{
+    protected $surveyAnswerRDFReader;
+    protected $surveyAnswerRDFWriter;
+    
+    public function __construct($surveyID,$sessionID,$respondentID)
     {
-        if($surveyID == null)
-            $surveyUID = md5( uniqid(rand(), true) );
+        parent::__construct($surveyID);
+        if($respondentID == null)
+            $respondentID = md5( uniqid(rand(), true) );
         else
-            $surveyUID = $surveyID;
-
-        $this->surveyRDFWriter = new SurveyRDFWriter($surveyUID);
-        $this->surveyRDFReader = new SurveyRDFReader($surveyUID);
-        $this->questionRDFWriter = new QuestionRDFWriter();
-        $this->questionRDFReader = new QuestionRDFReader();
-    }
-
-    public function setSurveyInfo($survey,$user)
-    {
-        $sTitle = $survey['surveyTitle'];
-        $sDescription = $survey['surveyDescription'];
-
-        $this->surveyRDFWriter->createSurvey($sTitle,$sDescription);
-
-        $sUserID = $user['username'];
-
-        $this->surveyRDFWriter->setUserData($sUserID);
-
-        $qNumber = 1;
-        while (isset($survey['questionTitle'.$qNumber]))
-        {
-            $qTitle = $survey['questionTitle'.$qNumber];
-            $qDescription = $survey['questionDescription'.$qNumber];
-            $qType = $survey['questionType'.$qNumber];
-            if (isset($survey['questionID'.$qNumber]))
-                $qID = $survey['questionID'.$qNumber];
-            else
-                $qID = md5( uniqid(rand(), true) );
-
-            $qAnswers = array();
-            $aNumber = 1;
-            while (isset($survey['q'.$qNumber.'ans'.$aNumber]))
-            {
-                $aArray = array();
-                $aArray['Title'] = 'q'.$qNumber.'ans'.$aNumber;
-                $aArray['Description'] = $survey['q'.$qNumber.'ans'.$aNumber];
-                $qAnswers[] = $aArray;
-
-                $aNumber++;
-            }
-
-            if(!$this->checkQuestionIDExists($qID))
-            {
-                $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers);
-            }            
-            $this->surveyRDFWriter->addQuestion($qID);
-
-            $qNumber++;
-        }
-
-        $this->surveyRDFWriter->saveSurvey();
-        $this->questionRDFWriter->saveQuestions();
-    }
-
-    public function getSurveyInfo()
-    {
-        $surveyInfo = array();
-
-        $this->questionRDFReader->loadQuestions();
+            $respondentID = $respondentID;
         
-        $resultSurvey = $this->surveyRDFReader->getSurveyInfo();
-        
-        $surveyInfo['surveyID'] = $resultSurvey['info'][0]['?uid']->label;
-        $surveyInfo['surveyTitle'] = $resultSurvey['info'][0]['?title']->label;
-        $surveyInfo['surveyDescription'] = $resultSurvey['info'][0]['?description']->label;
-        $surveyInfo['surveyCreator'] = $resultSurvey['info'][0]['?creator']->label;
-        $surveyQuestionIDs = $resultSurvey['questionIDs'];
-        
-        if($surveyQuestionIDs != false)
-        {
-            $qNumber = 1;
-            foreach($surveyQuestionIDs as $qID)
-            {
-                $questionID = $qID['?questionID']->label;
-                $surveyInfo['questionID'.$qNumber] = $questionID;
-
-                $questionTitleObject = $this->questionRDFReader->readQuestionTitle($questionID);
-                $surveyInfo['questionTitle'.$qNumber] = $questionTitleObject[0]['?questionTitle']->label;
-
-                $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($questionID);
-                $surveyInfo['questionDescription'.$qNumber] = $questionDescriptionObject[0]['?questionDescription']->label;
-
-                $questionTypeObject = $this->questionRDFReader->readQuestionType($questionID);
-                $surveyInfo['questionType'.$qNumber] = $questionTypeObject[0]['?questionType']->label;
-
-                $resultAnswers = $this->questionRDFReader->readQuestionAnswers($questionID);
-
-                if ($resultAnswers != null)
-                {
-                    for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++)
-                    {
-                        $surveyInfo['q'.$qNumber.'ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label;
-                    }
-                }
-                $resultAnswers = null;
-                $qNumber++;
-            }
-        }
-        
-        return $surveyInfo;
-    }
-
-    public function getExistingSurveys()
-    {
-        $surveyIDs = array();
-        $surveys = array();
-
-        if($handle = opendir('data/surveys/'))
-        {
-            while (false !== ($file = readdir($handle))) {
-                if(strstr($file, 'survey_') && strstr($file, '.rdf'))
-                    $surveyIDs[] = substr($file,7,strlen($file)-11);
-            }
-        }
-        
-        foreach($surveyIDs as $surveyID)
-        {
-            $surveyTitle = $this->surveyRDFReader->getSurveyTitleByID($surveyID);
-            $surveys[$surveyID] = $surveyTitle[0]['?title']->label;
-        }
-
-        return $surveys;
+        $this->surveyAnswerRDFReader = new SurveyAnswerRDFReader($surveyID,$sessionID,$respondentID);
+        $this->surveyAnswerRDFWriter = new SurveyAnswerRDFWriter($surveyID,$sessionID,$respondentID);
     }
     
-    public function getSurveyTitleByID($surveyID)
+    public function setRespondentInfo($respondentInfo)
     {
-        $surveyTitleLiteral = $this->surveyRDFReader->getSurveyTitleByID($surveyID);
-        $surveyTitle = $surveyTitle[0]['?title']->label;
+        $name = $respondentInfo['username'];
+        $this->surveyAnswerRDFWriter->setRespondentData($name);
+    }
+    
+    public function setSurveyAnswers($answer)
+    {
         
-        return $surveyTitle;
-    }
-
-    
-    
-    public function checkQuestionIDExists($qID)
-    {
-        $result = false;
-
-        $questionIDs = $this->questionRDFReader->readQuestionIDs();
-        
-        if ($questionIDs != null)
-        {
-            foreach($questionIDs as $questionID)
-            {
-                $id = $questionID['?questionID']->label;
-                if(!strcmp($id ,$qID))
-                {
-                    $result = true;
-                    break;
-                }
-            }
-        }
-
-        return $result;
     }
 }
