Index: Dev/branches/jos-branch/classes/DatabaseInterface.php
===================================================================
--- Dev/branches/jos-branch/classes/DatabaseInterface.php	(revision 130)
+++ Dev/branches/jos-branch/classes/DatabaseInterface.php	(revision 138)
@@ -20,4 +20,5 @@
     private $questionConnector;
     private $userConnector;
+    private $surveyConnector;
     
     /**
@@ -29,4 +30,5 @@
         $this->questionConnector = new QuestionConnector();
         $this->userConnector = new UserConnector();
+        $this->surveyConnector = new SurveyConnector();
     }
     
@@ -50,4 +52,6 @@
                 return $this->userConnector->get($arguments);
                 break;
+            case "survey":
+                return $this->surveyConnector->get($arguments);
         }
     }
@@ -70,4 +74,6 @@
                 $this->userConnector->set($rToolObject);
                 break;
+            case "Survey":
+                $this->surveyConnector->set($rToolObject);
         }
     }
Index: Dev/branches/jos-branch/classes/QuestionConnector.php
===================================================================
--- Dev/branches/jos-branch/classes/QuestionConnector.php	(revision 138)
+++ Dev/branches/jos-branch/classes/QuestionConnector.php	(revision 138)
@@ -0,0 +1,190 @@
+<?php
+
+// Survey database interface class as intermediate for storing data from the site to the RDF database 
+require_once 'rdfConstants.php';
+// Include RAP Library to write RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+
+
+/**
+ * Description of QuestionConnector
+ *
+ * @author jkraaijeveld
+ */
+class QuestionConnector implements IConnector {
+    
+    protected $model;
+    protected $fileName = 'data/questions/questions.rdf';
+    
+    /**
+     * Constructor for QuestionConnector
+     */
+    public function __construct()
+    {
+        //Ensure the required folder for this connector exists
+        if (!is_dir('data/questions/'))
+            mkdir('data/questions/');	
+    }
+    
+    /**
+     * function load()
+     * Loads the file into the standard MemModel.
+     */
+    public function load() {
+        //Get the Memory Model from the ModelFactory
+        $this->model = ModelFactory::getDefaultModel();
+        
+        //Ensure the required file exists before loading
+        if(file_exists($this->fileName))
+            $this->model->load($this->fileName);
+    }
+    
+    /**
+     * function save()
+     * Saves the MemModel into the given file.
+     */
+    public function save() {
+        $this->model->saveAs($this->fileName,'rdf'); 
+    }
+    
+    /**
+     * Get the questions corresponding to the arguments.
+     * @param type $arguments 
+     * @return type Array
+     */
+    public function get($arguments)
+    {
+        $this->load();
+        
+        $keys = array_keys($arguments);
+        //Set default values for arguments
+        $uid = "?uid"; $title = "?title"; $type = "?type"; $description = "?description"; $category = "?category";
+        //Set the arguments if they are supplied
+        if(in_array("uid", $keys))
+            $uid = '\''.$arguments["uid"].'\'';
+        if(in_array("title", $keys))
+            $title = '\''.$arguments["title"].'\'';
+        if(in_array("type", $keys))
+            $type = '\''.$arguments["type"].'\'';
+        if(in_array("description", $keys))
+            $description = "\"".$arguments["description"]."\"";
+        if(in_array("category", $keys))
+            $style = "\"".$arguments["category"]."\"";
+           
+        $querystring = '
+            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+            SELECT DISTINCT ?uid, ?title, ?type, ?description, ?category
+            WHERE 	
+            {
+                _question	predicates:resource_type	resources:question ;                
+                predicates:question_code ?uid ;
+                predicates:title ?title ;
+                predicates:question_type ?type ;
+                predicates:description ?description ;
+                predicates:question_category ?category ;
+
+                predicates:question_code ' . $uid . '
+                predicates:title ' . $title . '
+                predicates:question_type ' . $type . '
+                predicates:description ' . $description . '
+                predicates:question_category ' . $category . ' 
+            }';
+        //Create the querystring 
+        $results = $this->model->sparqlQuery($querystring);
+
+        
+        $questions = array();
+        if(!empty($results))
+        {
+            foreach($results as $result)
+            {
+                $answers = $this->getAnswers($result['?uid']->label);
+                $questions[] = new Question($result['?uid']->label, $result['?title']->label, $result['?type']->label, $result['?description']->label, $result['?category']->label, $answers);
+            }
+        }
+        return $questions;
+    }
+    
+    /**
+     * Gets the answers belonging to the given uid.
+     * @param type $uid
+     * @return type Array 
+     */
+    private function getAnswers($uid)
+    {
+        $querystring = '
+            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+            SELECT DISTINCT ?has_answer
+            WHERE
+            {
+                 _question	predicates:resource_type	resources:question ;
+                predicates:has_answer ?has_answer ; 
+                predicates:question_code \'' . $uid . '\'
+            }';
+
+        $answers = $this->model->sparqlQuery($querystring);
+        $returnArray = array();
+        if(!empty($answers))
+        {
+            foreach($answers as $answer)
+            {
+                $returnArray[] = $answer['?has_answer']->label;
+            }
+        }
+        return $returnArray;
+    }
+
+    
+    /**
+     * Save the given ResearchTool object
+     * @param type $rToolObject 
+     */
+    public function set($rToolObject)
+    {
+        $this->load();
+        
+        $resourceQuestion = new Resource(QUESTION.'/'.$rToolObject->uid);        
+        //Remove the old value stored with the given id
+        $this->model->subtract($this->model->find($resourceQuestion, null, null));
+        
+        //Save all the new values
+        $resourceQuestionType = new Resource(QUESTION);
+        $predicateRType = new Resource(RTYPE);
+        $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType));
+        
+        $questionQCode = new Literal($rToolObject->uid);
+        $predicateQCode = new Resource(QCODE);
+        $this->model->add(new Statement($resourceQuestion,$predicateQCode,$questionQCode));
+        
+        $questionTitle = new Literal($rToolObject->title);
+        $predicateTitle = new Resource(TITLE);		
+        $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle));	
+
+        $questionDescription = new Literal($rToolObject->description);
+        $predicateDescription = new Resource(DESCRIPTION);
+        $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription));		
+
+        $resourceQuestionType = new Literal($rToolObject->type);
+        $predicateQType = new Resource(QTYPE);
+        $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
+        
+        $questionQCategory = new Literal($rToolObject->category);
+        $predicateQCategory = new Resource(QCATEGORY);
+        $this->model->add(new Statement($resourceQuestion,$predicateQCategory,$questionQCategory));
+
+        if(isset($rToolObject->answers))
+        {
+            foreach($rToolObject->answers as $answer)
+            {		
+                $answerValue = new Literal($answer);
+                $predicateAnswer = new Resource(HAS_ANSWER);	
+                $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$answerValue));
+            }
+        }
+        $this->save();
+    }
+}
+
+?>
Index: Dev/branches/jos-branch/classes/Session.php
===================================================================
--- Dev/branches/jos-branch/classes/Session.php	(revision 130)
+++ 	(revision )
@@ -1,58 +1,0 @@
-<?php
-
-/**
- * Description of Session
- *
- * @author fpvanagthoven
- */
-class Session {
-
-    public $title;
-    public $description;
-    public $pipeline;
-    public $count;
-
-    public function __construct($title, $description) {
-        $this->title = $title;
-        $this->description = $description;
-        $this->count = 0;
-        
-        $this->pipeline = array();
-    }
-    
-    public static function getSession($info)
-    {
-        if (!empty($info))
-        {
-            $title = $info['sessionTitle'];
-            $description = $info['sessionDescription'];
-            $session = new Session($title, $description);
-            $session->count = $info['pipelineCount'];
-            
-            $pipelineCount = 1;
-            for ($i = 1; $i < $session->count + 1; $i++)
-            {
-                if (isset($info[$i . 's']))
-                {
-                    $session->pipeline[$i . 's'] = $info[$i . 's'];
-                }
-                else if (isset($info[$i . 'd']))
-                {
-                    $session->pipeline[$i . 'd'] = $info[$i . 'd'];
-                }
-                else if (isset($info[$i . 'a']))
-                {
-                    $session->pipeline[$i . 'a'] = $info[$i . 'a'];
-                }
-
-                $pipelineCount++;
-            }
-            
-            return $session;
-        }
-        else
-            return null;
-    }
-
-}
-?>
Index: Dev/branches/jos-branch/classes/Survey.php
===================================================================
--- Dev/branches/jos-branch/classes/Survey.php	(revision 138)
+++ Dev/branches/jos-branch/classes/Survey.php	(revision 138)
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * Description of Survey
+ *
+ * @author jkraaijeveld
+ */
+class Survey extends ResearchToolObject{
+    public $title;
+    public $description;
+    public $creator;
+    public $questions;
+    
+    public function __construct($uid = null, $title = null, $description = null, $questions = null) {
+        if(!isset($uid))
+        {
+            $uid = md5(uniqid(rand(), true));
+        }
+        $this->uid = $uid;
+        $this->title = $title;
+        $this->description = $description;
+        $this->questions = $questions;
+    }
+}
+
+?>
Index: Dev/branches/jos-branch/classes/SurveyConnector.php
===================================================================
--- Dev/branches/jos-branch/classes/SurveyConnector.php	(revision 138)
+++ Dev/branches/jos-branch/classes/SurveyConnector.php	(revision 138)
@@ -0,0 +1,180 @@
+<?php
+
+/**
+ * Description of SurveyConnector
+ *
+ * @author jkraaijeveld
+ */
+class SurveyConnector implements IConnector{
+    protected $model;
+    protected $fileName = 'data/surveys/surveys.rdf';
+    protected $db;
+
+    /**
+     * Constructor for ApplicationConnector.
+     */
+    public function __construct()
+    {
+        //Ensure the required folder for this connector exists
+        if (!is_dir('data/surveys/'))
+            mkdir('data/surveys/');	
+    }
+    
+    /**
+     * function load()
+     * Loads the file into the standard MemModel.
+     */
+    public function load() {
+        //Get the Memory Model from the ModelFactory
+        $this->model = ModelFactory::getDefaultModel();
+        
+        //Ensure the required file exists before loading
+        if(file_exists($this->fileName))
+            $this->model->load($this->fileName);
+    }
+    
+    /**
+     * function save()
+     * Saves the MemModel into the given file.
+     */
+    public function save() {
+        $this->model->saveAs($this->fileName,'rdf'); 
+    }
+    
+    /**
+     * function get($arguments)
+     * Gets the array of Survey objects belonging to arguments supplied.
+     * @param type $arguments : An array containing zero or more of the following keys:
+     *                          'uid', 'title', 'description', 'questions'
+     * Note: questions has to be an array of question IDs (codes) for this filter to work.
+     */
+    public function get($arguments)
+    {
+        $this->load();
+        
+        $keys = array_keys($arguments);
+        //Set default values for arguments
+        $uid = "?uid"; $title = "?title"; $description = "?description"; $questions = "";
+        if(in_array("uid", $keys))
+            $uid = '\''.$arguments["uid"].'\'';
+        if(in_array("title", $keys))
+            $title = '\''.$arguments["title"].'\'';
+        if(in_array("description", $keys))
+            $description = "\"".$arguments["description"]."\"";
+        if(in_array("questions", $keys))
+        {
+            //Append the questions string to filter for questions properly
+            foreach ($arguments["questions"] as $questionUid)
+            {
+                $questions = $questions . 'predicates:has_question \'' . $questionUid . '\' ';
+            }
+        }
+        
+        //Build the query string
+        $querystring = '
+            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+            SELECT DISTINCT ?uid, ?title, ?description
+            WHERE
+            {
+                _survey     predicates:resource_type    resources:survey ;
+                predicates:uid ?uid ;
+                predicates:title ?title ;
+                predicates:description ?description ;
+                predicates:uid ' . $uid . ' 
+                predicates:title ' . $title . '
+                predicates:description ' . $description . '
+                ' . $questions . '
+            }';
+        
+        //Query the model
+        $results = $this->model->sparqlQuery($querystring);
+        
+        //Create the corresponding Survey objects
+        $surveys = array();
+        if(!empty($results))
+        {
+            $this->db = new DatabaseInterface();
+            foreach($results as $result)
+            {
+                $questions = $this->getQuestions($result['?uid']->label);
+                $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $questions);
+            }
+        }
+        return $surveys;
+    }
+    
+    /**
+     * Gets the questions corresponding to the survey
+     * @param type $uid 
+     */
+    private function getQuestions($uid)
+    {
+        //Create the querystring. Note that the UID is the only argument in this case.
+        $querystring = '
+            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+            SELECT DISTINCT ?has_question
+            WHERE
+            {
+                 _survey	predicates:resource_type	resources:survey ;
+                predicates:has_question ?has_question ; 
+                predicates:uid \'' . $uid . '\'
+            }';
+
+        $results = $this->model->sparqlQuery($querystring);
+        $questions = array();
+        //For every question id, get the corresponding question
+        if(!empty($results))
+        {
+            foreach($results as $questionId)
+            {
+                $resultQ = $this->db->get("question", array("uid" => $questionId['?has_question']->label));
+                $questions[] = $resultQ[0];
+            }
+        }
+        return $questions;
+    }
+    
+    /**
+     * Saves the given Survey object.
+     * @param type $rToolObject 
+     */
+    public function set($rToolObject)
+    {
+        $this->load();
+        
+        $resourceSurvey = new Resource(SURVEY.'/'.$rToolObject->uid);
+        //Remove the old value stored with the given id
+        $this->model->subtract($this->model->find($resourceSurvey, null, null));
+        
+        $resourceSurveyType = new Resource(SURVEY);
+        $predicateRType = new Resource(RTYPE);
+        $this->model->add(new Statement($resourceSurvey,$predicateRType,$resourceSurveyType));
+
+        $predicateUniqueID = new Resource(UID);
+        $literalSurveyID = new Literal($rToolObject->uid);
+        $this->model->add(new Statement($resourceSurvey,$predicateUniqueID,$literalSurveyID));
+
+        $predicateTitle = new Resource(TITLE);		
+        $surveyTitle = new Literal($rToolObject->title);
+        $this->model->add(new Statement($resourceSurvey,$predicateTitle,$surveyTitle));		
+
+        $predicateDescription = new Resource(DESCRIPTION);
+        $surveyDescription = new Literal($rToolObject->description);
+        $this->model->add(new Statement($resourceSurvey,$predicateDescription,$surveyDescription));
+        
+        if(isset($rToolObject->questions))
+        {
+            foreach($rToolObject->questions as $question)
+            {
+                $questionUid = new Literal($question->uid);
+                $predicateQuid = new Resource(HAS_QUESTION);
+                $this->model->add(new Statement($resourceSurvey,$predicateQuid,$questionUid));
+            }
+        }
+        $this->save();
+    }
+}
+
+?>
Index: Dev/branches/jos-branch/classes/User.php
===================================================================
--- Dev/branches/jos-branch/classes/User.php	(revision 138)
+++ Dev/branches/jos-branch/classes/User.php	(revision 138)
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * Description of User
+ *
+ * @author jkraaijeveld
+ */
+
+class User extends ResearchToolObject {
+    
+    public $name;
+    public $password;
+    
+    /**
+     * Constructor of User
+     * If the user does not yet exist in the database, call with null as first parameter
+     */
+    public function __construct($uid = null, $name = null, $password = null) {
+        if(!isset($uid))
+        {
+             $uid = md5(uniqid(rand(), true));
+        }
+        $this->uid = $uid;
+        $this->name = $name;
+        $this->password = $password;
+    }
+}
+
+?>
Index: Dev/branches/jos-branch/classes/UserConnector.php
===================================================================
--- Dev/branches/jos-branch/classes/UserConnector.php	(revision 138)
+++ Dev/branches/jos-branch/classes/UserConnector.php	(revision 138)
@@ -0,0 +1,128 @@
+<?php
+// Survey database interface class as intermediate for storing data from the site to the RDF database 
+require_once 'rdfConstants.php';
+// Include RAP Library to write RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+
+/**
+ * Description of UserConnector
+ *
+ * @author jkraaijeveld
+ */
+class UserConnector implements IConnector{
+    
+    protected $model;
+    protected $fileName = 'data/users/users.rdf';
+    
+    /**
+     * Constructor for ApplicationConnector.
+     */
+    public function __construct()
+    {
+        //Ensure the required folder for this connector exists
+        if (!is_dir('data/users/'))
+            mkdir('data/users/');	
+    }
+    
+    /**
+     * function load()
+     * Loads the file into the standard MemModel.
+     */
+    public function load() {
+        //Get the Memory Model from the ModelFactory
+        $this->model = ModelFactory::getDefaultModel();
+        
+        //Ensure the required file exists before loading
+        if(file_exists($this->fileName))
+            $this->model->load($this->fileName);
+    }
+    
+    /**
+     * function save()
+     * Saves the MemModel into the given file.
+     */
+    public function save() {
+        $this->model->saveAs($this->fileName,'rdf'); 
+    }
+    
+    /**
+     * function get($arguments)
+     * Gets the array of User objects belonging to arguments supplied.
+     * @param type $arguments : An array containing zero or more of the following keys:
+     *                          'uid', 'name', 'password', 'style'
+     */
+    public function get($arguments) {
+        $this->load();
+        //Determine which arguments are supplied
+        $keys = array_keys($arguments);
+        //Set default values for arguments
+        $uid = "?uid"; $name = "?name"; $password = "?password";
+        //Set the arguments if they are supplied
+        if(in_array("uid", $keys))
+            $uid = "\"".$arguments["uid"]."\"";
+        if(in_array("name", $keys))
+            $name = '\''.$arguments["name"].'\'';
+        if(in_array("password", $keys))
+            $password = "\"".$arguments["password"]."\"";
+       
+        //Create the querystring 
+        $querystring = '
+            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+            SELECT ?uid, ?name, ?password
+            WHERE 	
+            {
+                    _user	predicates:resource_type	resources:user ;
+					predicates:uid ?uid ;
+					predicates:name ?name ;
+					predicates:password ?password ;
+                     			predicates:uid ' . $uid . ' 
+					predicates:name ' . $name . ' 
+					predicates:password ' . $password . ' 
+            }';
+        echo $querystring;
+        //Query the model
+        $results = $this->model->sparqlQuery($querystring);
+        $users = array();
+        if(!empty($results))
+        {
+            //Run over all results and create appropriate Application objets
+            foreach($results as $result)
+            { 
+                    $users[] = new User($result['?uid']->label, $result['?name']->label, $result['?password']->label);
+            }
+        }
+        return $users;
+    }
+    
+    /**
+     * Save the given User object in the file.
+     * @param type $rToolObject 
+     */
+    public function set($rToolObject)
+    {
+        $this->load();
+        $resourceUser = new Resource(USER . '/' . $rToolObject->uid);
+        //Remove the old value stored with the given id
+        $this->model->subtract($this->model->find($resourceUser, null, null));
+
+        $resourceUserType = new Resource(USER);
+        $predicateRType = new Resource(RTYPE);
+        $this->model->add(new Statement($resourceUser,$predicateRType,$resourceUserType));
+
+        $literalUserID = new Literal($rToolObject->uid);
+        $predicateUniqueID = new Resource(UID);
+        $this->model->add(new Statement($resourceUser,$predicateUniqueID,$literalUserID));
+        
+        $literalUserName = new Literal($rToolObject->name);
+        $predicateName = new Resource(NAME);
+        $this->model->add(new Statement($resourceUser,$predicateName,$literalUserName));			
+
+        $literalPassword = new Literal($rToolObject->password);
+        $predicatePassword = new Resource(PASSWORD);
+        $this->model->add(new Statement($resourceUser,$predicatePassword,$literalPassword));
+        $this->save();
+    }
+}
+
+?>
