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