setType("SoundStimulus"); $this->setName("Sound Stimulus"); $this->setTable("sound_stimulus"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"))); if ($id) { $data = $this->load($id); if ($data) { $this->setSound($data->sound); $this->setSoundAutoplay($data->sound_autoplay); } } } function create() { if ($id = parent::create()) { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, sound_autoplay) values (".$id.", ".$this->getSoundAutoplay().")"); if ($insert) { $this->setId($id); $this->save_sound(); return $id; } } return false; } function save() { if (parent::save()) { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound_autoplay=".$this->getSoundAutoplay()." WHERE base_id=".$this->getId()); if ($upd) { $this->save_sound(); return $this->getId(); } } return false; } function copy($locked=false) { $copy = $this->create(); if ($copy) { if ($locked) { $lock = $this->lock($copy); } if ($this->getSound()) { $sound = new Sound($this->getSound()); $this->load($copy); $this->setSound($sound->copy($locked)); } return $copy; } } function save_sound() { if ($this->getSound()) { return query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound=".$this->getSound()." WHERE base_id=".$this->getId()); } return query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound=NULL WHERE base_id=".$this->getId()); } function build($data) { if (parent::build($data)) { $sound_file = get_file("sound_file"); if (!isset($sound_file["error"]) || $sound_file["error"] == 0) { if ($this->getSound() > 0) { $sound = new Sound($this->getSound()); } else { $sound = new Sound(); } $sound_id = $sound->upload($sound_file); if ($sound_id) { $this->setSound($sound_id); } } else if (get_input("delete_sound", false)) { $sound = new Sound($this->getSound()); if ($sound->delete()) $this->setSound(NULL); } $this->setSoundAutoplay(0); if (isset($data["sound_autoplay"])) $this->setSoundAutoplay($data["sound_autoplay"]); if ($this->getId() > 0) { return $this->save(); } else { $this->setId($this->create()); return $this->save(); } } return false; } function delete() { if (is_admin() || $this->creator==get_logged_in_user()->getId()) { if (parent::delete()) { if ($this->getSound()) { $img = new Sound($this->getSound()); $img->delete(); } return true; } } return false; } function getSound() { return $this->sound; } function setSound($sound) { $this->sound = $sound; } function getListenSound() { $sound = new Sound($this->sound); return $sound->listen(); } function getSoundAutoplay() { return $this->sound_autoplay; } function setSoundAutoplay($sound_autoplay) { if ($sound_autoplay) { $this->sound_autoplay = 1; } else { $this->sound_autoplay = 0; } } function buildFromXML($obj, $folder=0, $dir, $version=1) { parent::buildFromXML($obj, $folder, $dir); $snd = $obj->file[0][0]; if ($snd) { $sound = new Sound(); $sound_id = $sound->save_from_dir($dir, $obj->file[0][0]); if ($sound_id > 0) { $this->setSound($sound_id); } } if (isset($obj->autoPlay[0][0]) && $obj->autoPlay[0][0] && $obj->autoPlay[0][0] != "False") { $this->setSoundAutoplay(1); } else { $this->setSoundAutoplay(0); } return $this->create(); } function getObjectsXML() { $xml = "getBodyImage()."]]>\n"; return $xml; } } ?>