answer; } public function setAnswer($val) { $this->answer = $val; } public function getCorrect() { return $this->correct; } public function setCorrect($val) { $this->correct = $val; } public function getSelection() { return $this->selection; } public function setSelection($val) { $this->selection = $val; } public function getASelections() { $selections = array(); foreach (split("#", $this->getAnswer()) as $sel) { $selections []= split(":", $sel); } return $selections; } public function getAClicktions() { $clictions = array(); foreach (split("#", $this->getSelection()) as $cel) { $clicktions []= split(":", $cel); } return $clicktions; } public function getACorrect() { $corrects = split(",", $this->getCorrect()); return $corrects; } public function getPoints() { $ca = $this->getACorrect(); $max = count($ca); $pts = 0; foreach ($ca as $c) { if ($c=="correct") { $pts++; } } $percent = 0; if ($pts>0) { $percent = round(($pts/$max)*100); } return array('max'=>$max, 'pts'=>$pts, 'percent'=>$percent); } public function getResult() { $result = $this->getPoints(); return $result['pts']." punkti ".$result['max']."-st, ".$result['percent']."%"; } public function save() { global $kdb; $aid = $this->getAnswerID(); parent::save(); if ( $aid == null ) { $sql = "INSERT INTO ".$this->table." values(".$this->getAnswerID().", '".$this->getAnswer()."', '".$this->getCorrect()."', '".$this->getSelection()."')"; $kdb->query($sql); } else { // update answer } } } ?>