getTypeData($rid, self::$table); $this->setExerciseData(unserialize($typeData['data'])); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { if (!$this->exerciseData) { return $this->defaultTimeline(); } return $this->exerciseData; } protected function defaultTimeline() { $ipath = "plugins/timeline/images/"; return array( array('src'=>$ipath.'b1.jpg', 'question'=>'Borodino lahing', 'description'=>'Septembri alguses otsustas eakas Vene väejuht Mihhail Illarionovitš Kutuzov võtta vastu lahingu Borodino all, tugevdades looduslikult niigi head kaitsepositsiooni - künkad jõe ja metsa vahel - välikindlustustega.', 'value'=>'1812', 'level'=>'100'), array('src'=>$ipath.'w1.jpg', 'question'=>'Waterloo lahing', 'description'=>'Lahingukoht asub tänapäeva Belgias, 2 km kaugusel Waterloo linnast.', 'value'=>'1815', 'level'=>'200'), array('src'=>$ipath.'j1.gif', 'question'=>'Juulirevolutsioon', 'description'=>'Keskklassi ülestõus kuningas Charles X vastu', 'value'=>'1830', 'level'=>'300'), array('src'=>$ipath.'a1.jpg', 'question'=>'Austerlitzi lahing', 'description'=>'Peeti Austerlitzi linna juures Prantsuse ja Vene-Austria ühendvägede vahel.', 'value'=>'1805', 'level'=>'400'), //array('src'=>'', 'question'=>'', 'description'=>'', 'value'=>'', 'level'=>'500'), ); } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO timeline (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $this->setExerciseData(unserialize($xml['data'])); $this->setUsedImages(); $_SESSION['krihvel_notice'] = "\"".gettext("Timeline")."\" ".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; } function setUsedImages() { $this->removeUsedImages(); $ed = $this->getExerciseData(); foreach ($ed as $e) { $imageUID = substr($e['src'],15,22); 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 timeline (resourceID, data) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."')"); $this->setUsedImages(); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Timeline")."\""; } 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 timeline (resourceID, data) values (".$this->getResourceID().", '".serialize($this->getExerciseData())."')"); } } protected function collectCompileData($p) { $this->removeUsedImages(); $ed = $this->getExerciseData(); $cnt = 0; $dat = array(); foreach ($ed as $e) { $level = ($cnt+1)*100; $image = $p['image_'.$cnt]; if (substr($image,0,5)=='image') { $this->useImage($image); $image = 'images.php?iid='.$image.'&thumb=1'; } $nd = array('src'=>$image, 'question'=>$p['question_'.$cnt], 'description'=>$p['description_'.$cnt], 'value'=>$p['answer_'.$cnt], 'level'=>$level); $dat []= $nd; $cnt++; } $this->setExerciseData($dat); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->collectCompileData($_POST); $kdb->query("UPDATE timeline 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(); } } ?>