getTypeData($rid, self::$table); $this->setExerciseData($typeData['data']); $this->setQuestions(unserialize($typeData['questions'])); $this->setAnswers(unserialize($typeData['answers'])); } } protected function createArray() { return array('question'=>'', 'src'=>'', 'ic1'=>'', 'ic2'=>'', 'ic3'=>'', 'ca'=>''); } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function setQuestions($d) { $this->questions = $d; } public function getQuestions() { if (count($this->questions)<1) { $this->questions = array('100'=>$this->createArray(), '200'=>$this->createArray(), '300'=>$this->createArray(), '500'=>$this->createArray(), '1000'=>$this->createArray(), '2000'=>$this->createArray(), '4000'=>$this->createArray(), '8000'=>$this->createArray(), '16000'=>$this->createArray(), '32000'=>$this->createArray(), '64000'=>$this->createArray(), '125000'=>$this->createArray(), '250000'=>$this->createArray(), '500000'=>$this->createArray(), '1000000'=>$this->createArray() ); } return $this->questions; } protected function setAnswers($d) { $this->answers = $d; } public function getAnswers() { return $this->answers; } protected function updateCompiler($p) { $this->removeUsedImages(); $c = 0; $datar = $this->getQuestions(); foreach ($this->getQuestions() as $lvl => $data) { $datar[$lvl]['question'] = $p['q_'.$c]; $datar[$lvl]['src'] = $p['question_src_'.$c]; if (substr($p['question_src_'.$c],0,5)=='image') { $this->useImage($p['question_src_'.$c]); } $datar[$lvl]['ic1'] = $p['wa_1_'.$c]; $datar[$lvl]['ic2'] = $p['wa_2_'.$c]; $datar[$lvl]['ic3'] = $p['wa_3_'.$c]; $datar[$lvl]['ca'] = $p['ca_'.$c]; $c++; } $this->setQuestions($datar); } function setUsedImages() { $this->removeUsedImages(); $ed = $this->getQuestions(); foreach ($ed as $e) { $imageUID = $e['src']; if (substr($imageUID,0,5)=='image') { $this->useImage($imageUID); } } } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO millionaire (resourceID, data, questions, answers) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['questions']."', '".$xml['answers']."')"); if ($res) { $this->setQuestions(unserialize($xml['questions'])); $this->setUsedImages(); $_SESSION['krihvel_notice'] = "\"".gettext("Millionaire")."\" ".gettext("has been imported successfully!"); } else { $_SESSION['krihvel_notice'] = gettext("Upload failed! Zip file was corrupted!"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } public function makeXML() { $xml = 'getExerciseData().']]>\n'; $xml .= 'getQuestions()).']]>\n'; $xml .= 'getAnswers()).']]>\n'; return $xml; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCopy() { global $kdb; $this->updateData($_POST); $rid = $this->getResourceID(); parent::copy(); if ($this->getResourceID() != $rid){ $res = $kdb->query("INSERT INTO millionaire (resourceID, data, questions, answers) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getQuestions())."', '".serialize($this->getAnswers())."')"); if ($res) { $this->setUsedImages(); $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Millionaire")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => $mode); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new"){ $kdb->query("INSERT INTO millionaire (resourceID, data, questions, answers) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getQuestions())."', '".serialize($this->getAnswers())."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->updateCompiler($_POST); $kdb->query("UPDATE millionaire SET questions='".serialize($this->getQuestions())."', answers='".serialize($this->getAnswers())."' WHERE resourceID=".$this->getResourceID()); $this->updateFulltext(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => "settings"); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionAnswer() { global $user, $krihvel; //$aid = $this->answerData($_POST); $a = new MillionaireAnswer(); $a->setResourceID($this->getResourceID()); $a->setAssignmentID($_POST['assignment']); $a->setUserID($user->getId()); $a->setGrade(0); $a->setComment(""); $a->setExponate(0); $a->setAnswer($_POST['answer']); $a->save(); $_SESSION['krihvel_notice'] = gettext("Answered"); return array('rid' => $this->getResourceID(), 'mode' => "answer"); } function fulltext() { return $this->getExerciseData(); } } ?>