Changeset 82
- Timestamp:
- 08/24/11 17:52:20 (14 years ago)
- Location:
- Dev/trunk
- Files:
-
- 4 added
- 1 deleted
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/SurveyCreationDatabaseInterface.php
r81 r82 12 12 protected $surveyRDFWriter; 13 13 protected $surveyRDFReader; 14 14 protected $questionRDFWriter; 15 protected $questionRDFReader; 15 16 16 17 public function __construct($surveyID) … … 23 24 $this->surveyRDFWriter = new SurveyRDFWriter($surveyUID); 24 25 $this->surveyRDFReader = new SurveyRDFReader($surveyUID); 26 $this->questionRDFWriter = new QuestionRDFWriter(); 27 $this->questionRDFReader = new QuestionRDFReader(); 25 28 } 26 29 27 public function setSurveyInfo($survey )30 public function setSurveyInfo($survey,$user) 28 31 { 29 32 $sTitle = $survey['surveyTitle']; … … 32 35 $this->surveyRDFWriter->createSurvey($sTitle,$sDescription); 33 36 34 $sUserID = "Creator";37 $sUserID = $user['username']; 35 38 36 39 $this->surveyRDFWriter->setUserData($sUserID); … … 59 62 } 60 63 61 $this->surveyRDFWriter->addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers); 64 if(!$this->checkQuestionIDExists($qID)) 65 { 66 $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers); 67 } 68 $this->surveyRDFWriter->addQuestion($qID); 62 69 63 70 $qNumber++; … … 65 72 66 73 $this->surveyRDFWriter->saveSurvey(); 74 $this->questionRDFWriter->saveQuestions(); 67 75 } 68 76 … … 71 79 $surveyInfo = array(); 72 80 81 $this->questionRDFReader->loadQuestions(); 82 73 83 $resultSurvey = $this->surveyRDFReader->getSurveyInfo(); 84 85 $surveyInfo['surveyID'] = $resultSurvey['info'][0]['?uid']->label; 86 $surveyInfo['surveyTitle'] = $resultSurvey['info'][0]['?title']->label; 87 $surveyInfo['surveyDescription'] = $resultSurvey['info'][0]['?description']->label; 88 $surveyInfo['surveyCreator'] = $resultSurvey['info'][0]['?creator']->label; 89 $surveyQuestionIDs = $resultSurvey['questionIDs']; 90 91 if($surveyQuestionIDs != false) 92 { 93 $qNumber = 1; 94 foreach($surveyQuestionIDs as $qID) 95 { 96 $questionID = $qID['?questionID']->label; 97 $surveyInfo['questionID'.$qNumber] = $questionID; 74 98 75 $surveyInfo['surveyID'] = substr($resultSurvey[0][0]['?uid'],9,strlen($resultSurvey[0][0]['?uid'])-11); 76 $surveyInfo['surveyTitle'] = substr($resultSurvey[0][0]['?title'],9,strlen($resultSurvey[0][0]['?title'])-11); 77 $surveyInfo['surveyDescription'] = substr($resultSurvey[0][0]['?description'],9,strlen($resultSurvey[0][0]['?description'])-11); 78 $surveyInfo['surveyCreator'] = substr($resultSurvey[0][0]['?creator'],9,strlen($resultSurvey[0][0]['?creator'])-11); 99 $questionTitleObject = $this->questionRDFReader->readQuestionTitle($questionID); 100 $surveyInfo['questionTitle'.$qNumber] = $questionTitleObject[0]['?questionTitle']->label; 79 101 80 for($qNumber = 1;$qNumber<=sizeof($resultSurvey[1][0]);$qNumber++) 81 { 82 $surveyInfo['questionID'.$qNumber] = substr($resultSurvey[1][3][$qNumber-1]['?questionID'],9,strlen($resultSurvey[1][3][$qNumber-1]['?questionID'])-11); 83 $surveyInfo['questionTitle'.$qNumber] = substr($resultSurvey[1][0][$qNumber-1]['?questionTitle'],9,strlen($resultSurvey[1][0][$qNumber-1]['?questionTitle'])-11); 84 $surveyInfo['questionDescription'.$qNumber] = substr($resultSurvey[1][1][$qNumber-1]['?questionDescription'],9,strlen($resultSurvey[1][1][$qNumber-1]['?questionDescription'])-11); 85 $surveyInfo['questionType'.$qNumber] = substr($resultSurvey[1][2][$qNumber-1]['?questionType'],9,strlen($resultSurvey[1][2][$qNumber-1]['?questionType'])-11); 102 $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($questionID); 103 $surveyInfo['questionDescription'.$qNumber] = $questionDescriptionObject[0]['?questionDescription']->label; 86 104 87 $resultAnswers = $this->surveyRDFReader->readSurveyAnswers($surveyInfo['questionID'.$qNumber]); 105 $questionTypeObject = $this->questionRDFReader->readQuestionType($questionID); 106 $surveyInfo['questionType'.$qNumber] = $questionTypeObject[0]['?questionType']->label; 88 107 89 if ($resultAnswers != null)90 { 91 for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++)108 $resultAnswers = $this->questionRDFReader->readQuestionAnswers($questionID); 109 110 if ($resultAnswers != null) 92 111 { 93 $surveyInfo['q'.$qNumber.'ans'.$aNumber] = substr($resultAnswers[$aNumber-1]['?answerDescription'],9,strlen($resultAnswers[$aNumber-1]['?answerDescription'])-11); 112 for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++) 113 { 114 $surveyInfo['q'.$qNumber.'ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label; 115 } 94 116 } 117 $resultAnswers = null; 118 $qNumber++; 95 119 } 96 120 } 97 121 98 122 return $surveyInfo; 99 123 } … … 111 135 } 112 136 } 113 137 114 138 foreach($surveyIDs as $surveyID) 115 139 { 116 140 $surveyTitle = $this->surveyRDFReader->getSurveyTitleByID($surveyID); 117 $surveys[$surveyID] = substr($surveyTitle[0]['?title'],9,strlen($surveyTitle[0]['?title'])-11);141 $surveys[$surveyID] = $surveyTitle[0]['?title']->label; 118 142 } 119 143 … … 124 148 { 125 149 $surveyTitleLiteral = $this->surveyRDFReader->getSurveyTitleByID($surveyID); 126 $surveyTitle = substr($surveyTitle[0]['?title'],9,strlen($surveyTitle[0]['?title'])-11);150 $surveyTitle = $surveyTitle[0]['?title']->label; 127 151 128 152 return $surveyTitle; 129 153 } 130 154 155 156 157 public function checkQuestionIDExists($qID) 158 { 159 $result = false; 160 161 $questionIDs = $this->questionRDFReader->readQuestionIDs(); 162 163 if ($questionIDs != null) 164 { 165 foreach($questionIDs as $questionID) 166 { 167 $id = $questionID['?questionID']->label; 168 if(!strcmp($id ,$qID)) 169 { 170 $result = true; 171 break; 172 } 173 } 174 } 175 176 return $result; 177 } 131 178 } 132 179 ?> -
Dev/trunk/classes/SurveyRDFReader.php
r78 r82 25 25 public function getSurveyInfo() 26 26 { 27 SurveyRDFReader::loadSurvey();27 $this->loadSurvey(); 28 28 29 29 $result = array(); 30 $result[ ] = $this->readSurveyInfo();31 $result[ ] = $this->readSurveyQuestions();30 $result['info'] = $this->readSurveyInfo(); 31 $result['questionIDs'] = $this->readSurveyQuestionIDs(); 32 32 33 33 return $result; … … 53 53 return $result; 54 54 } 55 56 public function readSurveyQuestions() 57 { 58 $result = array(); 59 $result[] = $this->readSurveyQuestionsTitle(); 60 $result[] = $this->readSurveyQuestionsDescription(); 61 $result[] = $this->readSurveyQuestionsType(); 62 $result[] = $this->readSurveyQuestionsID(); 63 64 return $result; 65 } 66 67 public function readSurveyQuestionsTitle() 68 { 69 $querystring = ' 70 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 71 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 72 SELECT ?questionTitle 73 WHERE 74 { 75 _question predicates:resource_type resources:question ; 76 predicates:title ?questionTitle 77 }'; 78 79 $result = $this->model->sparqlQuery($querystring); 80 81 return $result; 82 } 83 84 public function readSurveyQuestionsDescription() 85 { 86 $querystring = ' 87 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 88 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 89 SELECT ?questionDescription 90 WHERE 91 { 92 _question predicates:resource_type resources:question ; 93 predicates:description ?questionDescription 94 }'; 95 96 $result = $this->model->sparqlQuery($querystring); 97 98 return $result; 99 } 100 101 public function readSurveyQuestionsType() 102 { 103 $querystring = ' 104 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 105 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 106 SELECT ?questionType 107 WHERE 108 { 109 _question predicates:resource_type resources:question ; 110 predicates:question_type ?questionType 111 }'; 112 113 $result = $this->model->sparqlQuery($querystring); 114 115 return $result; 116 } 117 118 public function readSurveyQuestionsID() 55 56 public function readSurveyQuestionIDs() 119 57 { 120 58 $querystring = ' … … 124 62 WHERE 125 63 { 126 _question predicates:resource_type resources:question ; 127 predicates:uid ?questionID 128 }'; 129 130 $result = $this->model->sparqlQuery($querystring); 131 132 return $result; 133 } 134 135 public function readSurveyAnswers($questionID) 136 { 137 $querystring = ' 138 PREFIX predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '> 139 PREFIX resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '> 140 SELECT ?answerDescription 141 WHERE 142 { 143 _question predicates:resource_type resources:question ; 144 predicates:uid "' . $questionID . '" ; 145 predicates:has_answer _answer . 146 _answer predicates:description ?answerDescription 64 _survey predicates:resource_type resources:survey ; 65 predicates:has_question ?questionID 147 66 }'; 148 67 -
Dev/trunk/classes/SurveyRDFWriter.php
r62 r82 48 48 } 49 49 50 public function setUserData($u serID)50 public function setUserData($uID) 51 51 { 52 $ resourceUser = new Resource(USER . '/' . $userID);52 $userID = new Literal($uID); 53 53 54 54 $predicateCreator = new Resource(CREATOR); 55 $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$ resourceUser));55 $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$userID)); 56 56 } 57 57 58 public function addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers) 59 { 60 $questionID = $qID; 61 $resourceQuestion = new Resource(QUESTION.'/'.$questionID); 62 63 $resourceQuestionType = new Resource(QUESTION); 64 $predicateRType = new Resource(RTYPE); 65 $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType)); 66 67 $predicateUniqueID = new Resource(UID); 68 $questionUID = new Literal($questionID); 69 $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID)); 70 71 $predicateTitle = new Resource(TITLE); 72 $questionTitle = new Literal($qTitle); 73 $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle)); 74 75 $predicateDescription = new Resource(DESCRIPTION); 76 $questionDescription = new Literal($qDescription); 77 $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription)); 78 79 $predicateQType = new Resource(QTYPE); 80 $resourceQuestionType = new Literal($qType); 81 $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType)); 82 83 foreach($qAnswers as $answer) 84 { 85 $answerID = md5( uniqid(rand(), true) ); 86 $resourceAnswer = new Resource(ANSWER.'/'.$answerID); 87 88 $resourceAnswerType = new Resource(ANSWER); 89 $predicateRType = new Resource(RTYPE); 90 $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); 91 92 $predicateUniqueID = new Resource(UID); 93 $answerUID = new Literal($answerID); 94 $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID)); 95 96 $answerTitle = new Literal($answer['Title']); 97 $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle)); 98 99 $answerDescription = new Literal($answer['Description']); 100 $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription)); 101 102 $predicateAnswer = new Resource(HAS_ANSWER); 103 $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer)); 104 } 105 106 $predicateQuestion = new Resource(HAS_QUESTION); 107 $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion)); 108 } 58 public function addQuestion($qID) 59 { 60 $questionID = new Literal($qID); 61 $predicateQuestion = new Resource(HAS_QUESTION); 62 $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$questionID)); 63 } 109 64 } 110 65 -
Dev/trunk/classes/UserDatabaseInterface.php
r62 r82 25 25 $userPassword = $this->RIJNDAEL_encrypt($userInfo['password']); 26 26 27 $this->userRDFWriter->addNewUser($userName, $userPassword); 28 $this->userRDFWriter->saveUsers(); 27 if($this->checkUserName($userName)) 28 { 29 $this->userRDFWriter->addNewUser($userName, $userPassword); 30 $this->userRDFWriter->saveUsers(); 31 } 29 32 } 30 33 … … 39 42 foreach($resultUser as $user) 40 43 { 41 $name = substr($user['?name'],9,strlen($user['?name'])-11);44 $name = $user['?name']->label; 42 45 if(!strcmp($name ,$userName)) 43 46 { … … 58 61 59 62 $encryptedPasswordLiteral = $this->userRDFReader->getUserPassword($userName); 60 $encryptedPassword = substr($encryptedPasswordLiteral[0]['?password'],9,strlen($encryptedPasswordLiteral[0]['?password'])-11);63 $encryptedPassword = $encryptedPasswordLiteral[0]['?password']->label; 61 64 62 65 if(!strcmp($this->RIJNDAEL_encrypt($userPassword),$encryptedPassword)) -
Dev/trunk/data/users/users.rdf
r78 r82 4 4 5 5 <rdf:RDF 6 xml:base="data/users/users.rdf#" 6 7 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 7 8 xmlns:ns1="http://www.survey.tool/predicates/"> … … 14 15 </rdf:Description> 15 16 17 <rdf:Description rdf:about="http://www.survey.tool/resources/user/e93dda3924206c6fd2e4a52a2999415a"> 18 <ns1:resource_type rdf:resource="http://www.survey.tool/resources/user"/> 19 <ns1:name>Igor</ns1:name> 20 <ns1:uid>e93dda3924206c6fd2e4a52a2999415a</ns1:uid> 21 <ns1:password>AHNpYa+Ft7ZrC5KpRisJTJkhIqCANtF46xizdXF4ecQ=</ns1:password> 22 </rdf:Description> 23 16 24 </rdf:RDF> -
Dev/trunk/mainmenu.php
r78 r82 2 2 require 'classes/master.php'; //should be at top of every page 3 3 4 var_dump($_POST);5 4 if (isset($_POST['login'])) { 6 5 if ($_POST['username'] == '') -
Dev/trunk/rdfConstants.php
r78 r82 5 5 6 6 // Default namespace for survey tool 7 define('SURVEYTOOL_NAMESPACE','http:// www.survey.tool/');7 define('SURVEYTOOL_NAMESPACE','http://tbm.tudelft.nl/researchtool/'); 8 8 define('SURVEYTOOL_RESOURCES_NAMESPACE',SURVEYTOOL_NAMESPACE . 'resources/'); 9 9 define('SURVEYTOOL_PREDICATES_NAMESPACE',SURVEYTOOL_NAMESPACE . 'predicates/'); … … 29 29 define('RTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'resource_type'); 30 30 define('QTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_type'); 31 define('QCODE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_code'); 32 define('QCATEGORY',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_category'); 31 33 define('HAS_QUESTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_question'); 32 34 define('HAS_ANSWER',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_answer'); -
Dev/trunk/surveycreation.php
r80 r82 26 26 // echo '<br/><br/>'; 27 27 $surveyDBI = new SurveyDatabaseInterface($_POST['surveyID']); 28 $surveyDBI->setSurveyInfo($_POST );28 $surveyDBI->setSurveyInfo($_POST,$_SESSION); 29 29 $info = $surveyDBI->getSurveyInfo(); 30 30 // echo '<br/><br/>';
Note: See TracChangeset
for help on using the changeset viewer.