Exemplo n.º 1
0
 protected function tryRecordingAreaResult(Connection $conn, Area $area, TestTrial $trial)
 {
     $areaResult = AreaCourseResult::fetchResult($conn, $area, $this->course);
     if ($areaResult->result == Question::RESULT_UNKNOWN) {
         $conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $this->user->getId(), 'courseId' => $this->course->getId()]);
         $progress = CourseProgress::fetchByArea($conn, $area);
         $progress->updateResults($conn, $areaResult, $trial);
         return $progress;
     } elseif ($areaResult->result == Question::RESULT_INVALID) {
         $conn->update(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $this->user->getId(), 'courseId' => $this->course->getId()], ['areaId' => $area->getId(), 'courseId' => $this->course->getId()]);
         $progress = CourseProgress::fetchByArea($conn, $area);
         $progress->updateResults($conn, $areaResult, $trial);
         return $progress;
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Certain courses do not have a test. In this situation the user may click a button where he
  * simply confirms in good-faith that he/she has completed the given course.
  * 
  * @param Connection $conn Database connection
  * @param Area $area The area which finishes the course.
  * @param User $user The user who completes the course.
  * @return CourseProgress|boolean
  */
 public function confirmGoodFaithCompletion(Connection $conn, Area $area, User $user)
 {
     if ($this->hasTest()) {
         throw new ModelException('Cannot confirm good-faith completion for a course that has a test assigned.');
     }
     try {
         $stmt = $conn->prepare('INSERT INTO `' . CourseTables::COURSE_RESULT_TBL . '` ' . '(`userId`, `courseId`, `trialNumber`, `startedAt`, `completedAt`, `result`, `totalQuestions`, `passedQuestions`) ' . 'VALUES(:userId, :courseId, 1, :startedAt, :completedAt, :result, :totalQuestions, :passedQuestions)');
         $stmt->bindValue(':userId', $user->getId());
         $stmt->bindValue(':courseId', $this->getId());
         $stmt->bindValue(':result', Question::RESULT_CORRECT);
         $stmt->bindValue(':startedAt', time());
         $stmt->bindValue(':completedAt', time());
         $stmt->bindValue(':totalQuestions', 1);
         $stmt->bindValue(':passedQuestions', 1);
         $stmt->execute();
         $areaResult = AreaCourseResult::fetchResult($conn, $area, $this);
         if ($areaResult->getResult() == Question::RESULT_UNKNOWN) {
             $conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['userId' => $user->getId(), 'areaId' => $area->getId(), 'courseId' => $this->id]);
             $progress = CourseProgress::fetchByArea($conn, $area);
             $progress->updateGoodFaithCompletion($conn);
             return $progress;
         }
         return true;
     } catch (UniqueConstraintViolationException $exception) {
         throw new ModelException('Cannot complete a completed test!');
     }
 }
Exemplo n.º 3
0
 public function getAreaResult(Area $area, Course $course)
 {
     return AreaCourseResult::fetchResult($this->conn, $area, $course);
 }