id = $id; } $this->load($this->id); } function load($id) { if (is_numeric($id)) { $this->id = $id; } $data = false; if (is_numeric($this->id)) { $data = query_row("SELECT * FROM " . DB_PREFIX . $this->getTable() . " WHERE id='{$id}'"); } if ($data) { $this->id = $id; $this->setTitle($data->title); $this->setPosition($data->position); $this->setTest($data->test); return $data; } return false; } function create() { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (title, position, test) values ('".mysql_real_escape_string($this->getTitle())."', '".$this->getPosition()."', '".$this->getTest()."')"); /*if ($insert) { $this->setId($insert); }*/ return $insert; } function save() { $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " title='" . mysql_real_escape_string($this->getTitle()) . "',"; $update_query .= " position='" . $this->getPosition() . "'"; //$update_query .= " test='" . $this->getTest() . "',"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); if ($update) { return $this->getId(); } return $update; } function saveTest() { $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " test='" . $this->getTest() . "'"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); if ($update) { return $this->getId(); } return $update; } function copy($locked=false) { $crt = $this->create(); if ($crt && $locked) { $lock = $this->lock($crt); $this->copyItems($crt); } return $crt; } function copyItems($section_id) { global $TeKe; $items = $this->getItems(); //$test_position = 0; foreach ($items as $item) { $id = $item->id; $obj = $TeKe->plugin->loadType("", $id); $new_id = $obj->copy(true); $new_obj = $TeKe->plugin->loadType("", $new_id); $new_obj->setTestSection($section_id, $new_id); //$test_position++; //$new_obj->setPosition($test_position, $new_id); } } function lock($id=null) { if (!$id) $id = $this->getId(); return query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET locked=1 WHERE id=".$id); } function setAssessment($assessment_id, $id=null) { if (!$id) $id = $this->getId(); return query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET assessment={$assessment_id} WHERE id=".$id); } function build($data) { if (!isset($data["title"]) || empty($data["title"])) { return false; } else { $this->setTitle($data["title"]); if (isset($data["position"])) $this->setPosition($data["position"]); if (isset($data["test"])) $this->setTest($data["test"]); } if ($this->getId() > 0) { return $this->save(); } else { $id = $this->create(); return $id; } } function delete() { global $TeKe; if (is_numeric($this->getId()) && $this->getId() > 0) { if ($TeKe->plugin->is_test_constructor()) { return query("DELETE FROM " . DB_PREFIX . $this->getTable() . " WHERE id=".$this->getId()); } } return false; } public function getId() { return $this->id; } public function setId($id) { $this->id = $id; } public function getTable() { return $this->table; } function setTable($table) { $this->table = $table; } public function getName() { return $this->name; } function setName($name) { $this->name = $name; } public function getLocked() { return $this->locked; } public function setLocked($locked) { if ($locked) { $this->locked = 1; } else { $this->locked = 0; } } public function getTitle() { return $this->title; } function setTitle($title) { $this->title = $title; } public function getPosition() { return $this->position; } function setPosition($position) { $this->position = $position; } public function getTest() { return $this->test; } function setTest($test) { $this->test = $test; } public function getItems() { $res = query_rows("SELECT * FROM ". DB_PREFIX . "base_item WHERE test_section=".$this->getId()." ORDER BY position"); return $res; } public function reorderItems() { global $TeKe; $items = $this->getItems(); $position = 0; foreach($items as $item) { $position++; $item_obj = $TeKe->plugin->loadType("", $item->id); $item_obj->setPosition($position); } } public function getMaximumScore() { global $TeKe; $items = $this->getItems(); $score = 0; foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType($item->type, $item->id); $score += $item_obj->getMaximumScore(); } return $score; } function addBuildError($err) { $this->build_error []= $err; } function getBuildError() { return $this->build_error; } public function isLocked() { return false; } } ?>