setExerciseData("");
$this->setImages(array("plugins/memory/images/hiir.jpg","plugins/memory/images/kass.jpg","plugins/memory/images/koer.jpg","plugins/memory/images/lehm.jpg","plugins/memory/images/hobune.jpg","plugins/memory/images/kana.jpg","plugins/memory/images/lind.jpg","plugins/memory/images/madu.jpg"));
$this->setImagesA(array("HIIR","KASS","KOER","LEHM","HOBUNE","KANA","LIND","MADU"));
$this->setImagesB(array("MOUSE","CAT","DOG","COW","HORSE","CHICKEN","BIRD","SNAKE"));
$this->setGameLevel(1);
} else {
// type specific data loading
global $kdb;
$typeData = $kdb->getTypeData($rid, self::$table);
$this->setExerciseData($typeData['data']);
$this->setImages(unserialize($typeData['images']));
$this->setImagesA(unserialize($typeData['imagesa']));
$this->setImagesB(unserialize($typeData['imagesb']));
$this->setGameLevel($typeData['level']);
}
}
protected function setExerciseData($d) {
$this->exerciseData = $d;
}
public function getExerciseData() {
return $this->exerciseData;
}
protected function setImages($d) {
$this->images = $d;
}
public function getImages() {
return $this->images;
}
protected function setImagesA($d) {
$this->imagesA = $d;
}
public function getImagesA() {
return $this->imagesA;
}
protected function setImagesB($d) {
$this->imagesB = $d;
}
public function getImagesB() {
return $this->imagesB;
}
protected function setGameLevel($d) {
$this->gameLevel = $d;
}
public function getGameLevel() {
return $this->gameLevel;
}
public function getLevels() {
return array('very slow', 'slow', 'normal', 'fast', 'very fast');
}
protected function collectCompileData($p) {
$is = array();
$ia = array();
$ib = array();
for ($i=0; $i<8; $i++) {
$is []= $p['imgs'.$i];
$ia []= $p['imgs1'.$i];
$ib []= $p['imgs2'.$i];
}
$this->setImages($is);
$this->setImagesA($ia);
$this->setImagesB($ib);
$this->setGameLevel($p['level']);
}
public function makeResourceFromXML($xml) {
parent::makeResourceFromXML($xml);
if ($this->getResourceID()!="new"){
global $kdb;
$res = $kdb->query("INSERT INTO memory (resourceID, data, images, imagesa, imagesb) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['images']."', '".$xml['imagesa']."', '".$xml['imagesb']."')");
if ($res) {
$_SESSION['krihvel_notice'] = "\"".gettext("Memory")."\" ".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 .= 'getImages()).']]>\n';
$xml .= 'getImagesA()).']]>\n';
$xml .= 'getImagesB()).']]>\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 memory (resourceID, data, images, imagesa, imagesb) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getImages())."', '".serialize($this->getImagesA())."', '".serialize($this->getImagesB())."')");
if ($res) {
$_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Memory")."\"";
} 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 memory (resourceID, data, images, imagesa, imagesb) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".serialize($this->getImages())."', '".serialize($this->getImagesA())."', '".serialize($this->getImagesB())."')");
}
}
/**
* @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'})
* */
public function actionCompile() {
global $kdb;
$this->collectCompileData($_POST);
$kdb->query("UPDATE memory SET images='".serialize($this->getImages())."', imagesa='".serialize($this->getImagesA())."', imagesb='".serialize($this->getImagesB())."', level=".$this->getGameLevel()." 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 MemoryAnswer();
$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();
}
}
?>