Index: Dev/trunk/classes/Connector.php
===================================================================
--- Dev/trunk/classes/Connector.php	(revision 191)
+++ Dev/trunk/classes/Connector.php	(revision 195)
@@ -66,11 +66,15 @@
 				case "password" : $addition = "predicates:password '" . $arguments[$key] . "'\n"; break;
 				case "creator" : $addition = "predicates:creator '" . $arguments[$key] . "'\n"; break;
-				case "datetime" : $addition = "predicates:datetime '" . $arguments[$key] . "'\n"; break;
+				case "creationdate" : $addition = "predicates:creationdate '" . $arguments[$key] . "'\n"; break;
 				case "applications" : foreach($arguments[$key] as $application) { $addition = $addition . "predicates:has_application '" . $application . "'\n"; } break;
-
 				case "surveys" : foreach($arguments[$key] as $survey) { $addition = $addition . "predicates:has_survey '" . $survey . "'\n"; } break;
 				case "answersets" : foreach($arguments[$key] as $answerset) { $addition = $addition . "predicates:has_answerset '" . $answerset . "'\n"; } break;
 				case "questions" : foreach($arguments[$key] as $question) { $addition = $addition . "predicates:has_question '" . $question . "'\n"; } break;
-
+				case "location" : $addition = "predicates:location '" . $arguments[$key] . "\n"; break;
+				case "facilitator" : $addition = "predicates:facilitator '" . $arguments[$key] . "\n"; break;
+				case "starttime" : $addition = "predicates:starttime '" . $arguments[$key] . "\n"; break;
+				case "endtime" : $addition = "predicates:endtime '" . $arguments[$key] . "\n"; break;
+				case "session" : $addition = "predicates:of_session '" . $arguments[$key] . "\n"; break;
+				case "resultset" : $addition = "predciates:has_resultset '" . $arguments[$key] . "\n"; break;
 			}
 			$argumentString = $argumentString . $addition;
Index: Dev/trunk/classes/DatabaseInterface.php
===================================================================
--- Dev/trunk/classes/DatabaseInterface.php	(revision 191)
+++ Dev/trunk/classes/DatabaseInterface.php	(revision 195)
@@ -25,4 +25,5 @@
 	private $answerSetConnector;
 	private $sessionConnector;
+	private $sessionInstanceConnector;
     
     /**
@@ -39,4 +40,5 @@
 		$this->answerSetConnector = new AnswerSetConnector();
 		$this->sessionConnector = new SessionConnector();
+		$this->sessionInstanceConnector = new SessionInstanceConnector();
     }
     
@@ -75,4 +77,7 @@
 				return $this->sessionConnector->get($arguments);
 				break;
+			case "sessioninstance":
+				return $this->sessionInstanceConnector->get($arguments);
+				break;
         }
     }
@@ -87,26 +92,29 @@
         {
             case "Application":
-                $this->applicationConnector->set($rToolObject);
+                return $this->applicationConnector->set($rToolObject);
                 break;
             case "Question":
-                $this->questionConnector->set($rToolObject);
+                return $this->questionConnector->set($rToolObject);
                 break;
             case "User":
-                $this->userConnector->set($rToolObject);
+                return $this->userConnector->set($rToolObject);
                 break;
             case "Survey":
-				$this->surveyConnector->set($rToolObject);
+				return $this->surveyConnector->set($rToolObject);
 				break;
             case "Respondent":
-				$this->respondentConnector->set($rToolObject);
+				return $this->respondentConnector->set($rToolObject);
 				break;
             case "Answer":
-				$this->answerConnector->set($rToolObject);
+				return $this->answerConnector->set($rToolObject);
 				break;
 			case "AnswerSet":
-				$this->answerSetConnector->set($rToolObject);
+				return $this->answerSetConnector->set($rToolObject);
 				break;
 			case "Session":
-				$this->sessionConnector->set($rToolObject);
+				return $this->sessionConnector->set($rToolObject);
+				break;
+			case "SessionInstance":
+				return $this->sessionInstanceConnector->set($rToolObject);
 				break;
         }
@@ -122,6 +130,8 @@
         foreach ($rToolObjects as $rToolObject)
         {
-            $this->set($rToolObject);
-        }
+			if(!$this->set($rToolObject))
+				return false;
+		}
+		return true;
     }
 
Index: Dev/trunk/classes/Session.php
===================================================================
--- Dev/trunk/classes/Session.php	(revision 191)
+++ Dev/trunk/classes/Session.php	(revision 195)
@@ -10,7 +10,6 @@
 	public $title;
 	public $creator;
-	public $datetime;
+	public $creationdate;
 	public $pipeline;
-	public $answersets;
 
 	
@@ -23,5 +22,5 @@
 	 * @param type $pipeline
 	 */
