Index: /Dev/branches/jQueryUI/server/classes/models/ApplicationInstance.php
===================================================================
--- /Dev/branches/jQueryUI/server/classes/models/ApplicationInstance.php	(revision 254)
+++ /Dev/branches/jQueryUI/server/classes/models/ApplicationInstance.php	(revision 254)
@@ -0,0 +1,170 @@
+<?php
+require_once 'rdfConstants.php';
+//Include RAP Library to write to RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+
+/**
+ * Description of ApplicationInstance
+ *
+ * @author jkraaijeveld
+ */
+
+class ApplicationInstance extends ResearchToolObject{
+	public static $filename = 'data/applications/applicationinstances.rdf';
+
+	public $application;
+	public $starttime;
+	public $endtime;
+	public $open;
+	public $playerresults;
+	public $groupresults;
+	public $periodicresults;
+
+	/**
+	 * Constructor for an ApplicationInstance object.
+	 * @param type $uid: The UID of the application instance object.
+	 * @param type $application: The related application.
+	 * @param type $starttime: The starttime of the application round.
+	 * @param type $endtime: The endtime of the application round.
+	 * @param type $open: A boolean to specify if people can start this application.
+	 * @param type $playerresults: Individual player results from playing.
+	 * @param type $groupresults: Group-based results from playing.
+	 * @param type $periodicresults: Periodical results from playing.
+	 */
+	public function __construct($uid = null, $application = null, $starttime = null, $endtime = null, $open = false, $playerresults = null, $groupresults = null, $periodicresults = null)
+	{
+		if(!isset($uid))
+		{
+			$uid = md5(uniqid(rand(), true));
+		}
+		$this->uid = $uid;
+		$this->application = $application;
+		$this->starttime = $starttime;
+		$this->endtime = $endtime;
+		$this->open = $open;
+		$this->playerresults = $playerresults;
+		$this->groupresults = $groupresults;
+		$this->periodicresults = $periodicresults;
+	}
+
+	/**
+	 * function evaluate()
+	 * Evaluates the references in this object
+	 */
+	public function evaluate()
+	{
+		if(is_string($this->application))
+		{
+			$result = Application::get(array("uid" => $this->application));
+			if(!isset($result[0]))
+				return false;
+			$this->application = $result[0];
+		}
+
+		//TODO: Evaluate game results.
+
+
+		return true;
+	}
+
+	/**
+	 * function save()
+	 * Saves the current object into the database.
+	 */
+	public function save()
+	{
+		//Do note save if there are invalid references in this object.
+		if(!$this->evaluate())
+			return false;
+
+		//Ensure the required folder exists.
+		if(!is_dir('data/applications/'))
+			mkdir('data/applications/');
+
+		$model = ResearchToolObject::load(ApplicationInstance::$filename);
+		$resourceAI = new Resource(APPLICATIONINSTANCE.'/'.$this->uid);
+		//Remove the old value stored with the given id.
+		$model->subtract($model->find($resourceAI, null, null));
+
+		//Add the new statements to the model
+		$resourceAIType = new Resource(APPLICATIONINSTANCE);
+		$predicateRType = new Resource(RTYPE);
+		$model->add(new Statement($resourceAI, $predicateRType, $resourceAIType));
+
+		$AIUid = new Literal($this->uid);
+		$predicateUid = new Resource(UID);
+		$model->add(new Statement($resourceAI, $predicateUid, $AIUid));
+
+		$AIApplication = new Literal($this->application->uid);
+		$predicateApplication = new Resource(OF_APPLICATION);
+		$model->add(new Statement($resourceAI, $predicateApplication, $AIApplication));
+
+		$AIStartTime = new Literal($this->starttime->getTimestamp());
+		$predicateStartTime = new Resource(STARTTIME);
+		$model->add(new Statement($resourceAI, $predicateStartTime, $AIStartTime));
+
+		$AIEndTime = new Literal($this->endtime->getTimestamp());
+		$predicateEndTime = new Resource(ENDTIME);
+		$model->add(new Statement($resourceAI, $predicateEndTime, $AIEndTime));
+
+		$AIOpen = new Literal($this->open);
+		$predicateOpen = new Resource(OPEN);
+		$model->add(new Statement($resourceAI, $predicateOpen, $AIOpen));
+
+		$model->saveAs(ApplicationInstance::$filename, 'rdf');
+		return true;
+		//TODO: Game results.
+	}
+
+	/**
+	 * function get($arguments)
+	 * Gets the array of ApplicationInstance objects belonging to the arguments supplied.
+	 * @param type $arguments : An array containing zero or more of the following keys:
+	 * 							'uid', 'of_application', 'starttime', 'endtime', 'open'
+	 * TODO: Support game results.
+	 */ 
+	public static function get($arguments)
+	{
+		$model = ResearchToolObject::load(ApplicationInstance::$filename);
+
+		//Build the query string
+		$querystring = '
+			PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
+			PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
+			SELECT DISTINCT ?uid, ?of_application, ?starttime, ?endtime, ?open
+			WHERE
+			{
+				_applicationinstance	predicates:resource_type	resources:applicationinstance ;
+				predicates:uid ?uid ;
+				predicates:of_application ?of_application ;
+				predicates:starttime ?starttime ;
+				predicates:endtime ?endtime ;
+				predicates:open ?open ;
+				' . ResearchToolObject::createArguments($arguments) . '
+			}';
+		//Query the model
+		$results = $model->sparqlQuery($querystring);
+
+		//Create the corresponding ApplicationInstance objects
+		$aInstances = array();
+		if(!empty($results))
+		{
+			foreach($results as $result)
+			{
+				$startTime = new DateTime();
+				$startTime->setTimestamp(intval($result['?starttime']->label));
+				$endTime = new DateTime();
+				$endTime->setTimestamp(intval($result['?endtime']->label));
+				$open = false;
+				if ($result['?open'] == 'true')
+					$open = true;
+
+				$aInstances[] = new ApplicationInstance($result['?uid']->label, $result['?of_application']->label, $startTime, $endTime, $open, null, null, null); 
+			}
+		}
+		return $aInstances;
+
+
+	}
+}
+?>
Index: /Dev/branches/jQueryUI/server/classes/models/ResearchToolObject.php
===================================================================
--- /Dev/branches/jQueryUI/server/classes/models/ResearchToolObject.php	(revision 253)
+++ /Dev/branches/jQueryUI/server/classes/models/ResearchToolObject.php	(revision 254)
@@ -68,5 +68,7 @@
 				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;
