correct; } public function setCorrect($val) { $this->correct = $val; } public function getAnswer() { return $this->answer; } public function setAnswer($val) { $this->answer = $val; } public function getAnswerById($aid) { foreach (split(";", $this->getAnswer()) as $answer_element){ $a = split(":", $answer_element); if (is_array($a)){ if ($a[0]==$aid){ if ($a[1]==""){return "_";} return $a[1]; } } } return false; } public function getResult() { $score = 0; $tot = 0; foreach (unserialize($this->getCorrect()) as $correct_element) { if ($correct_element) { $score++; } $tot++; } $percent = round(100*$score/$tot); return $score." punkti ".$tot."-st, ".$percent."%"; } public function getCorrectById($cid) { $correct_elements = unserialize($this->getCorrect()); if (array_key_exists($cid, $correct_elements)){ return $correct_elements[$cid]; } return false; } public function save() { global $kdb; $aid = $this->getAnswerID(); parent::save(); if ( $aid == null ) { $sql = "INSERT INTO ".$this->table." (answerID, answer, correct) values(".$this->getAnswerID().", '".$this->getAnswer()."', '".$this->getCorrect()."')"; $kdb->query($sql); } else { // update answer } } } ?>