Index: Dev/branches/jos-branch/classes/models/Answer.php
===================================================================
--- Dev/branches/jos-branch/classes/models/Answer.php	(revision 215)
+++ Dev/branches/jos-branch/classes/models/Answer.php	(revision 217)
@@ -11,5 +11,5 @@
  */
 class Answer extends ResearchToolObject {
-	public static $filename = 'data/answers/answers.rdf';
+	public static $filename = 'data/results/answers.rdf';
 
     public $question;
@@ -115,6 +115,6 @@
 
 		//Ensure the required folder exists.
-		if(!is_dir('data/answers'))
-			mkdir('data/answers');
+		if(!is_dir('data/results'))
+			mkdir('data/results');
 		$model = ResearchToolObject::load(Answer::$filename);
 
Index: Dev/branches/jos-branch/classes/models/AnswerSet.php
===================================================================
--- Dev/branches/jos-branch/classes/models/AnswerSet.php	(revision 215)
+++ Dev/branches/jos-branch/classes/models/AnswerSet.php	(revision 217)
@@ -10,5 +10,5 @@
  */
 class AnswerSet extends ResearchToolObject{
-	public static $filename = 'data/answers/answersets.rdf';
+	public static $filename = 'data/results/answersets.rdf';
 
 	public $survey;
@@ -83,6 +83,6 @@
 			return false;
 		//Ensure the required folder exists.
-		if(!is_dir('data/answers/'))
-			mkdir('data/answers/');
+		if(!is_dir('data/results/'))
+			mkdir('data/results/');
 
 		$model = ResearchToolObject::load(AnswerSet::$filename);
Index: Dev/branches/jos-branch/classes/models/Question.php
===================================================================
--- Dev/branches/jos-branch/classes/models/Question.php	(revision 215)
+++ Dev/branches/jos-branch/classes/models/Question.php	(revision 217)
@@ -1,4 +1,3 @@
 <?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
Index: Dev/branches/jos-branch/classes/models/ResultSet.php
===================================================================
--- Dev/branches/jos-branch/classes/models/ResultSet.php	(revision 217)
+++ Dev/branches/jos-branch/classes/models/ResultSet.php	(revision 217)
@@ -0,0 +1,163 @@
+<?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 ResultSet
+ */
+class ResultSet extends ResearchToolObject{
+
+	private static $filename = 'data/results/resultsets.rdf';
+
+	public $answersets;
+	public $playerresults;
+	public $groupresults;
+	public $periodicresults;
+
+	/**
+	 * Constructor for an ResultSet object.
+	 * @param type $uid
+	 * @param type $answersets;
+	 * @param type $playerresults;
+	 * @param type $groupresults;
+	 * @param type $periodicresults;
+	 */
+	public function __construct($uid=null, $answersets = null, $playerresults = null, $groupresults = null, $periodicresults = null)
+	{
+		if(!isset($uid))
+		{
+			$uid = md5(uniqid(rand(), true));
+		}
+		
+		$this->uid = $uid;
+		$this->answersets = $answersets;
+		$this->playerresults = $playerresults;
+		$this->groupresults = $groupresults;
+		$this->periodicresults = $periodicresults;
+	}
+
+	/**
+	 * funtion evaluate()
+	 * evaluates the references of all results
+	 */
+	public function evaluate()
+	{
+		if(!empty($this->answersets) && is_string($this->answersets[0]))
+		{
+			$newAnswerSets = array();
+			foreach($this->answersets as $answerSet)
+			{
+				$result = AnswerSet::get(array("uid" => $answerSet));
+				if(!isset($result[0]))
+					return false;
+				$newAnswerSets[] = $result[0];
+			}			
+			$this->answersets = $newAnswerSets;
+		}
+		//TODO: Evaluate the other sets when they are implemented.
+
+		return true;
+	}
+
+	/**
+	 * function save()
+	 * Saves the current object into the database.
+	 */
+	public function save()
+	{
+		//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(!$this->evaluate()) 
+			return false;
+		//Ensure the required folder exists.
+		if(!is_dir('data/results/'))
+			mkdir('data/results/');
+
+		$model = ResearchToolObject::load(ResultSet::$filename);
+
+		$resourceResultSet = new Resource(RESULTSET . '/' . $this->uid);
+		//Remove the old value stored with the given id
+		$model->subtract($model->find($resourceResultSet, null, null));
+
+		//Set new values
+		$resourceResultSetType = new Resource(RESULTSET);
+		$predicateRType = new Resource(RTYPE);
+		$model->add(new Statement($resourceResultSet, $predicateRType, $resourceResultSetType));
+
+		$resultSetId = new Literal($this->uid);
+		$predicateId = new Resource(UID);
+		$model->add(new Statement($resourceResultSet, $predicateId, $resultSetId));
+
+		if(isset($this->answersets))
+		{
+			foreach($this->answersets as $answerset)
+			{
+				$answerSetId = new Literal($answerset->uid);
+				$predicateAnswerSet = new Resource(HAS_ANSWERSET);
+				$model->add(new Statement($resourceResultSet, $predicateAnswerSet, $answerSetId));
+			}
+		}
+
+		//TODO: store other sets when they are implemented.
+
+		$model->saveAs(ResultSet::$filename, 'rdf');
+		return true;
+	}
+
+	/**
+	 * function get()
+	 * @param type $arguments : An array having one or more of the following elements:
+	 * 'uid', 'answersets', 'playerresults', 'groupresults', 'periodicresults'
+	 */
+	public static function get($arguments)
+	{
+		$model = ResearchToolObject::load(ResultSet::$filename);
+		//Build the query string
+		$querystring = '
+			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			PREFIX resources: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			SELECT DISTINCT ?uid
+			WHERE
+			{
+				_resultset predicates:resource_type resources:resultset ;
+				predicates:uid ?uid ;
+				' . ResearchToolObject::createArguments($arguments) . '
+			}';
+
+		//Query the model
+		$results = $model->sparqlQuery($querystring);
+		$resultSets = array();
+		if(!empty($results))
+		{
+			foreach($results as $result)
+			{
+				$answerSets = ResultSet::getAnswerSets($model, $result['?uid']->label);
+				$resultSets[] = new ResultSet($result['?uid']->label, $answerSets, array(), array(), array());
+			}
+		}
+		return $resultSets;
+	}
+
+	/**
+	 * function getAnswerSets()
+	 * @param type $uid : The ResultSet uid for which the answerSets should be retrieved.
+	 */
+	private static function getAnswerSets($model, $uid)
+	{
+		$result = $this->model->findRegex("[(".$uid.")]", "[(has_answerset)]" ,null);
+		$iterator = $result->getStatementIterator();
+		$answersets = array();
+		while($iterator->hasNext())
+		{
+			$element = $iterator->next();
+			$answersets[] = $element->getLabelObject();
+		}
+		return $answersets;
+	}
+
+
+
+}
Index: Dev/branches/jos-branch/classes/models/Session.php
===================================================================
--- Dev/branches/jos-branch/classes/models/Session.php	(revision 217)
+++ Dev/branches/jos-branch/classes/models/Session.php	(revision 217)
@@ -0,0 +1,325 @@
+<?php
+require_once 'rdfConstants.php';
+// Include RAP Library to write RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+/**
+ * Description of Session
+ *
+ * @author jkraaijeveld
+ */
+
+class Session extends ResearchToolObject
+{
+	private static $filename = 'data/sessions/sessions.rdf';
+
+	public $title;
+	public $creator;
+	public $creationdate;
+	public $pipeline;
+
+	
+	/**
+	 * Constructor for a Session object
+	 * @param type $uid
+	 * @param type $title
+	 * @param type $creator
+	 * @param type $datetime
+	 * @param type $pipeline
+	 */
+	public function __construct($uid = null, $title = null, $creator = null, $datetime = null, $pipeline = null)
+	{
+		if(!isset($uid))
+		{
+			$uid = md5(uniqid(rand(), true));
+		}
+		$this->uid = $uid;
+		$this->title = $title;
+		$this->creator = $creator;
+		$this->creationdate = $datetime;
+		$this->pipeline = $pipeline;
+	}
+
+	/*
+	 * function evaluate(()
+	 * Evaluates all the references of this object.
+	 */
+	public function evaluate()
+	{
+		if(is_string($this->creator))
+		{
+			$result = User::get(array("uid" => $this->creator));
+			if(!isset($result[0]))
+				return false;
+			$this->creator = $result[0];
+		}
+		if(!empty($this->pipeline) && is_string($this->pipeline[0]))
+		{
+			$newPipeline = array();
+			foreach($this->pipeline as $element)
+			{
+				//Check if the element's UID can be found in surveys, if not: 
+				//Check applications. If it isn't in either: invalid reference.
+				$result = Survey::get(array("uid" => $element));
+				if(!isset($result[0]))
+					$result = Application::get(array("uid" => $element));
+				if(!isset($result[0]))
+					return false;
+				$newPipeline[] = $result[0];
+			}
+			$this->pipeline = $newPipeline;
+		}
+		return true;
+	}
+
+	/**
+	 * function save()
+	 * Saves the current object into the database.
+	 */
+	public function save()
+	{
+		//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(!$this->evaluate())
+			return false;
+
+		//Ensure the required folder exists.
+		if(!is_dir('data/sessions/'))
+			mkdir('data/sessions/');
+
+		$model = ResearchToolObject::load(Session::$filename);
+
+		$resourceSession = new Resource(SESSION . '/' . $this->uid);
+		//Remove the old value stored with the given id
+		$model->subtract($model->find($resourceSession, null, null));
+
+		//Set the new values
+		$resourceSessionType = new Resource(SESSION);
+		$predicateType = new Resource(RTYPE);
+		$model->add(new Statement($resourceSession, $predicateType, $resourceSessionType));
+
+		$sessionId = new Literal($this->uid);
+		$predicateId = new Resource(UID);
+		$model->add(new Statement($resourceSession, $predicateId, $sessionId));
+
+		$sessionTitle = new Literal($this->title);
+		$predicateTitle = new Resource(TITLE);
+		$model->add(new Statement($resourceSession, $predicateTitle, $sessionTitle));
+
+		$sessionCreator = new Literal($this->creator->uid);
+		$predicateCreator = new Resource(CREATOR);
+		$model->add(new Statement($resourceSession, $predicateCreator, $sessionCreator));
+
+		$sessionTimestamp = new Literal($this->creationdate->getTimestamp());
+        //      $sessionTimestamp = new Literal($this->datetime);    // Edit of above function, allows for creation of session, but still results in errors...
+        $predicateTimestamp = new Resource(CREATIONDATE);
+		$model->add(new Statement($resourceSession, $predicateTimestamp, $sessionTimestamp));
+
+		//Create a sequence to store the different applications and surveys.
+		if(isset($this->pipeline))
+		{
+			foreach($this->pipeline as $element)
+			{
+				$sessionObject = new Literal($element->uid);
+				$predicateObject = null;
+				if(get_class($element) == "Application")
+					$predicateObject = new Resource(HAS_APPLICATION);
+				else if(get_class($element) == "Survey")
+					$predicateObject = new Resource(HAS_SURVEY);
+				if(isset($predicateObject))
+					$model->add(new Statement($resourceSession, $predicateObject, $sessionObject));
+			}
+		}
+
+		if(isset($this->answersets))
+		{
+			foreach($this->answersets as $answerset)
+			{
+				$sessionAnswerSet = new Literal($answerset->uid);
+				$predicateAnswerSet = new Resource(HAS_ANSWERSET);
+				$model->add(new Statement($resourceSession, $predicateAnswerSet, $sessionAnswerSet));
+			}
+		}
+
+		$model->saveAs(Session::$filename, 'rdf');
+		return true;
+	}
+
+
+	/**
+	 * function get()
+	 * @param type $arguments : An array containing one or more of the following elements:
+	 * 'uid', 'title', 'creationdate', 'applications', 'surveys'
+	 */
+	public static function get($arguments)
+	{
+		$model = ResearchToolObject::load(Session::$filename);
+	
+		//Build the query string
+		$querystring = '
+			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+			SELECT DISTINCT ?uid, ?title, ?creator, ?creationdate
+			WHERE
+			{
+				_session predicates:resource_type resources:session ;
+				predicates:uid ?uid ;
+				predicates:title ?title ;
+				predicates:creator ?creator ;
+				predicates:creationdate ?creationdate ;
+				' . ResearchToolObject::createArguments($arguments) . '
+			}';
+		//Query the model
+		$results = $model->sparqlQuery($querystring);
+		$sessions = array();
+		if(!empty($results))
+		{
+			foreach($results as $result)
+			{
+				//Create a session object out of every result, get all required fields as well.
+				$pipeline = Session::getPipeline($model, $result['?uid']->label);
+				$creator = $result['?creator']->label;
+				$creationdate = new DateTime();
+				$creationdate->setTimestamp(intval($result['?creationdate']->label));
+				$sessions[] = new Session($result['?uid']->label, $result['?title']->label, $creator, $creationdate, $pipeline);
+			}
+		}
+		return $sessions;
+	}
+	/**
+	 * function getPipeline()
+	 * param type $uid : The Session uid for which the pipeline should be retrieved.
+	 */
+	private static function getPipeline($model, $uid)
+	{
+		$result = $model->findRegex("[(".$uid.")]", "[(has_application)|(has_survey)]" ,null);
+		$iterator = $result->getStatementIterator();
+		$pipeline = array();
+		while($iterator->hasNext())
+		{
+			$element = $iterator->next();
+			$pipeline[] = $element->getLabelObject();
+		}
+		return $pipeline;
+	}
+
+	/**
+	 * function toSPSS
+	 * @param type $location
+	 * Writes an SPSS parseable file at the given location, named '$datetime_$title.txt'
+	 * One big note about toSPSS: If this session contains multiple instances of THE SAME Survey,
+	 * the world burns, people die, etcetera. (or, in a more fortunate case, the latest values
+	 * are written to the file whilst the others get lost.
+	 */
+	//DO NOT USE - BROKEN AS OF 23/12/2011
+	public function toSPSS($location)
+	{
+		$this->evaluate();
+		if(!is_dir($location))
+		{
+			mkdir($location);
+		}
+		//Create the filename, open the file at the given location
+		$fileName = $this->datetime->format("d-m-Y") . "_" . $this->title . ".txt";
+
+		//Make a list of all 'column headers', e.g. "respondent" and all the question codes.
+		$headers = array();
+		$headers[] = "respondent";
+		foreach ($this->pipeline as $element)
+		{
+			if(get_class($element) == "Survey")
+			{
+				$element->evaluate();
+				foreach($element->questions as $question)
+				{
+					//TODO: This might need fixing after lazy initialization refactoring.
+					$headers[] = $element->title . '_' . $question->uid;
+				}
+			}
+		}
+		//Return if there are no surveys.
+		if(count($headers) < 2)
+			return;
+		
+		//Get the answers for all respondents
+		$answers = $this->getAnswers($headers);
+
+		//Create the strings and write to file.
+		$headerString = "";
+		foreach($headers as $headerElement)
+		{
+			$headerString = $headerString . $headerElement . "\t";
+		}
+		$fileHandler = fopen($location . '/' . $fileName, 'w') or die("File in use");
+		fwrite($fileHandler, $headerString . "\n");
+		foreach($answers as $entry)
+		{
+			$entryString = "";
+			//PHP doesn't automatically sort the indices so I have to do it myself
+			//Entry elements can now be printed in order to match the headers
+			for ($i = 0; $i < count($headers); $i++)
+			{
+				if(in_array($i, array_keys($entry)))
+					$entryString = $entryString . $entry[$i] . "\t";	
+				else
+					$entryString = $entryString . "\t";
+			}
+			fwrite($fileHandler, $entryString . "\n");	
+		}
+	}
+
+	/*
+	 * function getAnswers
+	 * @param type $headers
+	 * Based on the questions specified in the headers array, matches the answers of every
+	 * respondent to the correct questions and returns an array containing a list of answers per 
+	 * respondent
+	 */
+	private function getAnswers($headers)
+	{
+		//Add the answers per survey per respondent. Requires some extra looping to assure proper ordering.
+		//Keeps a list of respondents which have already been used. If an answerset exists for a respondent which
+		//already exists within the answers-array, use the index of the respondent. Else: make a new row.
+		$respondentsUsed = array();
+		$answers = array();
+		foreach($this->answersets as $answerset)
+		{
+			$entryIndex;
+			if(in_array($answerset->respondent->name, $respondentsUsed))
+			{
+				$entryIndex = array_search($answerset->respondent->name, $respondentsUsed);
+				$entry = $answers[$entryIndex];
+			}
+			else
+			{
+				$entry = array();
+				$entry[0] = $answerset->respondent->name;
+				$entryIndex = count($respondentsUsed);
+				$respondentsUsed[] = $answerset->respondent->name;
+			}
+			foreach ($answerset->answers as $answer)
+			{
+				$index = array_search($answerset->survey->title . '_' . $answer->question->uid, $headers);
+				//Index has to be a good number, else the answer doesn't belong in this session
+				//Causes might be a missing question or having a wrong survey
+				if($index != 0)
+				{
+					$value = "";
+					foreach ($answer->values as $val)
+					{
+						$value = $value . $val . ",";
+					}
+					//We all hate trailing commas
+					if (strlen($value) > 0) { $value = substr($value, 0, strlen($value)-1); }
+					$entry[$index] = $value;
+				}
+			}
+			$answers[$entryIndex] = $entry;
+		}
+		return $answers;
+	}
+
+}	
+
+
+?>
Index: Dev/branches/jos-branch/classes/models/SessionInstance.php
===================================================================
--- Dev/branches/jos-branch/classes/models/SessionInstance.php	(revision 217)
+++ Dev/branches/jos-branch/classes/models/SessionInstance.php	(revision 217)
@@ -0,0 +1,248 @@
+<?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 SessionInstance
+ *
+ * @author jkraaijeveld
+ */
+
+class SessionInstance extends ResearchToolObject
+{
+	public static $filename = 'data/sessions/sessioninstances.rdf';
+
+	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()
+	{
+		if(is_string($this->facilitator))
+		{
+			$result = User::get(array("uid" => $this->facilitator));
+			if(!isset($result[0]))
+				return false;
+			$this->facilitator = $result[0];
+		}
+
+		if(is_string($this->session))
+		{
+			$result = Session::get(array("uid" => $this->session));
+			if(!isset($result[0]))
+				return false;
+			$this->session = $result[0]; 
+		}
+
+		if(is_string($this->resultset))
+		{
+			$result = ResultSet::get(array("uid" => $this->resultset));
+			if(!isset($result[0]))
+				return true;
+			$newResultSets[] = $result[0];
+		}
+		return true;
+	}
+
+	/**
+	 * function save()
+	 * Saves the current object into the database.
+	 */
+	public function save()
+	{
+		//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(!$this->evaluate()) 
+			return false;
+
+		//Ensure the required folder exists.
+		if(!is_dir('data/sessions/'))
+			mkdir('data/sessions/');
+
+		$model = ResearchToolObject::load(SessionInstance::$filename);
+
+		$resourceSInstance = new Resource(SESSIONINSTANCE . '/' . $this->uid);
+		//Remove the old value stored with the given id
+		$model->subtract($model->find($resourceSInstance, null, null));
+
+		//Set the new values
+		$resourceSInstanceType = new Resource(SESSIONINSTANCE);
+		$predicateType = new Resource(RTYPE);
+		$model->add(new Statement($resourceSInstance, $predicateType, $resourceSInstanceType));
+
+		$sInstanceId = new Literal($this->uid);
+		$predicateId = new Resource(UID);
+		$model->add(new Statement($resourceSInstance, $predicateId, $sInstanceId));
+
+		$sInstanceTitle = new Literal($this->title);
+		$predicateTitle = new Resource(TITLE);
+		$model->add(new Statement($resourceSInstance, $predicateTitle, $sInstanceTitle));
+
+		$sInstanceLocation = new Literal($this->location);
+		$predicateLocation = new Resource(LOCATION);
+		$model->add(new Statement($resourceSInstance, $predicateLocation, $sInstanceLocation));
+
+		$sInstanceFacilitator = new Literal($this->facilitator->uid);
+		$predicateFacilitator = new Resource(FACILITATOR);
+		$model->add(new Statement($resourceSInstance, $predicateFacilitator, $sInstanceFacilitator));
+
+		$sInstanceStartTime = new Literal($this->starttime->getTimestamp());
+		$predicateStartTime = new Resource(STARTTIME);
+		$model->add(new Statement($resourceSInstance, $predicateStartTime, $sInstanceStartTime));
+
+		$sInstanceEndTime = new Literal($this->endtime->getTimestamp());
+		$predicateEndTime = new Resource(ENDTIME);
+		$model->add(new Statement($resourceSInstance, $predicateEndTime, $sInstanceEndTime));
+
+		if(isset($this->notes))
+		{
+			foreach($this->notes as $note)
+			{
+				$sInstanceNote = new Literal($note);
+				$predicateNote = new Resource(HAS_NOTE);
+				$model->add(new Statement($resourceSInstance, $predicateNote, $sInstanceNote));
+			}
+		}
+
+		$sInstanceSession = new Literal($this->session->uid);
+		$predicateSession = new Resource(OF_SESSION);
+		$model->add(new Statement($resourceSInstance, $predicateSession, $sInstanceSession));
+
+		if(isset($this->resultset))
+		{
+			//$sInstanceResultSet = new Literal($this->resultset->uid);
+			$sInstanceResultSet = new Literal($this->resultset);
+			$predicateResultSet = new Resource(HAS_RESULTSET);
+			$model->add(new Statement($resourceSInstance, $predicateResultSet, $sInstanceResultSet));
+		}
+		$model->saveAs(SessionInstance::$filename, 'rdf');
+		return true;
+	}
+
+	/**
+	 * 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 static function get($arguments)
+	{
+		$model = ResearchToolObject::load(SessionInstance::$filename);
+
+		//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 ;
+				' . ResearchToolObject::createArguments($arguments) . '
+	}';
+		//Query the model
+		$results = $model->sparqlQuery($querystring);
+		$sessioninstances = array();
+		if(!empty($results))
+		{	
+			foreach($results as $result)
+			{
+				//Create a SessionInstance object out of every result. Get all the required fields as well.
+				$notes = SessionInstance::getNotes($model, $result['?uid']->label);
+				$resultset = SessionInstance::getResultSet($model, $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 static function getNotes($model, $uid)
+	{
+		$result = $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 static function getResultSet($model, $uid)
+	{
+		//TODO: Implement when ResultSet is in.
+		return null;
+	}
+
+
+
+}
