model = $factory->getDefaultModel(); $this->surveyUID = $surveyUID; $this->filePath = 'data/surveys/'; if (!is_dir($this->filePath)) mkdir($this->filePath); } public function saveSurvey() { $this->model->saveAs($this->filePath.'survey_'.$this->surveyUID.'.rdf','rdf'); } public function createSurvey($sTitle, $sDescription) { $this->resourceSurvey = new Resource(SURVEY.'/'.$this->surveyUID); $resourceSurveyType = new Resource(SURVEY); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($this->resourceSurvey,$predicateRType,$resourceSurveyType)); $literalSurveyID = new Literal($this->surveyUID); $predicateUniqueID = new Resource(UID); $this->model->add(new Statement($this->resourceSurvey,$predicateUniqueID,$literalSurveyID)); $predicateTitle = new Resource(TITLE); $surveyTitle = new Literal($sTitle); $this->model->add(new Statement($this->resourceSurvey,$predicateTitle,$surveyTitle)); $predicateDescription = new Resource(DESCRIPTION); $surveyDescription = new Literal($sDescription); $this->model->add(new Statement($this->resourceSurvey,$predicateDescription,$surveyDescription)); } public function setUserData($userID) { $resourceUser = new Resource(USER . '/' . $userID); $predicateCreator = new Resource(CREATOR); $this->model->add(new Statement($this->resourceSurvey,$predicateCreator,$resourceUser)); } public function addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers) { $questionID = $qID; $resourceQuestion = new Resource(QUESTION.'/'.$questionID); $resourceQuestionType = new Resource(QUESTION); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($resourceQuestion,$predicateRType,$resourceQuestionType)); $predicateUniqueID = new Resource(UID); $questionUID = new Literal($questionID); $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID)); $predicateTitle = new Resource(TITLE); $questionTitle = new Literal($qTitle); $this->model->add(new Statement($resourceQuestion,$predicateTitle,$questionTitle)); $predicateDescription = new Resource(DESCRIPTION); $questionDescription = new Literal($qDescription); $this->model->add(new Statement($resourceQuestion,$predicateDescription,$questionDescription)); $predicateQType = new Resource(QTYPE); $resourceQuestionType = new Literal($qType); $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType)); foreach($qAnswers as $answer) { $answerID = md5( uniqid(rand(), true) ); $resourceAnswer = new Resource(ANSWER.'/'.$answerID); $resourceAnswerType = new Resource(ANSWER); $predicateRType = new Resource(RTYPE); $this->model->add(new Statement($resourceAnswer,$predicateRType,$resourceAnswerType)); $predicateUniqueID = new Resource(UID); $answerUID = new Literal($answerID); $this->model->add(new Statement($resourceAnswer,$predicateUniqueID,$answerUID)); $answerTitle = new Literal($answer['Title']); $this->model->add(new Statement($resourceAnswer,$predicateTitle,$answerTitle)); $answerDescription = new Literal($answer['Description']); $this->model->add(new Statement($resourceAnswer,$predicateDescription,$answerDescription)); $predicateAnswer = new Resource(HAS_ANSWER); $this->model->add(new Statement($resourceQuestion,$predicateAnswer,$resourceAnswer)); } $predicateQuestion = new Resource(HAS_QUESTION); $this->model->add(new Statement($this->resourceSurvey,$predicateQuestion,$resourceQuestion)); } } ?>