+				case "resultset" : $addition = "predicates:has_resultset '" . $arguments[$key] . "\n"; break;
+				case "of_application" : $addition = "predicates:of_application '" . $arguments[$key] . "\n"; break;
+				case "open" : $addition = "predicates:open '" . $arguments[$key] . "\n"; break;
 			}
 			$argumentString = $argumentString . $addition;
Index: /Dev/branches/jQueryUI/server/rdfConstants.php
===================================================================
--- /Dev/branches/jQueryUI/server/rdfConstants.php	(revision 253)
+++ /Dev/branches/jQueryUI/server/rdfConstants.php	(revision 254)
@@ -24,4 +24,5 @@
 define('SESSIONINSTANCE', SURVEYTOOL_RESOURCES_NAMESPACE . 'sessioninstance');
 define('RESULTSET', SURVEYTOOL_RESOURCES_NAMESPACE . 'resultset');
+define('APPLICATIONINSTANCE', SURVEYTOOL_RESOURCES_NAMESPACE . 'applicationinstance');
 
 // Predicates used for RDF triples
@@ -60,5 +61,7 @@
 define('HAS_NOTE', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_note');
 define('OF_SESSION', SURVEYTOOL_PREDICATES_NAMESPACE . 'of_session');
+define('OF_APPLICATION', SURVEYTOOL_PREDICATES_NAMESPACE . 'of_application');
 define('HAS_RESULTSET', SURVEYTOOL_PREDICATES_NAMESPACE . 'has_resultset');
 define('CREATIONDATE', SURVEYTOOL_PREDICATES_NAMESPACE . 'creationdate');
+define('OPEN', SURVEYTOOL_PREDICATES_NAMESPACE . 'open');
 ?>
