/** * Complete course * * This function is used to set the course status to completed for * the current user. If the course is set to automatically issue a * certificate, the certificate is issued. * <br/>Example: * <code> * $user -> completeCourse(5, 87, 'Very good progress'); //Complete course with id 5 * </code> * * @param Efrontmixed $course Either an EfrontCourse object or a course id * @param int $score The course score * @param string $comments Comments for the course completion * @return boolean True if everything is ok */ public function completeCourse($course, $score, $comments, $time = '') { $time ? $timestamp = $time : ($timestamp = time()); if (!$course instanceof EfrontCourse) { $course = new EfrontCourse($course); } $constraints = array('archive' => false, 'active' => true, 'return_objects' => false); $userCourses = $this->getUserCourses($constraints); if (in_array($course->course['id'], array_keys($userCourses))) { //keep completed date when it is set (when only score changed for example) $checkCompleted = $userCourses[$course->course['id']]['to_timestamp']; $fields = array('completed' => 1, 'to_timestamp' => $timestamp, 'score' => str_replace(',', '.', $score), 'comments' => $comments); $where = "users_LOGIN = '******'login'] . "' and courses_ID=" . $course->course['id']; EfrontCourse::persistCourseUsers($fields, $where, $course->course['id'], $this->user['login']); if (!self::$cached_modules) { self::$cached_modules = eF_loadAllModules(); } // Trigger all necessary events. If the function has not been re-defined in the derived module class, nothing will happen foreach (self::$cached_modules as $module) { $module->onCompleteCourse($course->course['id'], $this->user['login']); } if ($course->options['auto_certificate']) { $certificate = $course->prepareCertificate($this->user['login'], $time); $course->issueCertificate($this->user['login'], $certificate); } $event = array("type" => EfrontEvent::COURSE_COMPLETION, "users_LOGIN" => $this->user['login'], "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name'], "replace" => true); EfrontEvent::triggerEvent($event); // Assign the related course skills to the employee if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE if (!$this->aspects['hcd']) { $this->aspects['hcd'] = EfrontEmployeeFactory::factory($this->user['login']); } $employee = $this->aspects['hcd']; $newSkills = eF_getTableDataFlat("module_hcd_course_offers_skill", "skill_ID, specification", "courses_ID = '" . $course->course['id'] . "'"); // The course associated skills will *complement* the existing ones - last argument = true $employee->addSkills($newSkills['skill_ID'], $newSkills['specification'], array_fill(0, sizeof($newSkills['skill_ID']), $score), true); } #cpp#endif return true; } else { return false; } }