setExerciseData(array('title'=>'', 'words'=>array())); } else { // type specific data loading global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData(unserialize($typeData['data'])); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function collectCompileData($p) { $data = $this->getExerciseData(); $rows = $p['word_data_count']; $data['title'] = $p['title']; $newData = array(); for ($i=0;$i<=$rows;$i++) { if ($p['w_'.$i]!="") { $nData = array(); $nData['word'] = $p['w_'.$i]; $nData['hint'] = $p['h_'.$i]; $nData['tries'] = $p['t_'.$i]; $newData []= $nData; } } $data['words'] = $newData; $this->setExerciseData($data); } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO hangman (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Hangman")."\" ".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'; 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 hangman (resourceID, data) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Hangman")."\""; } 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 hangman (resourceID, data) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->collectCompileData($_POST); $kdb->query("UPDATE hangman SET data='".serialize($this->getExerciseData())."' WHERE resourceID=".$this->getResourceID()); $this->updateFulltext(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => "settings"); } function fulltext() { return $this->getExerciseData(); } } ?>