setType("WordStimulus"); $this->setName("Word Stimulus"); $this->setTable("word_stimulus"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"), "compose"=>_("Compose"))); if ($id) { $data = $this->load($id); if ($data) { $this->setDisplayAll($data->display_all); $this->setTableHeight($data->table_height); $this->setTableWidth($data->table_width); $this->setTableHasBorder($data->table_has_border); } } } function create() { if ($id = parent::create()) { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, display_all, table_height, table_width, table_has_border) values (".$id.", ".$this->getDisplayAll().", ".$this->getTableHeight().", ".$this->getTableWidth().", ".$this->getTableHasBorder().")"); return $id; } return false; } function save() { if (parent::save()) { $bi = ""; if (query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET display_all=".$this->getDisplayAll().", table_height=".$this->getTableHeight().", table_width=".$this->getTableWidth().", table_has_border=".$this->getTableHasBorder()." WHERE base_id=".$this->getId())) return $this->getId(); } return false; } function copy($locked=false) { //muuda $copy = $this->create(); if ($copy){ if ($locked) { $lock = $this->lock($copy); } $choices = $this->getChoices(); foreach ($choices as $choice) { $choice->setParent($copy); if (!$choice->copy($locked)) return false; } return true; } return false; } function compose($data) { $nr = 0; foreach ($this->getChoices() as $choice) { $choice->setParent($this->getId()); $choice->build($nr, $data); $nr++; } return true; } function build($data) { if (parent::build($data)) { $this->setDisplayAll(0); if (isset($data["display_all"])) $this->setDisplayAll($data["display_all"]); if (isset($data["table_height"])) { if (is_numeric($data["table_height"])) { $this->setTableHeight($data["table_height"]); } else { $this->addBuildError(_("Table height")); } } if (isset($data["table_width"])) { if (is_numeric($data["table_width"])) { $this->setTableWidth($data["table_width"]); } else { $this->addBuildError(_("Table width")); } } $this->setTableHasBorder(0); if (isset($data["table_has_border"])) $this->setTableHasBorder($data["table_has_border"]); if ($this->getBuildError()) { global $TeKe; $TeKe->add_system_message(_("Problems with fields") . ": " . implode(",", $this->getBuildError()), 'error'); return false; } if ($this->getId() > 0) { return $this->save(); } else { return $this->create(); } } } function delete() { if (is_admin() || $this->getCreator()==get_logged_in_user()->getId()) { $choices = $this->getChoices(); if (parent::delete()) { foreach ($choices as $choice) { $choice->delete(); } return true; } } return false; } function getDisplayAll() { return $this->display_all; } function setDisplayAll($display_all) { if ($display_all) { $this->display_all = 1; } else { $this->display_all = 0; } } function getTableHeight() { return $this->table_height; } function setTableHeight($table_height) { $this->table_height = $table_height; } function getTableWidth() { return $this->table_width; } function setTableWidth($table_width) { $this->table_width = $table_width; } function getTableHasBorder() { return $this->table_has_border; } function setTableHasBorder($table_has_border) { if ($table_has_border) { $this->table_has_border = 1; } else { $this->table_has_border = 0; } } function getChoices() { $choices = array(); foreach(query_rows("SELECT id FROM " . DB_PREFIX . "choices WHERE parent=".$this->getId()) as $ch) { $choices []= new ChoiceObject($ch->id); } for ($i=count($choices); $i<($this->getTableHeight()*$this->getTableWidth()); $i++) { $choices []= new ChoiceObject(); } return $choices; } function buildFromXML($obj, $version=1) { var_dump($obj);exit; //parent::buildFromXML($obj); } } ?>