Changeset 149 for Dev/trunk/classes
- Timestamp:
- 11/07/11 16:55:36 (13 years ago)
- Location:
- Dev/trunk/classes
- Files:
-
- 7 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/ApplicationConnector.php
r144 r149 11 11 * @author jkraaijeveld 12 12 */ 13 class ApplicationConnector implements IConnector 14 13 class ApplicationConnector implements IConnector{ 14 15 15 protected $model; 16 16 protected $fileName = 'data/applications/applications.rdf'; … … 19 19 * Constructor for ApplicationConnector. 20 20 */ 21 public function __construct() { 21 public function __construct() 22 { 22 23 //Ensure the required folder for this connector exists 23 if (!is_dir('data/applications/')) { 24 mkdir('data/applications/', null, true); 25 } 24 if (!is_dir('data/applications/')) 25 mkdir('data/applications/'); 26 26 } 27 27 28 28 /** 29 29 * function load() … … 33 33 //Get the Memory Model from the ModelFactory 34 34 $this->model = ModelFactory::getDefaultModel(); 35 35 36 36 //Ensure the required file exists before loading 37 if 37 if(file_exists($this->fileName)) 38 38 $this->model->load($this->fileName); 39 39 } 40 40 41 41 /** 42 42 * function save() … … 44 44 */ 45 45 public function save() { 46 $this->model->saveAs($this->fileName, 'rdf');46 $this->model->saveAs($this->fileName,'rdf'); 47 47 } 48 48 49 49 /** 50 50 * function get($arguments) … … 58 58 $keys = array_keys($arguments); 59 59 //Set default values for arguments 60 $uid = "?uid"; 61 $title = "?title"; 62 $description = "?description"; 63 $style = "?style"; 60 $uid = "?uid"; $title = "?title"; $description = "?description"; $style = "?style"; 64 61 //Set the arguments if they are supplied 65 if 66 $uid = "\"" . $arguments["uid"] ."\"";67 if 68 $title = '\'' . $arguments["title"] .'\'';69 if 70 $description = "\"" . $arguments["description"] ."\"";71 if 72 $style = "\"" . $arguments["style"] . "\"";62 if(in_array("uid", $keys)) 63 $uid = "\"".$arguments["uid"]."\""; 64 if(in_array("title", $keys)) 65 $title = '\''.$arguments["title"].'\''; 66 if(in_array("description", $keys)) 67 $description = "\"".$arguments["description"]."\""; 68 if(in_array("style", $keys)) 69 $style = "\"".$arguments["style"]."\""; 73 70 74 71 //Create the querystring … … 93 90 $results = $this->model->sparqlQuery($querystring); 94 91 $applications = array(); 95 if (!empty($results)) { 92 if(!empty($results)) 93 { 96 94 //Run over all results and create appropriate Application objets 97 foreach ($results as $result) { 98 $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label); 95 foreach($results as $result) 96 { 97 $applications[] = new Application($result['?uid']->label, $result['?title']->label, $result['?description']->label, $result['?style']->label); 99 98 } 100 99 } 101 100 return $applications; 102 101 } 103 102 104 103 /** 105 104 * function set() … … 108 107 * @param type $rToolObject: The ResearchToolObject to be saved. 109 108 */ 110 public function set($rToolObject) { 109 public function set($rToolObject) 110 { 111 111 $this->load(); 112 $resourceApplication = new Resource(APPLICATION . '/' .$rToolObject->uid);112 $resourceApplication = new Resource(APPLICATION.'/'.$rToolObject->uid); 113 113 //Remove the old value stored with the given id 114 114 $this->model->subtract($this->model->find($resourceApplication, null, null)); … … 117 117 $resourceApplicationType = new Resource(APPLICATION); 118 118 $predicateRType = new Resource(RTYPE); 119 $this->model->add(new Statement($resourceApplication, $predicateRType,$resourceApplicationType));120 119 $this->model->add(new Statement($resourceApplication,$predicateRType,$resourceApplicationType)); 120 121 121 $literalApplicationID = new Literal($rToolObject->uid); 122 122 $predicateUniqueID = new Resource(UID); 123 $this->model->add(new Statement($resourceApplication, $predicateUniqueID,$literalApplicationID));123 $this->model->add(new Statement($resourceApplication,$predicateUniqueID,$literalApplicationID)); 124 124 125 125 $applicationTitle = new Literal($rToolObject->title); 126 $predicateTitle = new Resource(TITLE); 127 $this->model->add(new Statement($resourceApplication, $predicateTitle,$applicationTitle));126 $predicateTitle = new Resource(TITLE); 127 $this->model->add(new Statement($resourceApplication,$predicateTitle,$applicationTitle)); 128 128 129 129 $applicationDescription = new Literal($rToolObject->description); 130 130 $predicateDescription = new Resource(DESCRIPTION); 131 $this->model->add(new Statement($resourceApplication, $predicateDescription,$applicationDescription));131 $this->model->add(new Statement($resourceApplication,$predicateDescription,$applicationDescription)); 132 132 133 133 $applicationStyle = new Literal($rToolObject->style); 134 134 $predicateStyle = new Resource(STYLE); 135 $this->model->add(new Statement($resourceApplication, $predicateStyle,$applicationStyle));136 137 135 $this->model->add(new Statement($resourceApplication,$predicateStyle,$applicationStyle)); 136 137 $this->save(); 138 138 } 139 140 139 } 141 140 -
Dev/trunk/classes/DatabaseInterface.php
r139 r149 21 21 private $userConnector; 22 22 private $surveyConnector; 23 private $respondentConnector; 24 private $answerConnector; 25 private $answerSetConnector; 26 private $sessionConnector; 23 27 24 28 /** … … 31 35 $this->userConnector = new UserConnector(); 32 36 $this->surveyConnector = new SurveyConnector(); 37 $this->respondentConnector = new RespondentConnector(); 38 $this->answerConnector = new AnswerConnector(); 39 $this->answerSetConnector = new AnswerSetConnector(); 40 $this->sessionConnector = new SessionConnector(); 33 41 } 34 42 … … 39 47 * @return type 40 48 */ 41 public function get($type, $arguments )49 public function get($type, $arguments = array()) 42 50 { 43 51 switch(strtolower($type)) … … 54 62 case "survey": 55 63 return $this->surveyConnector->get($arguments); 64 break; 65 case "respondent": 66 return $this->respondentConnector->get($arguments); 67 break; 68 case "answer": 69 return $this->answerConnector->get($arguments); 70 break; 71 case "answerset": 72 return $this->answerSetConnector->get($arguments); 73 break; 74 case "session": 75 return $this->sessionConnector->get($arguments); 76 break; 56 77 } 57 78 } … … 75 96 break; 76 97 case "Survey": 77 $this->surveyConnector->set($rToolObject); 98 $this->surveyConnector->set($rToolObject); 99 break; 100 case "Respondent": 101 $this->respondentConnector->set($rToolObject); 102 break; 103 case "Answer": 104 $this->answerConnector->set($rToolObject); 105 break; 106 case "AnswerSet": 107 $this->answerSetConnector->set($rToolObject); 108 break; 109 case "Session": 110 $this->sessionConnector->set($rToolObject); 111 break; 78 112 } 79 113 } -
Dev/trunk/classes/Question.php
r131 r149 29 29 public function __construct($uid, $title = null, $type = null, $description = null, $category = null, $answers = null) 30 30 { 31 if(!isset($uid)) 32 { 33 $uid = md5(uniqid(rand(), true)); 34 } 31 35 $this->uid = $uid; 32 36 $this->title = $title; -
Dev/trunk/classes/QuestionConnector.php
r131 r149 59 59 $keys = array_keys($arguments); 60 60 //Set default values for arguments 61 $uid = "?uid"; $title = "?title"; $type = "?type"; $description = "?description"; $category = "?category"; 61 $uid = "?uid"; $title = "?title"; $type = "?type"; $description = "?description"; $category = "?category"; $has_answer = ""; 62 62 //Set the arguments if they are supplied 63 63 if(in_array("uid", $keys)) … … 70 70 $description = "\"".$arguments["description"]."\""; 71 71 if(in_array("category", $keys)) 72 $style = "\"".$arguments["category"]."\""; 72 $style = "\"".$arguments["category"]."\""; 73 if(in_array("answers", $keys)) 74 { 75 foreach($arguments["answers"] as $answer) 76 { 77 $has_answer = $has_answer . 'predicates:has_answer \'' . $answer . '\' '; 78 } 79 } 73 80 74 81 $querystring = ' 75 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>82 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 76 83 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 77 84 SELECT DISTINCT ?uid, ?title, ?type, ?description, ?category … … 89 96 predicates:question_type ' . $type . ' 90 97 predicates:description ' . $description . ' 91 predicates:question_category ' . $category . ' 98 predicates:question_category ' . $category . ' 99 ' . $has_answer . ' 92 100 }'; 93 101 //Create the querystring 94 102 $results = $this->model->sparqlQuery($querystring); 103 95 104 96 105 $questions = array(); -
Dev/trunk/classes/Session.php
r69 r149 1 1 <?php 2 3 2 /** 4 3 * Description of Session 5 4 * 6 * @author fpvanagthoven5 * @author jkraaijeveld 7 6 */ 8 class Session {9 7 10 public $title; 11 public $description; 12 public $pipeline; 13 public $count; 8 class Session extends ResearchToolObject 9 { 10 public $title; 11 public $datetime; 12 public $pipeline; 13 public $answersets; 14 14 15 public function __construct($title, $description) { 16 $this->title = $title; 17 $this->description = $description; 18 $this->count = 0; 19 20 $this->pipeline = array(); 21 } 22 23 public static function getSession($info) 24 { 25 if (!empty($info)) 26 { 27 $title = $info['sessionTitle']; 28 $description = $info['sessionDescription']; 29 $session = new Session($title, $description); 30 $session->count = $info['pipelineCount']; 31 32 $pipelineCount = 1; 33 for ($i = 1; $i < $session->count + 1; $i++) 34 { 35 if (isset($info[$i . 's'])) 36 { 37 $session->pipeline[$i . 's'] = $info[$i . 's']; 38 } 39 else if (isset($info[$i . 'd'])) 40 { 41 $session->pipeline[$i . 'd'] = $info[$i . 'd']; 42 } 43 else if (isset($info[$i . 'a'])) 44 { 45 $session->pipeline[$i . 'a'] = $info[$i . 'a']; 46 } 15 16 /** 17 * Constructor for a Session object 18 * @param type $uid 19 * @param type $title 20 * @param type $datetime 21 * @param type $pipeline 22 */ 23 public function __construct($uid = null, $title = null, $datetime = null, $pipeline = null, $answersets = null) 24 { 25 if(!isset($uid)) 26 { 27 $uid = md5(uniqid(rand(), true)); 28 } 29 $this->uid = $uid; 30 $this->title = $title; 31 $this->datetime = $datetime; 32 $this->pipeline = $pipeline; 33 $this->answersets = $answersets; 34 } 35 } 47 36 48 $pipelineCount++;49 }50 51 return $session;52 }53 else54 return null;55 }56 37 57 }58 38 ?> -
Dev/trunk/classes/Survey.php
r139 r149 12 12 public $questions; 13 13 14 public function __construct($uid = null, $title = null, $description = null, $ questions = null) {14 public function __construct($uid = null, $title = null, $description = null, $creator = null, $questions = null) { 15 15 if(!isset($uid)) 16 16 { … … 19 19 $this->uid = $uid; 20 20 $this->title = $title; 21 $this->description = $description; 21 $this->description = $description; 22 $this->creator = $creator; 22 23 $this->questions = $questions; 23 24 } -
Dev/trunk/classes/SurveyConnector.php
r139 r149 55 55 $keys = array_keys($arguments); 56 56 //Set default values for arguments 57 $uid = "?uid"; $title = "?title"; $description = "?description"; $ questions = "";57 $uid = "?uid"; $title = "?title"; $description = "?description"; $creator = "?creator"; $questions = ""; 58 58 if(in_array("uid", $keys)) 59 59 $uid = '\''.$arguments["uid"].'\''; … … 61 61 $title = '\''.$arguments["title"].'\''; 62 62 if(in_array("description", $keys)) 63 $description = "\"".$arguments["description"]."\""; 63 $description = "\"".$arguments["description"]."\""; 64 if(in_array("creator", $keys)) 65 $creator = "\"".$arguments["creator"]."\""; 64 66 if(in_array("questions", $keys)) 65 67 { … … 75 77 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 76 78 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 77 SELECT DISTINCT ?uid, ?title, ?description 79 SELECT DISTINCT ?uid, ?title, ?description, ?creator 78 80 WHERE 79 81 { … … 84 86 predicates:uid ' . $uid . ' 85 87 predicates:title ' . $title . ' 86 predicates:description ' . $description . ' 88 predicates:description ' . $description . ' 89 predicates:creator ' . $creator . ' 87 90 ' . $questions . ' 88 91 }'; … … 98 101 foreach($results as $result) 99 102 { 100 $questions = $this->getQuestions($result['?uid']->label); 101 $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $questions); 103 $questions = $this->getQuestions($result['?uid']->label); 104 $creator = $this->db->get("user", array("uid" => $result['?creator']->label)); 105 $surveys[] = new Survey($result['?uid']->label, $result['?title']->label, $result['?description']->label, $creator[0], $questions); 102 106 } 103 107 } … … 165 169 $this->model->add(new Statement($resourceSurvey,$predicateDescription,$surveyDescription)); 166 170 171 $predicateCreator = new Resource(CREATOR); 172 $surveyCreator = new Literal($rToolObject->creator->uid); 173 $this->model->add(new Statement($resourceSurvey, $predicateCreator, $surveyCreator)); 174 167 175 if(isset($rToolObject->questions)) 168 176 { -
Dev/trunk/classes/UserConnector.php
r131 r149 16 16 17 17 /** 18 * Constructor for ApplicationConnector.18 * Constructor for RespondentConnector. 19 19 */ 20 20 public function __construct() … … 50 50 * Gets the array of User objects belonging to arguments supplied. 51 51 * @param type $arguments : An array containing zero or more of the following keys: 52 * 'uid', 'name', 'password' , 'style'52 * 'uid', 'name', 'password' 53 53 */ 54 54 public function get($arguments) { … … 81 81 predicates:password ' . $password . ' 82 82 }'; 83 echo $querystring;84 83 //Query the model 85 84 $results = $this->model->sparqlQuery($querystring);
Note: See TracChangeset
for help on using the changeset viewer.