setType("HedgehogTask"); $this->setName("Hedgehog Task"); $this->setTable("hedgehog_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->setTaskType($data->task_type); $this->setAskNumberOfSteps($data->ask_number_of_steps); $this->setLandscapeTable(unserialize($data->landscape_table)); //$this->setRightChoice(unserialize($data->right_choice)); } } } function create() { if ($id = parent::create()) { $this->createLandscapeTable(); $serialized_table = serialize($this->landscape_table); //$serialized_right_choice = serialize($this->right_choice); $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, table_height, table_width, task_type, ask_number_of_steps, landscape_table) values (".$id.", ".$this->getTableHeight().", ".$this->getTableWidth().", '".$this->getTaskType()."', ".$this->getAskNumberOfSteps().", '".$serialized_table."')"); return $id; } return false; } function save() { if (parent::save()) { //$this->updateFlowerTable(); //$serialized_table = serialize($this->flower_table); if (query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET table_height=".$this->getTableHeight().", table_width=".$this->getTableWidth().", task_type='".$this->getTaskType()."', ask_number_of_steps=".$this->getAskNumberOfSteps()." 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) { $row = $data["row"]; $col = $data["col"]; $active_tool = $data["active_tool"]; $this->saveLandscapeTable($row, $col, $active_tool); } function saveLandscapeTable($row, $col, $data) { $this->landscape_table[$row][$col] = $data; $serialized_table = serialize($this->landscape_table); if (query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET landscape_table='".$serialized_table."' WHERE base_id=".$this->getId())) return $this->getId(); } 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']; $timer = parent::timer($data); if ($timer) { query_insert("INSERT INTO " . DB_PREFIX . "hedgehog_answer ". "(base_id, examinee, total, empty, hill, river, answer, moves, start, end, time_load, time_start, time_end, time_submit) values ". "(".$this->getId().", ".$examinee.", ". $total .", ". $empty .", ". $hill .", ". $river .", ". $answer .", '". $moves ."', ".$start.", ".$end.", ". $timer["load"].", ".$timer["start"].", ".$timer["end"].", ".$timer["submit"]. ") ON DUPLICATE KEY UPDATE total=". $total .", empty=". $empty .", hill=". $hill .", river=". $river .", answer=". $answer .", moves='". $moves ."', start=".$start.", end=".$end.", ". "time_load=".$timer["load"].", time_start=".$timer["start"].", time_end=".$timer["end"].", time_submit=".$timer["submit"]); } return true; } function collect($examinees) { $start = "start_time"; $end = "end_time"; $submit = "submit_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'][$submit] = _("Submit 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] = $answer->time_start; $answers[$examinee][$end] = $answer->time_end; $answers[$examinee][$submit] = $answer->time_submit; $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][$submit] = "-"; $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 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")); } } if (isset($data["task_type"])) $this->setTaskType($data["task_type"]); $this->setAskNumberOfSteps(0); if (isset($data["ask_number_of_steps"])) { $this->setAskNumberOfSteps($data["ask_number_of_steps"]); } 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 getTaskType() { return $this->task_type; } function setTaskType($task_type) { $this->task_type = $task_type; } function getAskNumberOfSteps() { return $this->ask_number_of_steps; } function setAskNumberOfSteps($ask_number_of_steps) { $this->ask_number_of_steps = $ask_number_of_steps; } function getFriend() { $friend = "dog"; if ($this->getTaskType() == "dog") { $friend = "hedgehog"; } return $friend; } function createLandscapeTable() { if (!$this->landscape_table) { $table = array(); $rows = $this->getTableHeight(); $cols = $this->getTableWidth(); foreach (range(0,$rows-1) as $row) { $table []= array(); foreach (range(0,$cols-1) as $col) { $table[$row][$col] = "empty"; } } $this->landscape_table = $table; } } function updateLandscapeTable() { $table = $this->landscape_table; $rows = $this->getTableHeight(); $cols = $this->getTableWidth(); $actor = $this->getTaskType(); foreach (range(0,$rows-1) as $row) { if ($row > count($table)-1) { $table []= array(); } foreach (range(0,$cols-1) as $col) { if ($col > count($table[$row])-1) { $table[$row][$col] = "empty"; } } } $this->landscape_table = $table; } function getLandscapeTable() { return $this->landscape_table; } function setLandscapeTable($landscape_table) { $this->landscape_table = $landscape_table; } function getMoves() { $table = array(); $rows = $this->getTableHeight(); $cols = $this->getTableWidth(); foreach (range(0,$rows-1) as $row) { $table []= array(); foreach (range(0,$cols-1) as $col) { $table[$row][$col] = "empty"; } } return $table; } function buildFromXML($obj, $version=1, $folder=0) { var_dump($obj);exit; //parent::buildFromXML($obj); } } ?>