-	public function __construct($uid = null, $title = null, $creator = null, $datetime = null, $pipeline = null, $answersets = null)
+	public function __construct($uid = null, $title = null, $creator = null, $datetime = null, $pipeline = null)
 	{
 		if(!isset($uid))
@@ -32,7 +31,6 @@
 		$this->title = $title;
 		$this->creator = $creator;
-		$this->datetime = $datetime;
+		$this->creationdate = $datetime;
 		$this->pipeline = $pipeline;
-		$this->answersets = $answersets;
 	}
 
@@ -67,16 +65,4 @@
 			$this->pipeline = $newPipeline;
 		}
-		if(!empty($this->answersets) && is_string($this->answersets[0]))
-		{
-			$newAnswerSets = array();
-			foreach($this->answersets as $element)
-			{
-				$result = $dbi->get("answerset", array("uid" => $element));
-				if(!isset($result[0]))
-					return false;
-				$newAnswerSets[] = $result[0];
-			}
-			$this->answersets = $newAnswerSets;
-		}
 		return true;
 	}
@@ -90,4 +76,5 @@
 	 * are written to the file whilst the others get lost.
 	 */
+	//DO NOT USE - BROKEN AS OF 23/12/2011
 	public function toSPSS($location)
 	{
Index: Dev/trunk/classes/SessionConnector.php
===================================================================
--- Dev/trunk/classes/SessionConnector.php	(revision 191)
+++ Dev/trunk/classes/SessionConnector.php	(revision 195)
@@ -28,5 +28,5 @@
 	 * function get()
 	 * @param type $arguments : An array containing one or more of the following elements:
-	 * 'uid', 'title', 'datetime', 'applications', 'surveys', 'answersets'
+	 * 'uid', 'title', 'creationdate', 'applications', 'surveys'
 	 */
 	public function get($arguments)
@@ -38,5 +38,5 @@
 			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
 			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-			SELECT DISTINCT ?uid, ?title, ?creator, ?datetime
+			SELECT DISTINCT ?uid, ?title, ?creator, ?creationdate
 			WHERE
 			{
@@ -45,5 +45,5 @@
 				predicates:title ?title ;
 				predicates:creator ?creator ;
-				predicates:datetime ?datetime ;
+				predicates:creationdate ?creationdate ;
 				' . $this->createArguments($arguments) . '
 			}';
@@ -58,9 +58,8 @@
 				//Create a session object out of every result, get all required fields as well.
 				$pipeline = $this->getPipeline($result['?uid']->label);
-				$answersets = $this->getAnswerSets($result['?uid']->label);
 				$creator = $result['?creator']->label;
 				$datetime = new DateTime();
-				$datetime->setTimestamp(intval($result['?datetime']->label));
-				$sessions[] = new Session($result['?uid']->label, $result['?title']->label, $creator, $datetime, $pipeline, $answersets);
+				$datetime->setTimestamp(intval($result['?creationdate']->label));
+				$sessions[] = new Session($result['?uid']->label, $result['?title']->label, $creator, $datetime, $pipeline);
 			}
 		}
