Changeset 171 for Dev/trunk/classes/AnswerConnector.php
- Timestamp:
- 12/02/11 15:26:01 (13 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.