setRows(8); $this->setCols(8); $this->setGameData($this->createGameData()); $this->setMessages(array()); $this->setTime(0); } else { global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setGameData(unserialize($typeData['data'])); $this->setRows($typeData['rows']); $this->setCols($typeData['cols']); $this->setMessages(unserialize($typeData['messages'])); $this->setTime($typeData['time']); } } protected function setGameData($d) { $this->gameData = $d; } public function getGameData() { return $this->gameData; } protected function setRows($d) { $this->rows = $d; } public function getRows() { return $this->rows; } protected function setCols($d) { $this->cols = $d; } public function getCols() { return $this->cols; } protected function setMessages($d) { $this->messages = $d; } public function getMessages() { return $this->messages; } protected function setTime($d) { $this->time = $d; } public function getTime() { return $this->time; } public function getActor() { return $this->actor; } public function getShowGameTime() { return true; } public function getNumberOfSQ(){ $nosq = 0; foreach ($this->getGameData() as $x) { foreach ($x as $y) { if ($y) { $nosq++; } } } return $nosq; } public function createGameData() { $gamedata = false; if ( !is_array($gamedata) ) { $gd = array(); for ($r=0; $r<=$this->getRows(); $r++) { $gda = array(); for ($c=0; $c<=$this->getCols(); $c++) { $gda []= 0; } $gd []= $gda; } return $gd; } if ( count($gamedata)<=$this->getRows() || count($gamedata[0])<=$this->getCols()) { for ($r=count($gamedata)-1; $r<$this->getRows(); $r++) { $gda = array(); for ($c=0; $c<=$this->getCols(); $c++) { $gda []= 0; } $gamedata []= $gda; } for ($r=0; $r<=$this->getRows(); $r++) { $gda = $gamedata[$r]; for ($c=count($gda)-1; $c<$this->getCols(); $c++) { $gda []= 0; } $gamedata[$r] = $gda; } return $gamedata; } return $this->gameData; } public function addCombolingElement($x, $y) { $gd = $this->getGameData(); if ( count($gd)>$x && count($gd[$x])>$y ) { $gd[$x][$y] = 1; $this->setGameData($gd); } } public function delCombolingElement($x, $y) { $gd = $this->getGameData(); if ( count($gd)>$x && count($gd[$x])>$y ) { $gd[$x][$y] = 0; $this->setGameData($gd); } } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO psyhvel_comboling (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $_SESSION['psyhvel_notice'] = "\"".gettext("Comboling")."\" ".gettext("has been imported successfully!"); } else { $_SESSION['psyhvel_notice'] = gettext("Upload failed! Zip file was corrupted!"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } public function makeXML() { $xml = 'getGameData().']]>\n'; return $xml; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['psyhvel_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 psyhvel_comboling (resourceID, data) values (".$this->getResourceID().", '".$this->getGameData()."')"); if ($res) { $_SESSION['psyhvel_notice'] = gettext("You have new copy of")." \"".gettext("Comboling")."\""; } else { $_SESSION['psyhvel_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 psyhvel_comboling (resourceID, data, messages) values (".$this->getResourceID().", '".serialize($this->getGameData())."', '".serialize($this->getMessages())."')"); } } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function actionSaveCompile() { $message= "Problem"; $ret = $this->kdb->query("UPDATE psyhvel_comboling SET data='".serialize($this->getGameData())."' WHERE resourceID=".$this->getResourceID()); if (!$ret) { return 1; } return 0; } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function actionCompile() { $saved = 0; $_SESSION['psyhvel_notice'] = gettext("Nothing to save"); if ( $_POST['rows'] && is_numeric($_POST['rows']) ) { $this->setRows($_POST['rows']); $saved++; } if ( $_POST['cols'] && is_numeric($_POST['cols']) ) { $this->setCols($_POST['cols']); $saved++; } if ( $saved>0 ) { $_SESSION['psyhvel_notice'] = gettext("Saved"); $ret = $this->kdb->query("UPDATE psyhvel_comboling SET rows=".$this->getRows().", cols=".$this->getCols()." WHERE resourceID=".$this->getResourceID()); if (!$ret) { $_SESSION['psyhvel_notice'] = gettext("Problem"); } } return array('rid' => $this->getResourceID(), 'mode' => 'compile'); } } ?>