id = $id; } $this->load($this->id); $this->setActions(); } 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->setDescription($data->description); $this->setInstructions($data->instructions); if (strtotime($data->beginning) > 0) { $beginning = date("d.m.Y H:i", strtotime($data->beginning)); $this->setBeginning($beginning); } if (strtotime($data->ending) > 0) { $ending = date("d.m.Y H:i", strtotime($data->ending)); $this->setEnding($ending); } $time_limit = date("H:i", strtotime($data->time_limit)); if ($time_limit != "00:00") { $this->setTimeLimit($time_limit); } $this->setItemsPerPage($data->items_per_page); $this->setPreviewForProctor($data->preview_for_proctor); $this->setCreated($data->created); $this->setModified($data->modified); $this->setCreator($data->creator); $this->setProctor($data->proctor); return $data; } return false; } function create() { $this->setCreator(get_logged_in_user()->getId()); $beginning = $this->getMysqlDateTime($this->getBeginning()); $ending = $this->getMysqlDateTime($this->getEnding()); $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (title, description, instructions, beginning, ending, time_limit, items_per_page, preview_for_proctor, creator, created, modified) values ('".mysql_real_escape_string($this->getTitle())."', '".mysql_real_escape_string($this->getDescription())."', '".$this->getInstructions()."', '".$beginning."', '".$ending."', '".$this->getTimeLimit()."', '".$this->getItemsPerPage()."', ".$this->getPreviewForProctor().", ".$this->getCreator().", NOW(), NOW())"); 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 .= " instructions='" . mysql_real_escape_string($this->getInstructions()) . "',"; $update_query .= " beginning='" . $this->getMysqlDateTime($this->getBeginning()) . "',"; $update_query .= " ending='" . $this->getMysqlDateTime($this->getEnding()) . "',"; $update_query .= " time_limit='" . $this->getTimeLimit() . "',"; $update_query .= " items_per_page='" . $this->getItemsPerPage() . "',"; $update_query .= " preview_for_proctor=" . $this->getPreviewForProctor() . ","; $update_query .= " modified=NOW()"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); return $this->getId(); } function copy($locked=false) { $crt = $this->create(); if ($crt && $locked) { $lock = $this->lock($crt); } return $crt; } function lock($id=null) { if (!$id) $id = $this->getId(); return query_update("UPDATE " . DB_PREFIX . "base_object SET locked=1 WHERE id=".$id); } function saveTest($assessment_id, $test_id) { global $TeKe; $obj = $TeKe->plugin->loadType("test", $test_id); $new_id = $obj->copy(true); $new_obj = $TeKe->plugin->loadType("test", $new_id); $new_obj->setAssessment($assessment_id, $new_id); //$new_obj->copyItems($obj->getItems()); } function saveProctor() { global $TeKe; $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " proctor='" . $this->getProctor() . "'"; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); if ($update) { return $this->getId(); } return $update; } function build($data) { if (!isset($data["title"]) || empty($data["title"])) { return false; } else { $this->setTitle($data["title"]); $this->setDescription($data["description"]); $this->setInstructions($data["instructions"]); $this->setBeginning($data["beginning"]); $this->setEnding($data["ending"]); $this->setTimeLimit($data["time_limit"]); $this->setItemsPerPage($data["items_per_page"]); $this->setPreviewForProctor(0); if (isset($data["preview_for_proctor"])) { $this->setPreviewForProctor($data["preview_for_proctor"]); } } if ($this->getId() > 0) { return $this->save(); } else { return $this->create(); } } 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()) { // just in case, don't delete permanently, instead setting deleted to 1 return query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET deleted=1 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)) { if ($this->getTest()) { return WWW_ROOT . "assessments/assessment/". $this->getId() . "/candidates"; } return WWW_ROOT . "assessments/assessment/". $this->getId() . "/test"; } return WWW_ROOT . "assessments/assessment/". $this->getId() . "/view"; } function getActions() { return $this->actions; } function setActions() { global $TeKe; $this->actions = array(); if ($TeKe->has_access(7)) { $this->actions ["edit"] = array("title" => _("General Information"), "disabled" => false); $this->actions ["test"] = array("title" => _("Test"), "disabled" => true); $this->actions ["proctor"] = array("title" => _("Proctor"), "disabled" => true); $this->actions ["candidates"] = array("title" => _("Candidates"), "disabled" => true); if ($this->getId() > 0) { $this->actions ["test"] = array("title" => _("Test"), "disabled" => false); if ($this->getTest()) { $this->actions ["proctor"] = array("title" => _("Proctor"), "disabled" => false); $this->actions ["candidates"] = array("title" => _("Candidates"), "disabled" => false); } } } else if ($TeKe->has_access(5) && $this->getId() > 0) { $this->actions ["view"] = array("title" => _("General Information"), "disabled" => false); if ($this->getPreviewForProctor()) { $this->actions ["test"] = array("title" => _("Test"), "disabled" => false); } } } function isPermissionToView($context='edit') { global $TeKe; if (!get_logged_in_user()->getId()) { return false; } if ($TeKe->plugin->is_test_constructor()) { return true; } else if ($context == 'view' || $context == 'results') { if ($this->getProctor() == get_logged_in_user()->getId()) { return true; } } else if ($context == 'test') { if ($this->getProctor() == get_logged_in_user()->getId() && $this->getPreviewForProctor()) { return true; } } return false; } 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 getDescription() { return $this->description; } function setDescription($description) { $this->description = $description; } public function getInstructions() { return $this->instructions; } function setInstructions($instructions) { $this->instructions = $instructions; } public function getBeginning() { return $this->beginning; } function setBeginning($beginning) { $this->beginning = $beginning; } public function getEnding() { return $this->ending; } function setEnding($ending) { $this->ending = $ending; } public function getMysqlDateTime($datetime) { return date('Y-m-d H:i', strtotime($datetime)); } public function getTimeLimit() { return $this->time_limit; } public function setTimeLimit($time_limit) { $this->time_limit = $time_limit; } public function getItemsPerPage() { return $this->items_per_page; } public function setItemsPerPage($items_per_page) { $this->items_per_page = $items_per_page; } public function getPreviewForProctor() { return $this->preview_for_proctor; } public function setPreviewForProctor($preview_for_proctor) { $this->preview_for_proctor = $preview_for_proctor; } public function getCreated() { return $this->created; } function setCreated($created) { $this->created = $created; } public function getModified() { return $this->modified; } function setModified($modified) { $this->modified = $modified; } public function getCreator() { return $this->creator; } function setCreator($creator) { $this->creator = $creator; } public function getStatus() { return $this->status; } function setStatus($status) { $this->status = $status; } public function getSecurity() { return $this->security; } function setSecurity($security) { $this->security = $security; } public function getTest() { if ($this->getId()) return query_row("SELECT * FROM ". DB_PREFIX . "tests WHERE assessment=".$this->getId()); return false; } public function getItems() { global $TeKe; $test = $this->getTest(); $test_obj = $TeKe->plugin->loadType('test', $test->id); $sections = $test_obj->getSections(); $assessment_items = array(); foreach ($sections as $section_data) { $section_obj = $TeKe->plugin->loadType('testSection', $section_data['id']); $items = $section_obj->getItems(); foreach ($items as $item) { $assessment_items []= $item; } } return $assessment_items; } public function getItem($position) { $items = $this->getItems(); return $items[$position]; } public function getProctor() { return $this->proctor; } function setProctor($proctor) { $this->proctor = $proctor; } public function getCandidates() { return query_rows("SELECT * FROM ". DB_PREFIX ."candidates WHERE assessment=".$this->getId()); } function addBuildError($err) { $this->build_error []= $err; } function getBuildError() { return $this->build_error; } public function isLocked() { return false; } function isActive() { $beginning = $this->getBeginning(); $ending = $this->getEnding(); if (time() > strtotime($beginning)) { if (!$ending) { return true; } else if (time() < strtotime($ending)) { return true; } return false; } return false; } 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 getAssessmentStatistics() { $statistics = ""; $statistics .= $this->getStatisticsFileHeading(); $statistics .= $this->getStatisticsFileItemChoicesRow(); $statistics .= $this->getCandidatesResults(); return $statistics; } function getStatisticsFileHeading() { global $TeKe; $heading = ""; $heading .= _("Name") . ","; $heading .= _("Email") . ","; $heading .= _("Ending") . ","; $items = $this->getItems(); foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType("", $item->id); if ($item->type == "multipleResponse") { $item_choices = $item_obj->getChoices(); $choices_count = count($item_choices); foreach ($item_choices as $choice) { $heading .= "\"" . $item_obj->getTitle() . "\","; } } else { $heading .= "\"" . $item_obj->getTitle() . "\","; } } return $heading . "\n"; } function getStatisticsFileItemChoicesRow() { global $TeKe; $choices_row = ",,,"; $items = $this->getItems(); foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType("", $item->id); if ($item->type == "multipleResponse") { $item_choices = $item_obj->getChoices(); foreach ($item_choices as $choice) { $choices_row .= "\"" . $choice["choice_text"] . "\","; } } else { $choices_row .= ","; } } return $choices_row . "\n"; } function getCandidatesResults() { global $TeKe; $results = ""; $candidates = $this->getCandidates(); foreach ($candidates as $candidate) { $results .= $this->getCandidateResultRow($candidate->id); } return $results; } function getCandidateResultRow($candidate_id) { global $TeKe; $row = ""; $candidate = $TeKe->plugin->loadType("candidate", $candidate_id); $items = $this->getItems(); if ($candidate->isAssessmentCompleted()) { $row .= $candidate->getFullName() . ","; $row .= $candidate->getEmail() . ","; $row .= $candidate->getEnding() . ","; foreach ($items as $item) { $item_obj = $TeKe->plugin->loadType($item->type, $item->id); $row .= $item_obj->getCandidateAnswerForCSV($candidate->getToken()); } $row .= "\n"; } return $row; } function getCandidatesCSV() { global $TeKe; $csv = ""; $candidates = $this->getCandidates(); foreach ($candidates as $candidate) { $candidate = $TeKe->plugin->loadType("candidate", $candidate->id); $csv .= $candidate->getFirstName() . ","; $csv .= $candidate->getLastName() . ","; $csv .= $candidate->getEmail() . ","; $url = WWW_ROOT . "assessment?token=" . $candidate->getToken(); $csv .= $url . "\n"; } return $csv; } } ?>