setCategories($this->createArray()); $this->setLast(array('question'=>'', 'answer'=>'')); } else { // type specific data loading global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData($typeData['data']); $this->setCategories(unserialize($typeData['categories'])); $this->setLast(unserialize($typeData['last'])); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function setCategories($d) { $this->categories = $d; } public function getCategories() { //$this->setCategories($this->createArray()); return $this->categories; } protected function setLast($d) { $this->last = $d; } public function getLast() { return $this->last; } protected function createArray() { $arr = array(); $ar = array(); for ($j=0; $j<5; $j++) { $ar[$j] = array('points'=>'', 'question'=>'', 'answer'=>''); } for ($i=0; $i<15; $i++) { $arr[$i] = array('category'=>'', 'data'=>$ar); } return $arr; } protected function collectCompileData($p) { $cats = $this->getCategories(); for ($i=0;$i<15;$i++) { $cats[$i]['category']=$p['category_'.$i]; for ($j=0;$j<5;$j++) { $cats[$i]['data'][$j]['points']=$p['points_'.$i.'_'.$j]; $cats[$i]['data'][$j]['question']=$p['question_'.$i.'_'.$j]; $cats[$i]['data'][$j]['answer']=$p['answer_'.$i.'_'.$j]; } } $this->setCategories($cats); $this->setLast(array('question'=>$p['last_question'],'answer'=>$p['last_answer'])); } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO jeopardy (resourceID, data, categories, last) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['categories']."', '".$xml['last']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Jeopardy")."\" ".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 .= 'getCategories()).']]>\n'; $xml .= 'getLast()).']]>\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 jeopardy (resourceID, data, categories, last) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getCategories())."', '".serialize($this->getLast())."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Jeopardy")."\""; } 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 jeopardy (resourceID, data, categories, last) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getCategories())."', '".serialize($this->getLast())."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->collectCompileData($_POST); $kdb->query("UPDATE jeopardy SET categories='".serialize($this->getCategories())."', last='".serialize($this->getLast())."' WHERE resourceID=".$this->getResourceID()); $this->updateFulltext(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => "view"); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionAnswer() { global $user, $krihvel; //$aid = $this->answerData($_POST); $a = new JeopardyAnswer(); $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(); } } ?>