setExerciseData("");
$this->setTyps1("");
$this->setTyps2("");
$this->setObs1("");
$this->setObs2("");
$this->setGameRows(3);
} else {
// type specific data loading
global $kdb;
$typeData = $kdb->getTypeData($rid, self::$table);
$this->setExerciseData($typeData['data']);
$this->setTyps1($typeData['typs1']);
$this->setTyps2($typeData['typs2']);
$this->setObs1($typeData['obs1']);
$this->setObs2($typeData['obs2']);
$this->setGameRows($typeData['gamerows']);
}
}
protected function setExerciseData($d) {
$this->exerciseData = $d;
}
public function getExerciseData() {
return $this->exerciseData;
}
public function getTyps1() {
return $this->typs1;
}
public function getTypsA1() {
return split("#", $this->typs1);
}
protected function setTyps1($d) {
$this->typs1 = $d;
}
public function getObs1() {
return $this->obs1;
}
public function getObsA1() {
return split("#", $this->obs1);
}
protected function setObs1($d) {
$this->obs1 = $d;
}
public function getTyps2() {
return $this->typs2;
}
public function getTypsA2() {
return split("#", $this->typs2);
}
protected function setTyps2($d) {
$this->typs2 = $d;
}
public function getObs2() {
return $this->obs2;
}
public function getObsA2() {
return split("#", $this->obs2);
}
protected function setObs2($d) {
$this->obs2 = $d;
}
public function getGameRows() {
return $this->gamerows;
}
public function getPairCount() {
return count($this->getObsA1());
}
protected function setGameRows($d) {
$this->gamerows = $d;
}
public function makeResourceFromXML($xml) {
parent::makeResourceFromXML($xml);
if ($this->getResourceID()!="new"){
global $kdb;
$res = $kdb->query("INSERT INTO pairs (resourceID, data, obs1, obs2, typs1, typs2, gamerows) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['obs1']."', '".$xml['obs2']."', '".$xml['typs1']."', '".$xml['typs2']."', '".$xml['gamerows']."')");
if ($res) {
$this->setTyps1($xml['typs1']);
$this->setTyps2($xml['typs2']);
$this->setObs1($xml['obs1']);
$this->setObs2($xml['obs2']);
$this->setUsedImages();
$_SESSION['krihvel_notice'] = "\"".gettext("Pairs")."\" ".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 .= 'getObs1().']]>\n';
$xml .= 'getObs2().']]>\n';
$xml .= 'getTyps1().']]>\n';
$xml .= 'getTyps2().']]>\n';
$xml .= 'getGameRows().']]>\n';
return $xml;
}
function setUsedImages() {
$this->removeUsedImages();
$i = 0;
$o1 = $this->getObsA1();
$o2 = $this->getObsA2();
foreach ($this->getTypsA1() as $t1) {
if ($t1=="image") {
$this->useImage($o1[$i]);
}
$i++;
}
$i = 0;
foreach ($this->getTypsA2() as $t2) {
if ($t2=="image") {
$this->useImage($o2[$i]);
}
$i++;
}
}
/**
* @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 pairs (resourceID, data, obs1, obs2, typs1, typs2, gamerows) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".$this->getObs1()."', '".$this->getObs2()."', '".$this->getTyps1()."', '".$this->getTyps2()."', ".$this->getGameRows().")");
if ($res) {
$this->setUsedImages();
$_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Pairs")."\"";
} else {
$_SESSION['krihvel_notice'] = gettext("Making copy failed");
}
}
return array('rid' => $this->getResourceID(), 'mode' => 'view');
}
/**
* @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);
}
protected function save() {
global $kdb;
$rid = $this->getResourceID();
parent::save();
if ($rid == "new"){
$kdb->query("INSERT INTO pairs (resourceID, data) values (".$this->getResourceID().", '".$this->getExerciseData()."')");
}
}
/**
* @Secured('roles' = {'authenticated'}, 'valid' = {})
* */
public function actionCompile() {
global $kdb;
$this->setObs1($_POST['pics1_array']);
$this->setObs2($_POST['pics2_array']);
$this->setTyps1($_POST['types1_array']);
$this->setTyps2($_POST['types2_array']);
$this->setUsedImages();
$gameRows = $_POST['rows_in_game'];
$kdb->query("UPDATE pairs SET obs1='".$this->getObs1()."', obs2='".$this->getObs2()."', typs1='".$this->getTyps1()."', typs2='".$this->getTyps2()."', gamerows='".$gameRows."' 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 PairsAnswer();
$a->setResourceID($this->getResourceID());
$a->setAssignmentID($_POST['assignment']);
$a->setUserID($user->getId());
$a->setGrade(0);
$a->setComment("");
$a->setExponate(0);
$answer1 = array();
$answer2 = array();
$correct = array();
$place = array();
$uanswer = "";
$uselect = "";
//$items1 = split("#", $this->getObs1());
//$items2 = split("#", $this->getObs2());
$selection1 = split("#", $_POST['selected1_array']);
$selection2 = split("#", $_POST['selected2_array']);
for ($i=0; $i<$this->getGameRows(); $i++) {
$ax = $_POST['col_1_'.($i+1)];
$ay = $_POST['col_2_'.($i+1)];
$answer1[] = $ax;
$answer2[] = $ay;
$uanswer .= $selection1[$i].":".$selection2[$i]."#";
$uselect .= $ax.":".$ay."#";
}
$uanswer = substr_replace($uanswer ,"",-1);
$uselect = substr_replace($uselect ,"",-1);
for ($k=0; $k $an2) {
if ($selection1[$an1]==$selection2[$an2]) {
$correct []= 'correct';
} else {
$correct []= 'wrong';
}
}
$a->setAnswer($uanswer);
$a->setSelection($uselect);
$a->setCorrect(implode(",", $correct));
$a->save();
$_SESSION['krihvel_notice'] = gettext("Answered");
return array('rid' => $this->getResourceID(), 'mode' => "answer");
}
function fulltext() {
return $this->getExerciseData();
}
}
?>