50,'ay'=>0,'bx'=>300,'by'=>250); $this->setExerciseData(array('cordiantes'=>$cord)); $this->setDiaType("selfmade"); $this->setMaxFouls(6); } else { // type specific data loading global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData(unserialize($typeData['data'])); $this->setDiaType($typeData['diatype']); $this->setMaxFouls($typeData['maxfouls']); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function setDiaType($d) { $this->diatype = $d; } public function getDiaType() { return $this->diatype; } protected function setMaxFouls($d) { $this->maxfouls = $d; } public function getMaxFouls() { return $this->maxfouls; } protected function setDialogue($d) { //$this->dialogue = $d; return 0; } public function getTypes() { return array('arst', 'ehitaja', 'giid', 'juuksur', 'kokk', 'myyja', 'pritsumees'); } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO dialogue (resourceID, data, diatype, maxfouls) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['diatype']."', '".$xml['maxfouls']."')"); if ($res) { $this->setExerciseData(unserialize($xml['data'])); $this->setUsedImages(); $_SESSION['krihvel_notice'] = "\"".gettext("Dialogue")."\" ".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 = 'getDiaType().']]>\n'; $xml .= 'getMaxFouls().']]>\n'; $xml .= 'getExerciseData()).']]>\n'; return $xml; } protected function collectCompileData($p) { $this->removeUsedImages(); $this->setDiaType($p['diatype']); $this->setMaxFouls($p['maxfouls']); if ($p['diatype']=='selfmade') { $dat = array(); for ($i=0; $i<6; $i++) { $dat []= array('a'=>$p['sma_'.$i], 'b'=>$p['smb_'.$i]); } $cor = array('ax'=>$p['ax'],'ay'=>$p['ay'],'bx'=>$p['bx'],'by'=>$p['by']); $this->useImage($p['dialogue_bg']); $dia_data = array('image'=> $p['dialogue_bg'], 'cordinates'=>$cor, 'data'=>$dat); $this->setExerciseData($dia_data); } } function setUsedImages() { $this->removeUsedImages(); $ed = $this->getExerciseData(); $imageUID = $ed['image']; if (substr($imageUID,0,5)=='image') { $this->useImage($imageUID); } } /** * @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 dialogue (resourceID, data, diatype, maxfouls) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."', '".$this->getDiaType()."', '".$this->getMaxFouls()."')"); if ($res) { $this->setUsedImages(); $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Dialogue")."\""; } 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 dialogue (resourceID, data, diatype, maxfouls) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."', '".$this->getDiaType()."', '".$this->getMaxFouls()."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->collectCompileData($_POST); $kdb->query("UPDATE dialogue SET diatype='".$this->getDiaType()."', maxfouls='".$this->getMaxFouls()."', data='".serialize($this->getExerciseData())."' 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 DialogueAnswer(); $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(); } } ?>