Changeset 171
- Timestamp:
- 12/02/11 15:26:01 (13 years ago)
- Location:
- Dev/trunk/classes
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/AnswerConnector.php
r158 r171 10 10 * @author jkraaijeveld 11 11 */ 12 class AnswerConnector implements IConnector{ 13 protected $model; 14 protected $fileName = 'data/answers/answers.rdf'; 12 class AnswerConnector extends Connector{ 15 13 protected $db; 16 14 … … 21 19 //Ensure the required folder for this connector exists 22 20 if (!is_dir('data/answers/')) 23 mkdir('data/answers/'); 24 } 25 26 /** 27 * function load() 28 * Loads the file into the standard MemModel. 29 */ 30 public function load() { 31 //Get the Memory Model from the ModelFactory 32 $this->model = ModelFactory::getDefaultModel(); 33 34 //Ensure the required file exists before loading 35 if(file_exists($this->fileName)) 36 $this->model->load($this->fileName); 37 } 38 39 /** 40 * function save() 41 * Saves the MemModel into the given file. 42 */ 43 public function save() { 44 $this->model->saveAs($this->fileName,'rdf'); 21 mkdir('data/answers/'); 22 $this->fileName = 'data/answers/answers.rdf'; 45 23 } 46 24 … … 53 31 { 54 32 $this->load(); 55 $keys = array_keys($arguments);56 $uid = ""; $question = ""; $value = "";57 if(in_array("uid", $keys))58 $uid = 'predicates:uid \''.$arguments["uid"].'\'';59 if(in_array("question", $keys))60 $question = 'predicates:question_code \''.$arguments["question"].'\'';61 if(in_array("values", $keys))62 {63 foreach ($arguments["values"] as $val)64 {65 $value = $value . 'predicates:answered \'' . $val . '\' ';66 }67 }68 33 //Create the querystring 69 34 $querystring = ' … … 77 42 predicates:uid ?uid ; 78 43 predicates:question_code ?question_code ; 79 ' . $ uid . $question . $value. '44 ' . $this->createArguments($arguments) . ' 80 45 }'; 81 46 … … 89 54 foreach($results as $result) 90 55 { 91 $values = $this->getValues($result['?uid']->label); 92 $questionResult = $this->db->get("question", array("uid" => $result['?question_code']->label)); 93 $answers[] = new Answer($result['?uid']->label, $questionResult[0], $values); 56 $questionResult = $this->db->get("question", array("code" => $result['?question_code']->label)); 57 $answers[] = new Answer($result['?uid']->label, $questionResult[0], $this->getValues($result['?uid']->label)); 94 58 } 95 59 } 96 60 return $answers; 61 } 97 62 98 }99 63 /** 100 64 * function getValues() … … 103 67 private function getValues($uid) 104 68 { 105 $querystring = ' 106 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 107 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 108 SELECT DISTINCT ?answered 109 WHERE 110 { 111 _answer predicates:resource_type resources:answer ; 112 predicates:answered ?answered ; 113 predicates:uid \''. $uid . '\' 114 }'; 115 $values = $this->model->sparqlQuery($querystring); 116 $returnArray = array(); 117 if(!empty($values)) 69 $result = $this->model->findRegex("[(".$uid.")]", "[(answered)]", null); 70 $iterator = $result->getStatementIterator(); 71 $values = array(); 72 while($iterator->hasNext()) 118 73 { 119 foreach($values as $value) 120 { 121 $returnArray[] = $value['?answered']->label; 122 } 74 $element = $iterator->next(); 75 $values[] = $element->getLabelObject(); 123 76 } 124 return $ returnArray;77 return $values; 125 78 } 126 79 -
Dev/trunk/classes/AnswerSetConnector.php
r158 r171 6 6 * @author jkraaijeveld 7 7 */ 8 class AnswerSetConnector implements IConnector{ 9 protected $model; 10 protected $fileName = 'data/answers/answersets.rdf'; 8 class AnswerSetConnector extends Connector{ 11 9 protected $db; 12 10 … … 16 14 public function __construct() 17 15 { 16 $this->fileName = 'data/answers/answersets.rdf'; 18 17 //Ensure the required folder for this connector exists 19 18 if(!is_dir('data/answers')) 20 19 mkdir('data/answers'); 21 }22 23 /**24 * function load()25 * Loads the file into the standard MemModel26 */27 public function load()28 {29 //Get the Memory Model from the ModelFactory30 $this->model = ModelFactory::getDefaultModel();31 32 //Ensure the required file exists before loading33 if(file_exists($this->fileName))34 $this->model->load($this->fileName);35 }36 37 /**38 * function save()39 * Saves the MemModel into the given file.40 */41 public function save() {42 $this->model->saveAs($this->fileName,'rdf');43 20 } 44 21 … … 51 28 { 52 29 $this->load(); 53 54 $keys = array_keys($arguments);55 $uid = ""; $survey = ""; $respondent = ""; $answers = "";56 if(in_array("uid", $keys))57 $uid = 'predicates:uid \''.$arguments["uid"].'\' ';58 if(in_array("survey", $keys))59 $survey = 'predicates:for_survey \''.$arguments["survey"].'\' ';60 if(in_array("respondent", $keys))61 $respondent = 'predicates:by_respondent \''.$arguments["respondent"].'\' ';62 if(in_array("answers", $keys))63 {64 foreach ($arguments["answers"] as $answer)65 {66 $answers = $answers . 'predicates:given_answer \'' . $answer . '\' ';67 }68 }69 30 70 31 //Build the query string … … 79 40 predicates:for_survey ?for_survey ; 80 41 predicates:by_respondent ?by_respondent ; 81 ' . $ uid . $survey . $respondent . $answers. '42 ' . $this->createArguments($arguments) . ' 82 43 }'; 83 84 44 //Query the model 85 45 $results = $this->model->sparqlQuery($querystring); … … 105 65 private function getAnswers($uid) 106 66 { 107 $querystring = ' 108 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE .'> 109 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE .'> 110 SELECT DISTINCT ?given_answer 111 WHERE 112 { 113 _answerset predicates:resource_type resources:answerset ; 114 predicates:given_answer ?given_answer ; 115 predicates:uid \'' . $uid . '\' 116 }'; 117 $answers = $this->model->sparqlQuery($querystring); 118 $returnArray = array(); 119 if(!empty($answers)) 67 $result = $this->model->findRegex("[(".$uid.")]", "[(given_answer)]", null); 68 $iterator = $result->getStatementIterator(); 69 $answers = array(); 70 while($iterator->hasNext()) 120 71 { 121 foreach($answers as $answer) 122 { 123 $answerR = $this->db->get("answer", array("uid" => $answer["?given_answer"]->label)); 124 $returnArray[] = $answerR[0]; 125 } 72 $element = $iterator->next(); 73 $answersR = $this->db->get("answer", array("uid" => $element->getLabelObject())); 74 $answers[] = $answersR[0]; 126 75 } 127 return $ returnArray;76 return $answers; 128 77 } 129 78 -
Dev/trunk/classes/ApplicationConnector.php
r158 r171 11 11 * @author jkraaijeveld 12 12 */ 13 class ApplicationConnector implements IConnector{13 class ApplicationConnector extends Connector{ 14 14 15 protected $model;16 protected $fileName = 'data/applications/applications.rdf';17 18 15 /** 19 16 * Constructor for ApplicationConnector. … … 21 18 public function __construct() 22 19 { 20 $this->fileName = 'data/applications/applications.rdf'; 23 21 //Ensure the required folder for this connector exists 24 22 if (!is_dir('data/applications/')) 25 23 mkdir('data/applications/'); 26 }27 28 /**29 * function load()30 * Loads the file into the standard MemModel.31 */32 public function load() {33 //Get the Memory Model from the ModelFactory34 $this->model = ModelFactory::getDefaultModel();35 36 //Ensure the required file exists before loading37 if(file_exists($this->fileName))38 $this->model->load($this->fileName);39 }40 41 /**42 * function save()43 * Saves the MemModel into the given file.44 */45 public function save() {46 $this->model->saveAs($this->fileName,'rdf');47 24 } 48 25 … … 54 31 public function get($arguments) { 55 32 $this->load(); 56 //Determine which arguments are supplied57 $keys = array_keys($arguments);58 //Set default values for arguments59 $uid = ""; $title = ""; $description = ""; $style = "";60 //Set the arguments if they are supplied61 if(in_array("uid", $keys))62 $uid = "predicates:uid \"".$arguments["uid"]."\"";63 if(in_array("title", $keys))64 $title = 'predicates:title \''.$arguments["title"].'\'';65 if(in_array("description", $keys))66 $description = "predicates:description \"".$arguments["description"]."\"";67 if(in_array("style", $keys))68 $style = "predicates:style \"".$arguments["style"]."\"";69 33 70 34 //Create the querystring … … 80 44 predicates:description ?description ; 81 45 predicates:style ?style ; ' 82 . $ uid . $title . $description . $style. '46 . $this->createArguments($arguments) . ' 83 47 }'; 84 48 -
Dev/trunk/classes/QuestionConnector.php
r158 r171 12 12 * @author jkraaijeveld 13 13 */ 14 class QuestionConnector implements IConnector {14 class QuestionConnector extends Connector { 15 15 16 protected $model;17 protected $fileName = 'data/questions/questions.rdf';18 16 19 17 /** … … 22 20 public function __construct() 23 21 { 22 $this->fileName = 'data/questions/questions.rdf'; 24 23 //Ensure the required folder for this connector exists 25 24 if (!is_dir('data/questions/')) … … 28 27 29 28 /** 30 * function load()31 * Loads the file into the standard MemModel.32 */33 public function load() {34 //Get the Memory Model from the ModelFactory35 $this->model = ModelFactory::getDefaultModel();36 37 //Ensure the required file exists before loading38 if(file_exists($this->fileName))39 $this->model->load($this->fileName);40 }41 42 /**43 * function save()44 * Saves the MemModel into the given file.45 */46 public function save() {47 $this->model->saveAs($this->fileName,'rdf');48 }49 50 /**51 29 * Get the questions corresponding to the arguments. 52 30 * @param type $arguments : An array having one ore more of the following elements: 53 * ' uid', 'title', 'type', 'description', 'category', 'has_answer'.31 * 'code', 'title', 'type', 'description', 'category', 'definedanswers'. 54 32 */ 55 33 public function get($arguments) 56 34 { 57 35 $this->load(); 58 59 $keys = array_keys($arguments);60 //Set default values for arguments61 $uid = ""; $title = ""; $type = ""; $description = ""; $category = ""; $has_answer = "";62 //Set the arguments if they are supplied63 if(in_array("uid", $keys))64 $uid = 'predicates:question_code \''.$arguments["uid"].'\'';65 if(in_array("title", $keys))66 $title = 'predicates:title \''.$arguments["title"].'\'';67 if(in_array("type", $keys))68 $type = 'predicates:type \''.$arguments["type"].'\'';69 if(in_array("description", $keys))70 $description = "predicates:description \"".$arguments["description"]."\"";71 if(in_array("category", $keys))72 $style = "predicates:category \"".$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 }80 36 81 37 $querystring = ' … … 91 47 predicates:description ?description ; 92 48 predicates:question_category ?category ; 93 '. $uid . $title . $type . $description . $category . $has_answer . ' 94 }'; 49 '. $this->createArguments($arguments) . ' 50 }'; 51 52 95 53 //Create the querystring 96 54 $results = $this->model->sparqlQuery($querystring); … … 115 73 private function getAnswers($uid) 116 74 { 117 $querystring = ' 118 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 119 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 120 SELECT DISTINCT ?has_answer 121 WHERE 122 { 123 _question predicates:resource_type resources:question ; 124 predicates:has_answer ?has_answer ; 125 predicates:question_code \'' . $uid . '\' 126 }'; 75 $result = $this->model->findRegex("[(".$uid.")]", "[(has_answer)]", null); 76 $iterator = $result->getStatementIterator(); 77 $answers = array(); 78 while($iterator->hasNext()) 79 { 80 $element = $iterator->next(); 81 $answers[] = $element->getLabelObject(); 82 } 83 return $answers; 127 84 128 $answers = $this->model->sparqlQuery($querystring); 129 $returnArray = array(); 130 if(!empty($answers)) 131 { 132 foreach($answers as $answer) 133 { 134 $returnArray[] = $answer['?has_answer']->label; 135 } 136 } 137 return $returnArray; 138 } 139 85 } 140 86 141 87 /** -
Dev/trunk/classes/RespondentConnector.php
r158 r171 10 10 * @author jkraaijeveld 11 11 */ 12 class RespondentConnector implements IConnector{ 13 14 protected $fileName = 'data/users/respondents.rdf'; 12 class RespondentConnector extends Connector{ 15 13 16 14 /** … … 19 17 public function __construct() 20 18 { 19 $this->fileName = 'data/users/respondents.rdf'; 21 20 if (!is_dir('data/users/')) 22 21 mkdir('data/users/'); 23 }24 25 /**26 * function load()27 * Loads the file into the standard MemModel.28 */29 public function load() {30 //Get the Memory Model from the ModelFactory31 $this->model = ModelFactory::getDefaultModel();32 //Ensure the required file exists before loading33 if(file_exists($this->fileName))34 $this->model->load($this->fileName);35 }36 37 /**38 * function save()39 * Saves the MemModel into the given file.40 */41 public function save() {42 $this->model->saveAs($this->fileName,'rdf');43 22 } 44 23 … … 51 30 public function get($arguments) { 52 31 $this->load(); 53 //Determine which arguments are supplied54 $keys = array_keys($arguments);55 //Set default values for arguments56 $uid = ""; $name = ""; $password = "";57 //Set the arguments if they are supplied58 if(in_array("uid", $keys))59 $uid = "predicates:uid \"".$arguments["uid"]."\"";60 if(in_array("name", $keys))61 $name = 'predicates:name \''.$arguments["name"].'\'';62 if(in_array("password", $keys))63 $password = "predicates:password \"".$arguments["password"]."\"";64 32 65 33 //Create the querystring … … 74 42 predicates:name ?name ; 75 43 predicates:password ?password ; 76 ' . $ uid . $name . $password .'44 ' . $this->createArguments($arguments) . ' 77 45 }'; 78 46 //Query the model -
Dev/trunk/classes/Session.php
r170 r171 48 48 mkdir($location); 49 49 } 50 //Create the filename, open the file at the given location 50 51 $fileName = $this->datetime->format("d-m-Y") . "_" . $this->title . ".txt"; 51 52 -
Dev/trunk/classes/SessionConnector.php
r170 r171 10 10 * @author jkraaijeveld 11 11 */ 12 class SessionConnector implements IConnector12 class SessionConnector extends Connector 13 13 { 14 protected $model;15 protected $fileName = 'data/sessions/sessions.rdf';16 14 protected $db; 17 15 … … 21 19 public function __construct() 22 20 { 21 $this->fileName = 'data/sessions/sessions.rdf'; 23 22 //Ensure the required folder for this connector exists 24 23 if(!is_dir('data/sessions')) 25 24 mkdir('data/sessions'); 26 }27 28 /**29 * function load()30 * Loads the file into the standard MemModel31 */32 public function load()33 {34 $this->model = ModelFactory::getDefaultModel();35 if(file_exists($this->fileName))36 $this->model->load($this->fileName);37 }38 39 /**40 * fucntion save()41 * Saves the MemModel into the given file.42 */43 public function save()44 {45 $this->model->saveAs($this->fileName,'rdf');46 25 } 47 26 … … 54 33 { 55 34 $this->load(); 56 57 $keys = array_keys($arguments);58 $uid = ""; $title = ""; $creator = ""; $datetime = ""; $applications = ""; $surveys = ""; $answersets = "";59 if(in_array("uid", $keys))60 $uid = 'predicates:uid \''.$arguments["uid"].'\' ';61 if(in_array("title", $keys))62 $title = 'predicates:title \''.$arguments["title"].'\' ';63 if(in_array("creator", $keys))64 $creator = 'predicates:creator \''.$arguments["creator"].'\' ';65 if(in_array("datetime", $keys))66 $datetime = 'predicates:datetime \''.$arguments["datetime"].'\' ';67 if(in_array("applications", $keys))68 {69 foreach($arguments["applications"] as $application)70 {71 $applications = $applications . 'predicates:has_application \'' . $application . '\' ';72 }73 }74 if(in_array("surveys", $keys))75 {76 foreach($arguments["surveys"] as $survey)77 {78 $surveys = $surveys . 'predicates:has_survey \'' . $survey . '\' ';79 }80 }81 if(in_array("answersets", $keys))82 {83 foreach($arguments["answersets"] as $answerset)84 {85 $answersets = $answersets . 'predicates:has_answerset \'' . $answerset . '\' ';86 }87 }88 35 89 36 //Build the query string … … 99 46 predicates:creator ?creator ; 100 47 predicates:datetime ?datetime ; 101 ' . $ uid . $title . $creator . $datetime . $applications . $surveys . $answersets. '48 ' . $this->createArguments($arguments) . ' 102 49 }'; 50 echo $querystring; 103 51 //Query the model 104 52 $results = $this->model->sparqlQuery($querystring); -
Dev/trunk/classes/SurveyConnector.php
r158 r171 6 6 * @author jkraaijeveld 7 7 */ 8 class SurveyConnector implements IConnector{ 9 protected $model; 10 protected $fileName = 'data/surveys/surveys.rdf'; 8 class SurveyConnector extends Connector{ 11 9 protected $db; 12 10 … … 16 14 public function __construct() 17 15 { 16 $this->fileName = 'data/surveys/surveys.rdf'; 18 17 //Ensure the required folder for this connector exists 19 18 if (!is_dir('data/surveys/')) 20 19 mkdir('data/surveys/'); 21 }22 23 /**24 * function load()25 * Loads the file into the standard MemModel.26 */27 public function load() {28 //Get the Memory Model from the ModelFactory29 $this->model = ModelFactory::getDefaultModel();30 31 //Ensure the required file exists before loading32 if(file_exists($this->fileName))33 $this->model->load($this->fileName);34 }35 36 /**37 * function save()38 * Saves the MemModel into the given file.39 */40 public function save() {41 $this->model->saveAs($this->fileName,'rdf');42 20 } 43 21 … … 53 31 $this->load(); 54 32 55 $keys = array_keys($arguments);56 //Set default values for arguments57 $uid = ""; $title = ""; $description = ""; $creator = ""; $questions = "";58 if(in_array("uid", $keys))59 $uid = 'predicates:uid \''.$arguments["uid"].'\'';60 if(in_array("title", $keys))61 $title = 'predicates:title \''.$arguments["title"].'\'';62 if(in_array("description", $keys))63 $description = "predicates:description \"".$arguments["description"]."\"";64 if(in_array("creator", $keys))65 $creator = "predicates:creator \"".$arguments["creator"]."\"";66 if(in_array("questions", $keys))67 {68 //Append the questions string to filter for questions properly69 foreach ($arguments["questions"] as $questionUid)70 {71 $questions = $questions . 'predicates:has_question \'' . $questionUid . '\' ';72 }73 }74 75 33 //Build the query string 76 34 $querystring = ' … … 85 43 predicates:description ?description ; 86 44 predicates:creator ?creator ; 87 ' . $ uid . $title . $description . $creator . $questions. '45 ' . $this->createArguments($arguments) . ' 88 46 }'; 89 47 … … 112 70 private function getQuestions($uid) 113 71 { 114 //Create the querystring. Note that the UID is the only argument in this case. 115 $querystring = ' 116 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 117 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 118 SELECT DISTINCT ?has_question 119 WHERE 120 { 121 _survey predicates:resource_type resources:survey ; 122 predicates:has_question ?has_question ; 123 predicates:uid \'' . $uid . '\' 124 }'; 125 126 $results = $this->model->sparqlQuery($querystring); 127 $questions = array(); 128 //For every question id, get the corresponding question 129 if(!empty($results)) 130 { 131 foreach($results as $questionId) 132 { 133 $resultQ = $this->db->get("question", array("uid" => $questionId['?has_question']->label)); 134 $questions[] = $resultQ[0]; 135 } 136 } 137 return $questions; 72 $result = $this->model->findRegex("[(".$uid.")]", "[(has_question)]", null); 73 $iterator = $result->getStatementIterator(); 74 $questions = array(); 75 while($iterator->hasNext()) 76 { 77 $element = $iterator->next(); 78 $result = $this->db->get("question", array("code" => $element->getLabelObject())); 79 $questions[] = $result[0]; 80 } 81 return $questions; 138 82 } 139 83 -
Dev/trunk/classes/UserConnector.php
r158 r171 10 10 * @author jkraaijeveld 11 11 */ 12 class UserConnector implements IConnector{ 13 14 protected $model; 15 protected $fileName = 'data/users/users.rdf'; 12 class UserConnector extends Connector{ 16 13 17 14 /** 18 * Constructor for RespondentConnector.15 * Constructor for UserConnector. 19 16 */ 20 17 public function __construct() 21 18 { 19 $this->fileName = 'data/users/users.rdf'; 22 20 //Ensure the required folder for this connector exists 23 21 if (!is_dir('data/users/')) 24 22 mkdir('data/users/'); 25 }26 27 /**28 * function load()29 * Loads the file into the standard MemModel.30 */31 public function load() {32 //Get the Memory Model from the ModelFactory33 $this->model = ModelFactory::getDefaultModel();34 //Ensure the required file exists before loading35 if(file_exists($this->fileName))36 $this->model->load($this->fileName);37 }38 39 /**40 * function save()41 * Saves the MemModel into the given file.42 */43 public function save() {44 $this->model->saveAs($this->fileName,'rdf');45 23 } 46 24 … … 53 31 public function get($arguments) { 54 32 $this->load(); 55 //Determine which arguments are supplied56 $keys = array_keys($arguments);57 //Set default values for arguments58 $uid = ""; $name = ""; $password = "";59 //Set the arguments if they are supplied60 if(in_array("uid", $keys))61 $uid = "predicates:uid \"".$arguments["uid"]."\"";62 if(in_array("name", $keys))63 $name = 'predicates:name \''.$arguments["name"].'\'';64 if(in_array("password", $keys))65 $password = "predicates:password \"".$arguments["password"]."\"";66 67 33 //Create the querystring 68 34 $querystring = ' … … 76 42 predicates:name ?name ; 77 43 predicates:password ?password ; 78 ' . $ uid . $name . $password. '44 ' . $this->createArguments($arguments) . ' 79 45 }'; 80 46 //Query the model 81 47 $results = $this->model->sparqlQuery($querystring); 82 48 $users = array(); 83 49 if(!empty($results))
Note: See TracChangeset
for help on using the changeset viewer.