setType("DragTask"); $this->setName("Drag Task"); $this->setTable("drag_task"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"), "compose"=>_("Compose"))); if ($id) { $data = $this->load($id); if ($data) { $this->setBodyImage($data->body_image); $this->setElements($data->elements); } } } function create() { if ($id = parent::create()) { $bi1 = ""; $bi2 = ""; if ($this->getBodyImage()) { $bi1 = "body_image, "; $bi2 = "'".$this->getBodyImage()."', "; } $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, ".$bi1."elements) values (".$id.", ".$bi2."'".mysql_real_escape_string($this->getElements())."')"); return $id; } return false; } function save() { if (parent::save()) { $bi = ""; if ($this->getBodyImage()) $bi = "body_image='".$this->getBodyImage()."',"; $update = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET ".$bi."elements='".mysql_real_escape_string($this->getElements())."' WHERE base_id=".$this->getId()); if ($update) return $this->getId(); } return false; } function copy($locked=false) { if ($this->getBodyImage()) { $image = new Image($this->getBodyImage()); $this->setBodyImage($image->copy($locked)); } $copy = $this->create(); if ($copy && $locked) { $lock = $this->lock($copy); } return $copy; } function compose($data) { if (isset($data["drag_elements"]) && !empty($data["drag_elements"])) { $this->setElements($data["drag_elements"]); if ($this->getId() > 0) { $this->save(); return true; } } return false; } function delete() { if (is_admin() || $this->getCreator()==get_logged_in_user()->getId()) { if (parent::delete()) { if ($this->getBodyImage()) { $img = new Image($this->getBodyImage()); $img->delete(); } return true; } } return false; } function answer($data) { $examinee = get_examinee()->getId(); //$total = $data['answer_hedgehogmoves_total']; //$empty = $data['answer_hedgehogmoves_empty']; //$hill = $data['answer_hedgehogmoves_hill']; //$river = $data['answer_hedgehogmoves_river']; //$answer = $data['answer_hedgehogmoves_count']; //$moves = $data['answer_hedgehogmoves_array']; //$start = $data['answer_hedgehogmoves_start']; //$end = $data['answer_hedgehogmoves_end']; //$insert = query_insert("INSERT INTO " . DB_PREFIX . "hedgehog_answer (base_id, examinee, total, empty, hill, river, answer, moves, start, end) VALUES (". $this->getId() .", ". $examinee .", ". $total .", ". $empty .", ". $hill .", ". $river .", ". $answer .", '". $moves ."', ".$start.", ".$end.")"); return true; } function collect($examinees) { /*$start = "start_time"; $end = "end_time"; $total = "total"; $empty = "empty"; $hill = "hill"; $river = "river"; $answert = "answer"; $moves = "moves"; $answers = array(); $answers['title'][$start] = _("Start time"); $answers['title'][$end] = _("End time"); $answers['title'][$total] = _("Total"); $answers['title'][$empty] = _("Empty"); $answers['title'][$hill] = _("Hill"); $answers['title'][$river] = _("River"); $answers['title'][$answert] = _("Answer"); $answers['title'][$moves] = _("Moves"); foreach ($examinees as $examinee) { $answer = query_row("SELECT * FROM " . DB_PREFIX . "hedgehog_task t LEFT JOIN " . DB_PREFIX . "hedgehog_answer a ON t.base_id=a.base_id WHERE t.base_id=".$this->getId()." AND a.examinee=".$examinee); if ($answer) { $answers[$examinee][$start] = round($answer->start/1000, 1); $answers[$examinee][$end] = round($answer->end/1000, 1); $answers[$examinee][$total] = $answer->total; $answers[$examinee][$empty] = $answer->empty; $answers[$examinee][$hill] = $answer->hill; $answers[$examinee][$river] = $answer->river; $answers[$examinee][$answert] = $answer->answer; $answers[$examinee][$moves] = $answer->moves; } else { $answers[$examinee][$start] = "-"; $answers[$examinee][$end] = "-"; $answers[$examinee][$total] = "-"; $answers[$examinee][$empty] = "-"; $answers[$examinee][$hill] = "-"; $answers[$examinee][$river] = "-"; $answers[$examinee][$answert] = "-"; $answers[$examinee][$moves] = "-"; } } $id = "hedgehogtask_".$this->getId(); $title = _("None")." ".$this->getId(); if ($this->getTitle()) $title = $this->getTitle(); return array('id'=>$id, 'title'=>$title, 'answers'=>$answers); */ } function getElements() { return $this->elements; } function setElements($elements) { $this->elements = $elements; } function getBodyImage() { return $this->body_image; } function setBodyImage($body_image) { $this->body_image = $body_image; } function build($data) { if (parent::build($data)) { $body_image = get_file("body_image"); if (!isset($body_image["error"]) || $body_image["error"] == 0) { if ($this->getBodyImage() > 0) { $image = new Image($this->getBodyImage()); } else { $image = new Image(); } $image_id = $image->upload($body_image); if ($image_id) { $this->setBodyImage($image_id); } } else if (get_input("delete_body_image", false)) { $image = new Image($this->getBodyImage()); if ($image->delete()) $this->setBodyImage(NULL); } 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 buildFromXML($obj, $version=1, $folder=0) { var_dump($obj);exit; //parent::buildFromXML($obj); } } ?>