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->setAssessmentId($data->assessment); $this->setToken($data->token); $this->setFirstName($data->first_name); $this->setLastName($data->last_name); $this->setEmail($data->email); if (strtotime($data->beginning) > 0) { $beginning = date("d.m.Y H:i:s", strtotime($data->beginning)); $this->setBeginning($beginning); } if (strtotime($data->ending) > 0) { $ending = date("d.m.Y H:i:s", strtotime($data->ending)); $this->setEnding($ending); } $this->setAnsweredCount($data->answered_count); $this->setGaveUp($data->gave_up); /*$this->setCreated($data->created); $this->setModified($data->modified); $this->setCreator($data->creator);*/ return $data; } return false; } function create() { $this->setCreator(get_logged_in_user()->getId()); $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (first_name, last_name, email, assessment, token, creator) values ('".mysql_real_escape_string($this->getFirstName())."', '".mysql_real_escape_string($this->getLastName())."', '".mysql_real_escape_string($this->getEmail())."', ".$this->getAssessmentId().", '".$this->getToken()."', ".$this->getCreator().")"); return $insert; } function save() { $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " title='" . mysql_real_escape_string($this->getTitle()) . "',"; $update_query .= " description='" . mysql_real_escape_string($this->getDescription()) . "',"; $update_query .= " modified=NOW()"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); return $update; } function build($data) { global $TeKe; $this->setFirstName($data["first_name"]); $this->setLastName($data["last_name"]); $this->setEmail($data["email"]); $this->setAssessmentId($data["assessment_id"]); $token = $TeKe->generate_random_string(20); $this->setToken($token); if ($this->getId() > 0) { return $this->save(); } else { $id = $this->create(); if ($this->getEmail()) { $this->sendAssessmentMail(); } return $id; } } function sendAssessmentMail() { textdomain("tester"); global $TeKe; $TeKe->translator->addDomain("tester", '../../../i18n'); $assessment = $TeKe->plugin->loadType("assessment", $this->getAssessmentId()); $creator = $TeKe->user->getUserById($this->getCreator()); $subject = $assessment->getTitle(); $message = "Hi,\n\n"; $message .= "%s has added you to assessment: %s\n\n"; $message .= "Please find time to take the assessment. Your assessment is located at:\n"; $message .= "%s\n\n"; $message .= "Clicking on this link opens assessment, where is more detailed information and instructions about testing.\n\n"; $message .= "We are willing to help if you have any problems and best way to let us know is either call (699 8155) or write tiina.kuusk@bcs.ee\n\n"; $message .= "Best,\n"; $message .= "BCS Koolitus AS\n\n"; $message .= "--\n"; $message .= "Please do not reply to this message."; $msg = _($message); $msg = sprintf($msg, "BCS Koolitus", $assessment->getTitle(), $this->getAssessmentURL()); return $this->send_mail_to_candidate($subject, $msg); } function sendReminderMail($content="") { global $TeKe; textdomain("tester"); $TeKe->translator->addDomain("tester", '../../../i18n'); $assessment = $TeKe->plugin->loadType("assessment", $this->getAssessmentId()); $subject = sprintf(_("Reminder: %s"), $assessment->getTitle()); $message = sprintf(_("Hi %s,\n\n"), $this->getFullName()); if ($content) { $message .= $content . "\n\n"; } $message_content = "Your assessment is located at:\n"; $message_content .= "%s\n\n"; $message_content .= "Best,\n"; $message_content .= "%s\n\n"; $message_content .= "--\n"; $message_content .= "Please do not reply to this message."; $message_content = _($message_content); $message_content = sprintf($message_content, $this->getAssessmentURL(), "BCS Koolitus"); $message .= $message_content; return $this->send_mail_to_candidate($subject, $message); } function send_mail_to_candidate($subject, $message) { $to_name = $this->getFullName(); $to_email = $this->getEmail(); $to = "{$to_name} <{$to_email}>"; $headers = "MIME-Version: 1.0". "\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; $headers .= "From:BCS Koolitus " . "\r\n"; return mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $headers); } function delete() { global $TeKe; if (is_numeric($this->getId()) && $this->getId() > 0) { if ($this->canEdit() && !$this->isAssessmentStarted()) { return query("DELETE FROM " . DB_PREFIX . $this->getTable() . " WHERE id=".$this->getId()); } } return false; } function canEdit() { global $TeKe; if ($TeKe->plugin->is_test_constructor()) { return true; } else { $assessment_id = $this->getAssessmentId(); $assessment = $TeKe->plugin->loadType("assessment", $assessment_id); if ($assessment->getProctor() == get_logged_in_user()->getId()) { return true; } } 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 getAssessmentURL() { $token = $this->getToken(); return WWW_ROOT . "assessment?token=${token}"; } public function getFirstName() { return $this->first_name; } function setFirstName($first_name) { $this->first_name = $first_name; } public function getLastName() { return $this->last_name; } function setLastName($last_name) { $this->last_name = $last_name; } function getFullName() { return $this->getFirstName() . " " . $this->getLastName(); } public function getEmail() { return $this->email; } function setEmail($email) { $this->email = $email; } public function getToken() { return $this->token; } function setToken($token) { $this->token = $token; } public function getCreator() { return $this->creator; } function setCreator($creator) { $this->creator = $creator; } public function getAssessmentId() { return $this->assessment_id; } function setAssessmentId($assessment_id) { $this->assessment_id = $assessment_id; } public function getBeginning() { return $this->beginning; } function setBeginning($beginning) { $this->beginning = $beginning; } public function getEnding() { return $this->ending; } function setEnding($ending) { $this->ending = $ending; } function getAnsweredCount() { return intval($this->answered_count); } function setAnsweredCount($answered_count) { $this->answered_count = $answered_count; } function getGaveUp() { return $this->gave_up; } function setGaveUp($gave_up) { $this->gave_up = $gave_up; } function startAssessment() { return query_update("UPDATE " . DB_PREFIX . $this->getTable() ." SET beginning=NOW() WHERE id=".$this->getId()); } function giveUpAssessment() { return query_update("UPDATE " . DB_PREFIX . $this->getTable() ." SET beginning=NOW(), ending=NOW(), gave_up=true WHERE id=".$this->getId()); } function finishAssessment() { return query_update("UPDATE " . DB_PREFIX . $this->getTable() ." SET ending=NOW() WHERE id=".$this->getId()); } function isAssessmentStarted() { if ($this->getBeginning()) { return true; } return false; } function isAssessmentFinished() { if ($this->getEnding()) { return true; } return false; } function isAssessmentCompleted() { if ($this->getEnding() && $this->getGaveUp() == false) { return true; } return false; } function updateAnsweredCount($answered_count) { return query_update("UPDATE " . DB_PREFIX . $this->getTable() ." SET answered_count=${answered_count} WHERE id=".$this->getId()); } function getAssessmentStatus() { if (!$this->isAssessmentStarted()) { return _("Haven't Started"); } if ($this->getGaveUp()) { return _("Gave Up"); } if ($this->isAssessmentFinished()) { return _("Finished"); } else { return _("Not Finished"); } return ""; } function getTestSectionResult($test_section_id) { global $TeKe; $test_section = $TeKe->plugin->loadType("testSection", $test_section_id); $items = $test_section->getItems(); $score = 0; foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType($item->type, $item->id); $answer = $item_obj->getCandidateAnswer($this->getToken()); $score += $answer->score; } return $score; } public function getScore() { global $TeKe; $assessment_id = $this->getAssessmentId(); $assessment = $TeKe->plugin->loadType("assessment", $assessment_id); $items = $assessment->getItems(); $score = 0; foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType($item->type, $item->id); $answer = $item_obj->getCandidateAnswer($this->getToken()); $score += $answer->score; } return $score; } function getPercent() { global $TeKe; $assessment_id = $this->getAssessmentId(); $assessment = $TeKe->plugin->loadType("assessment", $assessment_id); $score = $this->getScore(); $maximum_score = $assessment->getMaximumScore(); $percent = $TeKe->plugin->calculatePercent($score, $maximum_score); return $percent; } function getRemainingTime() { global $TeKe; $assessment_id = $this->getAssessmentId(); $assessment = $TeKe->plugin->loadType("assessment", $assessment_id); $time_limit = $assessment->getTimeLimit(); $begin = strtotime($this->getBeginning()); //$elapsed = time() - $begin; $limit = explode(":", $time_limit); $time_given = ($limit[0] * 3600) + ($limit[1] * 60); $end = ($begin) + $time_given; $remaining = $end - strtotime("now"); $remaining_time = gmdate("H:i:s", $remaining); if ($remaining < 0) { return "00:00:00"; } /*var_dump("

".$elapsed . "elapsed sec"); $elapsed_date = date("H:i:s", $elapsed); $seconds_left = strtotime("01:00:00") - $elapsed; $time_left = date("H:i:s", $seconds_left); var_dump($time_left. "_time
");exit;*/ return $remaining_time; } /** * Get candidate assessment duration. * * @return string Only hours and minutes */ function getDuration() { $beginning = $this->getBeginning(); $ending = $this->getEnding(); $elapsed = strtotime($ending) - strtotime($beginning); return gmdate("H:i", $elapsed); } function addBuildError($err) { $this->build_error []= $err; } function getBuildError() { return $this->build_error; } } ?>