setType("SoundTesting"); $this->setName("Sound Testing"); $this->setTable("sound_stimulus"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"))); if ($id) { $data = $this->load($id); if ($data) { $this->setSound($data->sound); } } } function create() { if ($id = parent::create()) { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id) values (".$id.")"); if ($insert) { $this->setId($id); if ($this->getSound()) { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound=".$this->getSound()." WHERE base_id=".$this->getId()); } return $id; } } return false; } function save() { if (parent::save()) { if ($this->getSound()) { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound=".$this->getSound()." WHERE base_id=".$this->getId()); } else { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET sound=NULL WHERE base_id=".$this->getId()); } if ($upd) { 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 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); } if ($this->getId() > 0) { return $this->save(); } else { return $this->create(); } } 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 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); } } return $this->create(); } function getObjectsXML() { $xml = "getBodyImage()."]]>\n"; return $xml; } } ?>