Index: Dev/trunk/classes/SessionInstance.php
===================================================================
--- Dev/trunk/classes/SessionInstance.php	(revision 195)
+++ Dev/trunk/classes/SessionInstance.php	(revision 195)
@@ -0,0 +1,82 @@
+<?php
+/**
+ * Description of SessionInstance
+ *
+ * @author jkraaijeveld
+ */
+
+class SessionInstance extends ResearchToolObject
+{
+	public $title;
+	public $location;
+	public $facilitator;
+	public $starttime;
+	public $endtime;
+	public $notes;
+	public $session;
+	public $resultset;
+
+	/**
+	 * Constructor for a SessionInstance object
+	 * @param type $uid
+	 * @param type $title
+	 * @param type $location
+	 * @param type $facilitator
+	 * @param type $starttime
+	 * @param type $endtime
+	 * @param type $notes
+	 * @param type $session
+	 * @param type $resultset
+	 */
+	public function __construct($uid = null, $title = null, $location = null, $facilitator = null, $starttime = null, $endtime = null, $notes = null, $session = null, $resultset = null)
+	{
+		if(!isset($uid))
+		{
+			$uid = md5(uniqid(rand(), true));
+		}
+		$this->uid = $uid;
+		$this->title = $title;
+		$this->location = $location;
+		$this->facilitator = $facilitator;
+		$this->starttime = $starttime;
+		$this->endtime = $endtime;
+		$this->notes = $notes;
+		$this->session = $session;
+		$this->resultset = $resultset;
+	}
+
+	/*
+	 * function evaluate()
+	 * Evaluates all the references of this object.
+	 */
+	public function evaluate()
+	{
+		$dbi = new DatabaseInterface();
+		if(is_string($this->facilitator))
+		{
+			$result = $dbi->get("user", array("uid" => $this->facilitator));
+			if(!isset($result[0]))
+				return false;
+			$this->facilitator = $result[0];
+		}
+
+		if(is_string($this->session))
+		{
+			$result = $dbi->get("session", array("uid" => $this->session));
+			if(!isset($result[0]))
+				return false;
+			$this->session = $result[0]; 
+		}
+
+		if(is_string($this->resultset))
+		{
+			$result = $dbi->get("resultset", array("uid" => $this->resultset));
+			if(!isset($result[0]))
+				return true;
+			$newResultSets[] = $result[0];
+		}
+		return true;
+	}
+			
+
+}
Index: Dev/trunk/classes/SessionInstanceConnector.php
===================================================================
--- Dev/trunk/classes/SessionInstanceConnector.php	(revision 195)
+++ Dev/trunk/classes/SessionInstanceConnector.php	(revision 195)
@@ -0,0 +1,182 @@
+<?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 SessionInstanceConnector
+ *
+ * @author jkraaijeveld
+ */
+class SessionInstanceConnector extends Connector  
+{
+	protected $db;
+
+	/**
+	 * Constructor for the SessionInstanceConnector.
+	 */
+
+	public function __construct()
+	{
+		$this->fileName = 'data/sessions/sessioninstances.rdf';
+		//Ensure the required folder for this connector exists.
+		if(!is_dir('data/sessions'))
+			mkdir('data/sessions');
+	}
+
+	/**
+	 * function get()
+	 * @param type $arguments : An array containing one or more of the following elements:
+	 * 'uid', 'title', 'location', 'facilitator', 'starttime', 'endtime' 'notes', 'session', 'resultset'
+	 */
+	public function get($arguments)
+	{
+		$this->load();
+
+		//Build the query string
+		$querystring = '
+			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+			SELECT DISTINCT ?uid, ?title, ?location, ?facilitator, ?starttime, ?endtime, ?of_session, ?has_resultset 
+			WHERE
+			{
+				_sessioninstance predicates:resource_type resources:sessioninstance ;
+				predicates:uid ?uid ;
+				predicates:title ?title ;
+				predicates:location ?location ;
+				predicates:facilitator ?facilitator ;
+				predicates:starttime ?starttime ;
+				predicates:endtime ?endtime ;
+				predicates:of_session ?of_session ;
+				' . $this->createArguments($arguments) . '
+	}';
+		//Query the model
+		$results = $this->model->sparqlQuery($querystring);
+		$sessioninstances = array();
+		if(!empty($results))
+		{	
+			$this->db = new DatabaseInterface();
+			foreach($results as $result)
+			{
+				//Create a SessionInstance object out of every result. Get all the required fields as well.
+				$notes = $this->getNotes($result['?uid']->label);
+				$resultset = $this->getResultSet($result['?uid']->label);
+				$starttime = new DateTime();
+				$starttime->setTimestamp(intval($result['?starttime']->label));
+				$endtime = new DateTime();
+				$endtime->setTimestamp(intval($result['?endtime']->label));
+				$sessioninstances[] = new SessionInstance(  
+					$result['?uid']->label,
+					$result['?title']->label,
+					$result['?location']->label,
+					$result['?facilitator']->label,
+					$starttime,
+					$endtime,
+					$notes,
+					$result['?of_session'],
+					$resultset
+				);
+			}
+		}
+		return $sessioninstances;
+	}
+	
+	/**
+	 * function getNotes()
+	 * param type $uid : The SessionInstance uid for which the notes should be retrieved.
+	 */
+	public function getNotes($uid)
+	{
+		$result = $this->model->findRegex("[(".$uid.")]", "[(has_note)]", null);
+		$iterator = $result->getStatementIterator();
+		$notes = array();
+		while($iterator->hasNext())
+		{
+			$element = $iterator->next();
+			$notes[] = $element->getLabelObject();
+		}
+		return $notes;
+	}
+
+	/**
+	 * function getResultSet($uid)
+	 * param type $uid : The SessionInstance uid for which the ResultSet should be gotten.
+	 */
+	public function getResultSet($udi)
+	{
+		//TODO: Implement when ResultSet is in.
+		return null;
+	}
+
+	/**
+	 * function set()
+	 * @param type $rToolObject: The ResearchToolObject to be saved.
+	 */
+	public function set($rToolObject)
+	{
+		$this->load();
+		//If evaluation fails, some references are incorrect.
+		//We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed.
+		//TODO: Decide how to fix invalid references graciously.
+		if(!$rToolObject->evaluate()) 
+			return false;
+		$resourceSInstance = new Resource(SESSIONINSTANCE . '/' . $rToolObject->uid);
+		//Remove the old value stored with the given id
+		$this->model->subtract($this->model->find($resourceSInstance, null, null));
+
+		//Set the new values
+		$resourceSInstanceType = new Resource(SESSIONINSTANCE);
+		$predicateType = new Resource(RTYPE);
+		$this->model->add(new Statement($resourceSInstance, $predicateType, $resourceSInstanceType));
+
+		$sInstanceId = new Literal($rToolObject->uid);
+		$predicateId = new Resource(UID);
+		$this->model->add(new Statement($resourceSInstance, $predicateId, $sInstanceId));
+
+		$sInstanceTitle = new Literal($rToolObject->title);
+		$predicateTitle = new Resource(TITLE);
+		$this->model->add(new Statement($resourceSInstance, $predicateTitle, $sInstanceTitle));
+
+		$sInstanceLocation = new Literal($rToolObject->location);
+		$predicateLocation = new Resource(LOCATION);
+		$this->model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation));
+
+		$sInstanceFacilitator = new Literal($rToolObject->facilitator->uid);
+		$predicateFacilitator = new Resource(FACILITATOR);
+		$this->model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator));
+
+		$sInstanceStartTime = new Literal($rToolObject->starttime->getTimestamp());
+		$predicateStartTime = new Resource(STARTTIME);
+		$this->model->add(new Statement($resourceSInstance, $predicateStartTime, $sInstanceStartTime));
+
+		$sInstanceEndTime = new Literal($rToolObject->endtime->getTimestamp());
+		$predicateEndTime = new Resource(ENDTIME);
+		$this->model->add(new Statement($resourceSInstance, $predicateEndTime, $sInstanceEndTime));
+
+		if(isset($rToolObject->notes))
+		{
+			foreach($rToolObject->notes as $note)
+			{
+				$sInstanceNote = new Literal($note);
+				$predicateNote = new Resource(HAS_NOTE);
+				$this->model->add(new Statement($resourceSInstance, $predicateNote, $sInstanceNote));
+			}
+		}
+
+		$sInstanceSession = new Literal($rToolObject->session->uid);
+		$predicateSession = new Resource(OF_SESSION);
+		$this->model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession));
+
+		if(isset($rToolObject->resultset))
+		{
+			//$sInstanceResultSet = new Literal($rToolObject->resultset->uid);
+			$sInstanceResultSet = new Literal($rToolObject->resultset);
+			$predicateResultSet = new Resource(HAS_RESULTSET);
+			$this->model->add(new Statement($resourceSInstance, $predicateResultSet, $sInstanceResultSet));
+		}
+		$this->save();
+		return true;
+	}
+}
+?>
Index: Dev/trunk/rdfConstants.php
===================================================================
--- Dev/trunk/rdfConstants.php	(revision 191)
+++ Dev/trunk/rdfConstants.php	(revision 195)
@@ -22,4 +22,6 @@
 define('RESPONDENT',SURVEYTOOL_RESOURCES_NAMESPACE . 'respondent');
 define('APPDATA',SURVEYTOOL_RESOURCES_NAMESPACE . 'graph');
+define('SESSIONINSTANCE', SURVEYTOOL_RESOURCES_NAMESPACE . 'sessioninstance');
+define('RESULTSET', SURVEYTOOL_RESOURCES_NAMESPACE . 'resultset');
 
 // Predicates used for RDF triples
@@ -52,4 +54,11 @@
 define('HAS_SURVEY', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_survey');
 define('HAS_ANSWERSET', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_answerset');
+define('LOCATION', SURVEYTOOL_PREDICATES_NAMESPACE . 'location');
+define('FACILITATOR', SURVEYTOOL_PREDICATES_NAMESPACE . 'facilitator');
+define('STARTTIME', SURVEYTOOL_PREDICATES_NAMESPACE . 'starttime');
+define('ENDTIME', SURVEYTOOL_PREDICATES_NAMESPACE . 'endtime');
+define('HAS_NOTE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_note');
+define('OF_SESSION', SURVEYTOOL_PREDICATES_NAMESPACE . 'of_session');
+define('HAS_RESULTSET', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_resultset');
 
 ?>
