setType("ImageDragTask"); $this->setName("Image Drag Task"); $this->setTable("image_drag_task"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"), "compose"=>_("Compose"))); if ($id) { $data = $this->load($id); if ($data) { $this->setDragImage1($data->drag_image_1); $this->setDragImage2($data->drag_image_2); $this->setDragImage3($data->drag_image_3); $this->setDragImage4($data->drag_image_4); $this->setDragImage5($data->drag_image_5); $this->setDragImage6($data->drag_image_6); $this->setElementSize($data->element_size); $this->setElements(json_decode($data->elements)); $this->setTextTitle($data->text_title); $this->setTextInput($data->text_input); $this->setTextValue($data->text_value); $this->setTextCols($data->text_cols); $this->setTextRows($data->text_rows); $this->setTextCharcount($data->text_charcount); $this->setTextCharcounter($data->text_charcounter); $this->setAnswerRequired($data->answer_required); } } } function create() { if ($id = parent::create()) { $bi1 = ""; $bi2 = ""; if ($this->getDragImage1()) { $bi1 .= "drag_image_1, "; $bi2 .= "'".$this->getDragImage1()."', "; } if ($this->getDragImage2()) { $bi1 .= "drag_image_2, "; $bi2 .= "'".$this->getDragImage2()."', "; } if ($this->getDragImage3()) { $bi1 .= "drag_image_3, "; $bi2 .= "'".$this->getDragImage3()."', "; } if ($this->getDragImage4()) { $bi1 .= "drag_image_4, "; $bi2 .= "'".$this->getDragImage4()."', "; } if ($this->getDragImage5()) { $bi1 .= "drag_image_5, "; $bi2 .= "'".$this->getDragImage5()."', "; } if ($this->getDragImage6()) { $bi1 .= "drag_image_6, "; $bi2 .= "'".$this->getDragImage6()."', "; } if (!$this->getElements()){ $this->initializeComposer(); } $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (". "base_id, ".$bi1. "elements, ". "element_size, ". "answer_required, ". "text_title, ". "text_input, ". "text_value, ". "text_cols, ". "text_rows, ". "text_charcount, ". "text_charcounter". ") values (".$id.", ".$bi2."'". mysql_real_escape_string($this->getElementsJson())."', ". $this->getElementSize().", ". $this->getAnswerRequired().", '". mysql_real_escape_string($this->text_title)."', ". $this->text_input.", '". mysql_real_escape_string($this->text_value)."', ". $this->text_cols.", ".$this->text_rows.", ". $this->text_charcount.", ". $this->text_charcounter.")"); return $id; } return false; } function save() { if (parent::save()) { $bi = ""; if ($this->getDragImage1()) $bi .= "drag_image_1='".$this->getDragImage1()."',"; if ($this->getDragImage2()) $bi .= "drag_image_2='".$this->getDragImage2()."',"; if ($this->getDragImage3()) $bi .= "drag_image_3='".$this->getDragImage3()."',"; if ($this->getDragImage4()) $bi .= "drag_image_4='".$this->getDragImage4()."',"; if ($this->getDragImage5()) $bi .= "drag_image_5='".$this->getDragImage5()."',"; if ($this->getDragImage6()) $bi .= "drag_image_6='".$this->getDragImage6()."',"; $update = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET ".$bi. "elements='".mysql_real_escape_string($this->getElementsJson())."', ". "element_size=".$this->getElementSize().", ". "answer_required=".$this->getAnswerRequired().", ". "text_title='".mysql_real_escape_string($this->text_title)."', ". "text_input =".$this->text_input.", ". "text_value='".mysql_real_escape_string($this->text_value)."', ". "text_cols=".$this->text_cols.", ". "text_rows=".$this->text_rows.", ". "text_charcount=".$this->text_charcount.", ". "text_charcounter=".$this->text_charcounter." ". "WHERE base_id=".$this->getId()); if ($update) return $this->getId(); } return false; } function copy($locked=false) { if ($this->getDragImage1()) { $image = new Image($this->getDragImage1()); $this->setDragImage1($image->copy($locked)); } if ($this->getDragImage2()) { $image = new Image($this->getDragImage2()); $this->setDragImage2($image->copy($locked)); } if ($this->getDragImage3()) { $image = new Image($this->getDragImage3()); $this->setDragImage3($image->copy($locked)); } if ($this->getDragImage4()) { $image = new Image($this->getDragImage4()); $this->setDragImage4($image->copy($locked)); } if ($this->getDragImage5()) { $image = new Image($this->getDragImage5()); $this->setDragImage5($image->copy($locked)); } if ($this->getDragImage6()) { $image = new Image($this->getDragImage6()); $this->setDragImage6($image->copy($locked)); } $copy = $this->create(); if ($copy && $locked) { $lock = $this->lock($copy); } return $copy; } function initializeComposer() { $element_array = Array(); for ($i=0; $i<6; $i++) { $element_array[$i]->nr = $i+1; $element_array[$i]->drag_active = false; $element_array[$i]->drag_show_title = false; $element_array[$i]->drag_title = ""; $element_array[$i]->drag_image = null; $element_array[$i]->drop_active = false; $element_array[$i]->drop_show_title = false; $element_array[$i]->drop_title = ""; $element_array[$i]->drop_correct = 0; } $this->setElements($element_array); } function compose($data) { $this->initializeComposer(); $element_array = $this->getElements(); for ($i=0; $i<6; $i++) { if (isset($data["drag_image_active_".$i])) { $element_array[$i]->drag_active = true; } if (isset($data["drag_image_show_title_".$i])) { $element_array[$i]->drag_show_title = true; } if (isset($data["drag_title_input_".$i])) { $element_array[$i]->drag_title = $data["drag_title_input_".$i]; } if (isset($data["drag_image_id_".$i])) { $element_array[$i]->drag_image = $data["drag_image_id_".$i]; } if (isset($data["drop_image_active_".$i])) { $element_array[$i]->drop_active = true; } if (isset($data["drop_image_show_title_".$i])) { $element_array[$i]->drop_show_title = true; } if (isset($data["drop_title_input_".$i])) { $element_array[$i]->drop_title = $data["drop_title_input_".$i]; } if (isset($data["drop_image_correct_".$i])) { $element_array[$i]->drop_correct = $data["drop_image_correct_".$i]; } } $this->setElements($element_array); var_dump($this->getElements()); 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->getDragImage1()) { $img = new Image($this->getDragImage1()); $img->delete(); } if ($this->getDragImage2()) { $img = new Image($this->getDragImage2()); $img->delete(); } if ($this->getDragImage3()) { $img = new Image($this->getDragImage3()); $img->delete(); } if ($this->getDragImage4()) { $img = new Image($this->getDragImage4()); $img->delete(); } if ($this->getDragImage5()) { $img = new Image($this->getDragImage5()); $img->delete(); } if ($this->getDragImage6()) { $img = new Image($this->getDragImage6()); $img->delete(); } return true; } } return false; } function answer($data) { $examinee = get_examinee()->getId(); $elements = $this->getElements(); $answers = Array(); foreach($elements as $element) { $answer = Array('answer'=>'-', 'correct'=> 0); if ($element->drop_active) { if(isset($data['droppable_answer_'.$element->nr])) { $answer['answer'] = $data['droppable_answer_'.$element->nr]; if ($element->drop_correct === '0' || $element->drop_correct === $answer['answer']) { $answer['correct'] = 1; } } $answers[$element->nr] = $answer; } } $answer_start = null; if(isset($data['answer_start'])) { $answer_start = $data['answer_start']; } $answer_stop = null; if(isset($data['answer_stop'])) { $answer_stop = $data['answer_stop']; } $text = ""; if(isset($data['textfield_0'])) { $text = $data['textfield_0']; } $timer = parent::timer($data); if ($timer && $answers) { query_insert("INSERT INTO " . DB_PREFIX . "image_drag_answer ". "(base_id, examinee, answer, textfield, start, end, time_load, time_start, time_end, time_submit) values ". "(".$this->getId().", ".$examinee.", '".json_encode($answers) ."', '".mysql_real_escape_string($text)."', ".$answer_start.", ".$answer_stop.", ". $timer["load"].", ".$timer["start"].", ".$timer["end"].", ".$timer["submit"]. ") ON DUPLICATE KEY UPDATE answer='".json_encode($answers) ."', ". "textfield='".mysql_real_escape_string($text)."', start=".$answer_start.", end=".$answer_stop.",". "time_load=".$timer["load"].", time_start=".$timer["start"].", time_end=".$timer["end"].", time_submit=".$timer["submit"]); } return true; } function collect($examinees) { $answers = array(); $start = "start_time"; $end = "end_time"; $submit = "submit_time"; $answers['title'][$start] = _("Start time"); $answers['title'][$end] = _("End time"); $answers['title'][$submit] = _("Submit time"); $textfield = "textfield"; $choice = "choice"; $correct = "correct"; $title = _("Text"); if ($this->getTextTitle()) $title = $this->getTextTitle(); $answers ['title'][$textfield]= $title; foreach ($this->getElements() as $element) { if ($element->drop_active) { $answers['title'][$choice."_".$element->nr] = _("Selection")." ".$element->nr; $answers['title'][$correct."_".$element->nr] = _("Correct")." ".$element->nr; } } foreach ($examinees as $examinee) { $answer = query_row("SELECT * FROM " . DB_PREFIX . "image_drag_task t LEFT JOIN " . DB_PREFIX . "image_drag_answer a ON t.base_id=a.base_id WHERE t.base_id=".$this->getId()." AND a.examinee=".$examinee); if ($answer) { $answers[$examinee][$start] = $answer->time_start; $answers[$examinee][$end] = $answer->time_end; $answers[$examinee][$submit] = $answer->time_submit; $answers[$examinee][$textfield] = $answer->textfield; foreach (json_decode($answer->answer) as $nr => $ans) { $answers[$examinee][$choice."_".$nr] = $ans->answer; $answers[$examinee][$correct."_".$nr] = $ans->correct; } } else { $answers[$examinee][$start] = "-"; $answers[$examinee][$end] = "-"; $answers[$examinee][$submit] = "-"; $answers[$examinee][$textfield] = "-"; foreach ($this->getElements() as $element) { if ($element->drop_active) { $answers[$examinee][$choice."_".$element->nr] = "-"; $answers[$examinee][$correct."_".$element->nr] = "-"; } } } } $id = "imagedragtask_".$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 getElementsJson() { return json_encode($this->elements); } function getElementSize() { return $this->element_size; } function setElementSize($element) { $this->element_size = $element; } function getTextTitle() { return $this->text_title; } function setTextTitle($text_title) { $this->text_title = $text_title; } function getTextValue() { return $this->text_value; } function setTextValue($text_value) { $this->text_value = $text_value; } function getTextInput() { return $this->text_input; } function setTextInput($text_input) { if ($text_input) { $this->text_input = 1; } else { $this->text_input = 0; } } function getTextCols() { return $this->text_cols; } function setTextCols($text_cols) { $this->text_cols = $text_cols; } function getTextRows() { return $this->text_rows; } function setTextRows($text_rows) { $this->text_rows = $text_rows; } function getTextCharcount() { return $this->text_charcount; } function setTextCharcount($text_charcount) { $text_charcount = (int) $text_charcount; if (is_numeric($text_charcount)) { $this->text_charcount = $text_charcount; } } function getTextCharcounter() { return $this->text_charcounter; } function setTextCharcounter($text_charcounter) { if ($text_charcounter) { $this->text_charcounter = 1; } else { $this->text_charcounter = 0; } } function getAnswerRequired() { return $this->answer_required; } function setAnswerRequired($answer_required) { if ($answer_required) { $this->answer_required = 1; } else { $this->answer_required = 0; } } function getDragImage1() { return $this->drag_image_1; } function setDragImage1($drag_image_1) { $this->drag_image_1 = $drag_image_1; } function getDragImage2() { return $this->drag_image_2; } function setDragImage2($drag_image_2) { $this->drag_image_2 = $drag_image_2; } function getDragImage3() { return $this->drag_image_3; } function setDragImage3($drag_image_3) { $this->drag_image_3 = $drag_image_3; } function getDragImage4() { return $this->drag_image_4; } function setDragImage4($drag_image_4) { $this->drag_image_4 = $drag_image_4; } function getDragImage5() { return $this->drag_image_5; } function setDragImage5($drag_image_5) { $this->drag_image_5 = $drag_image_5; } function getDragImage6() { return $this->drag_image_6; } function setDragImage6($drag_image_6) { $this->drag_image_6 = $drag_image_6; } function getDragImages() { return Array( $this->getDragImage1(), $this->getDragImage2(), $this->getDragImage3(), $this->getDragImage4(), $this->getDragImage5(), $this->getDragImage6() ); } function build($data) { if (parent::build($data)) { $this->setAnswerRequired(0); if (isset($data["answer_required"])) $this->setAnswerRequired($data["answer_required"]); $this->setTextInput(0); if (isset($data["text_input"])) $this->setTextInput($data["text_input"]); if (isset($data["text_title"])) $this->setTextTitle($data["text_title"]); if (isset($data["text_value"])) $this->setTextValue($data["text_value"]); if (isset($data["text_cols"])) $this->setTextCols($data["text_cols"]); if (isset($data["text_rows"])) $this->setTextRows($data["text_rows"]); if (isset($data["text_charcount"])) { if (is_numeric($data["text_charcount"])) { $this->setTextCharcount($data["text_charcount"]); } else { $this->setTextCharcount(0); } } $this->setTextCharcounter(0); if (isset($data["text_charcounter"])) $this->setTextCharcounter($data["text_charcounter"]); if (isset($data["element_size"])) $this->setElementSize($data["element_size"]); // TODO this is really ***** // DG IMG 1 $drag_image_1 = get_file("drag_image_input_0"); if (!isset($drag_image_1["error"]) || $drag_image_1["error"] == 0) { if ($this->getDragImage1() > 0) { $image = new Image($this->getDragImage1()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_1); if ($image_id) { $this->setDragImage1($image_id); } } else if (get_input("delete_drag_image_0", false)) { $image = new Image($this->getDragImage1()); if ($image->delete()) $this->setDragImage1(NULL); } // DG IMG 2 $drag_image_2 = get_file("drag_image_input_1"); if (!isset($drag_image_2["error"]) || $drag_image_2["error"] == 0) { if ($this->getDragImage2() > 0) { $image = new Image($this->getDragImage2()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_2); if ($image_id) { $this->setDragImage2($image_id); } } else if (get_input("delete_drag_image_1", false)) { $image = new Image($this->getDragImage2()); if ($image->delete()) $this->setDragImage2(NULL); } // DG IMG 3 $drag_image_3 = get_file("drag_image_input_2"); if (!isset($drag_image_3["error"]) || $drag_image_3["error"] == 0) { if ($this->getDragImage3() > 0) { $image = new Image($this->getDragImage3()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_3); if ($image_id) { $this->setDragImage3($image_id); } } else if (get_input("delete_drag_image_2", false)) { $image = new Image($this->getDragImage3()); if ($image->delete()) $this->setDragImage3(NULL); } // DG IMG 4 $drag_image_4 = get_file("drag_image_input_3"); if (!isset($drag_image_4["error"]) || $drag_image_4["error"] == 0) { if ($this->getDragImage4() > 0) { $image = new Image($this->getDragImage4()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_4); if ($image_id) { $this->setDragImage4($image_id); } } else if (get_input("delete_drag_image_3", false)) { $image = new Image($this->getDragImage4()); if ($image->delete()) $this->setDragImage4(NULL); } // DG IMG 5 $drag_image_5 = get_file("drag_image_input_4"); if (!isset($drag_image_5["error"]) || $drag_image_5["error"] == 0) { if ($this->getDragImage5() > 0) { $image = new Image($this->getDragImage5()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_5); if ($image_id) { $this->setDragImage5($image_id); } } else if (get_input("delete_drag_image_4", false)) { $image = new Image($this->getDragImage5()); if ($image->delete()) $this->setDragImage5(NULL); } // DG IMG 6 $drag_image_6 = get_file("drag_image_input_5"); if (!isset($drag_image_6["error"]) || $drag_image_6["error"] == 0) { if ($this->getDragImage6() > 0) { $image = new Image($this->getDragImage6()); } else { $image = new Image(); } $image_id = $image->upload($drag_image_6); if ($image_id) { $this->setDragImage6($image_id); } } else if (get_input("delete_drag_image_5", false)) { $image = new Image($this->getDragImage6()); if ($image->delete()) $this->setDragImage6(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); } } ?>