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->setAssessment($data->assessment); $this->setCandidate($data->candidate); $this->setBeginning($data->beginning); $this->setEnding($data->ending); return $data; } return false; } function create() { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (assessment, candidate) values (".$this->getAssessment().", ".$this->getCandidate().")"); return $insert; } function finishAssessment() { $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " ending=NOW()"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); return $this->getId(); } function build($data) { //if (!isset($data["title"]) || empty($data["title"])) { // return false; //} else { $this->setAssessment($data["assessment"]); $this->setCandidate($data["candidate"]); //} 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() || $this->creator==get_logged_in_user()->getId()) { 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; } function getURL() { global $TeKe; if ($TeKe->has_access(7)) { return WWW_ROOT . "assessments/assessment/". $this->getId() . "/edit"; } return WWW_ROOT . "assessments/assessment/". $this->getId() . "/view"; } public function getAssessment() { return $this->assessment; } function setAssessment($assessment) { $this->assessment = $assessment; } public function getCandidate() { return $this->candidate; } function setCandidate($candidate) { $this->candidate = $candidate; } public function getEnding() { return $this->ending; } function setEnding($ending) { $this->ending = $ending; } public function isFinished() { console_log($this->getEnding(), "assessment endding"); if ($this->getEnding() > 0) { return true; } return false; } public function getBeginning() { return $this->beginning; } function setBeginning($beginning) { $this->beginning = $beginning; } public function getScore($token) { global $TeKe; $assessment = $this->getAssessment(); $items = $assessment->getItems(); $score = 0; foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType($item->type, $item->id); $answer = $item_obj.getCandidateAnswer($token); $score += $answer->getScore(); } return $score; } } ?>