setExerciseData(""); } else { // type specific data loading global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData($typeData['data']); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO paper (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Paper")."\" ".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 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); } /** * @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 paper (resourceID, data) values (".$this->getResourceID().", '".$this->getExerciseData()."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Paper")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new" || $this->getResourceID() != $rid){ $kdb->query("INSERT INTO paper (resourceID, data) values (".$this->getResourceID().", '".$this->getExerciseData()."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCompile() { global $kdb; $kdb->query("UPDATE paper SET data='".$_POST['exercise']."' 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 PaperAnswer(); $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(); } } ?>