setType("KeeperTask"); $this->setName("Keeper Task"); $this->setTable("keeper_task"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"), "compose"=>_("Compose"))); if ($id) { $data = $this->load($id); if ($data) { $this->setTableHeight($data->table_height); $this->setTableWidth($data->table_width); $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->setTextPos($data->text_pos); $this->setFloor(unserialize($data->floor)); } } } function create() { if ($id = parent::create()) { $serialized_floor = serialize($this->floor); $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, table_height, table_width, text_title, text_input, text_value, text_cols, text_rows, text_pos, floor) values (".$id.", ".$this->getTableHeight().", ".$this->getTableWidth().", '".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_pos.", '".mysql_real_escape_string($serialized_floor)."')"); return $id; } return false; } function save() { if (parent::save()) { if (query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET table_height=".$this->getTableHeight().", table_width=".$this->getTableWidth().", 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_pos=".$this->text_pos." WHERE base_id=".$this->getId())) return $this->getId(); } return false; } function copy($locked=false) { $copy = $this->create(); if ($copy && $locked) { $lock = $this->lock($copy); } return $copy; } function compose($data) { if (isset($data["keeper_elements"])) { return $this->saveFloor($data["keeper_elements"]); } } function saveFloor($data) { $this->floor = $data; $serialized_floor = serialize($this->floor); if (query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET floor='".mysql_real_escape_string($serialized_floor)."' WHERE base_id=".$this->getId())) return $this->getId(); return false; } function answer($data) { $examinee = get_examinee()->getId(); $load = 0; $start = 0; $end = 0; $different = 0; $walls = 0; $moves = array(); $steps = array(); $textfield = ""; if (isset($data['text_answer'])) $textfield = $data['text_answer']; if (isset($data['keeper_play_data']) && $data['keeper_play_data']!="") { $d = json_decode($data['keeper_play_data']); $load = $d->load; $start = $d->start; $end = $d->end; $different = $d->different; $walls = $d->walls; $moves = $d->moves; $steps = $d->steps; } $moves = serialize($moves); $steps = serialize($steps); $timer = parent::timer($data); if ($timer) { query_insert("INSERT INTO " . DB_PREFIX . "keeper_answer ". "(base_id, examinee, moves, steps, walls, different, load_time, start, end, textfield, time_load, time_start, time_end, time_submit) values ". "(".$this->getId().", ".$examinee.", '".mysql_real_escape_string($moves)."', '".mysql_real_escape_string($steps)."', ".$walls.", ".$different.", ".(int) $load.", ".$start.", ".$end.", '".mysql_real_escape_string($textfield)."', ". $timer["load"].", ".$timer["start"].", ".$timer["end"].", ".$timer["submit"]. ") ON DUPLICATE KEY UPDATE moves='".mysql_real_escape_string($moves)."', steps='".mysql_real_escape_string($steps)."', walls=".$walls.", different=".$different.", load_time=".(int) $load.", start=".$start.", end=".$end.", textfield='".mysql_real_escape_string($textfield)."', ". "time_load=".$timer["load"].", time_start=".$timer["start"].", time_end=".$timer["end"].", time_submit=".$timer["submit"]); } return true; } function collect($examinees) { $walls = "walls"; $different = "different"; $moves = "moves"; $steps = "steps"; $text = "text"; $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"); $answers['title'][$different] = _("Different squares"); $answers['title'][$walls] = _("Trough wall"); $answers['title'][$moves] = _("Moves"); $answers['title'][$steps] = _("Steps"); if ($this->getTextInput()) { $answers['title'][$text] = _("Text"); if ($this->getTextTitle()) $title = $this->getTextTitle(); $answers['title'][$text] = $title; } foreach ($examinees as $examinee) { $answer = query_row("SELECT * FROM " . DB_PREFIX . "keeper_task t LEFT JOIN " . DB_PREFIX . "keeper_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][$different] = $answer->different; $answers[$examinee][$walls] = $answer->walls; $moves_array = array(); foreach (unserialize($answer->moves) as $move) { //$moves_array []= $move->col.":".$move->row; //use coordinates $moves_array []= $this->arrayCoordinatesAsNr(array($move->col, $move->row), $this->getTableWidth()); //use index } $answers[$examinee][$moves] = join(",", $moves_array); $steps_array = array(); foreach (unserialize($answer->steps) as $step) { //$steps_array []= $step->col.":".$step->row; //use coordinates $steps_array []= $this->arrayCoordinatesAsNr(array($step->col, $step->row), $this->getTableWidth()); //use index } $answers[$examinee][$steps] = join(",", $steps_array); if ($this->getTextInput()) { $answers[$examinee][$text] = $answer->textfield; } } else { $answers[$examinee][$start] = "-"; $answers[$examinee][$end] = "-"; $answers[$examinee][$submit] = "-"; $answers[$examinee][$different] = "-"; $answers[$examinee][$walls] = "-"; $answers[$examinee][$moves] = "-"; $answers[$examinee][$steps] = "-"; if ($this->getTextInput()) { $answers[$examinee][$text] = "-"; } /*foreach (unserialize($answer->an_el) as $id => $element) { $answers['title'][$id] = $element['title']; $answers[$examinee][$id] = $element['choice']; }*/ } } $id = "keepertask_".$this->getId(); $title = _("None")." ".$this->getId(); if ($this->getTitle()) $title = $this->getTitle(); return array('id'=>$id, 'title'=>$title, 'answers'=>$answers); } function build($data) { if (parent::build($data)) { 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->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_pos"])) $this->setTextPos($data["text_pos"]); 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 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 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 getTextPos() { return $this->text_pos; } function setTextPos($text_pos) { $this->text_pos = $text_pos; } function getFloor() { return $this->floor; } function setFloor($floor) { $this->floor = $floor; } function buildFromXML($obj, $version=2, $folder=0) { var_dump($obj);exit; //parent::buildFromXML($obj); } } ?>