public function setUp() { $this->project = Project::fetch(self::$conn, 1); $this->status = AreaStatus::fetchByProject(self::$conn, 1, $this->project); $this->territory = Territory::fetchByProject(self::$conn, 1, $this->project); $this->area = Area::newArea($this->project, $this->territory, $this->status, 'Area1'); $this->area->insert(self::$conn); $this->course = new Course(); $this->course->setProject($this->project); $this->course->setName('Foo'); $this->course->setAuthorName('Foo'); $this->course->setAuthorEmail('*****@*****.**'); $this->course->setPresentationLink('http://www.example.com/'); $this->course->setIsPublished(true); $this->course->insert(self::$conn); $lang = new Language(); $lang->setId(1); $this->user = User::newUser('login', 'Some user', $lang); $this->user->insert(self::$conn); $this->anotherUser = User::newUser('login2', 'Another user', $lang); $this->anotherUser->insert(self::$conn); $pp = new CourseProgress($this->area); $pp->insert(self::$conn); }
/** * 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!'); } }
public function testDeletingUnpublishedCourse() { // Given $this->area2->insert(self::$conn); $tpa2 = new CourseProgress($this->area2); $tpa2->insert(self::$conn); $course = new Course(); $course->setName('Foo'); $this->setDefaults($course); $course->setIsPublished(false); $course->insert(self::$conn); $this->insertResult($course, $this->area, $this->user, Question::RESULT_CORRECT); $this->insertResult($course, $this->area2, $this->user2, Question::RESULT_INVALID); $this->fillRecord($this->area, 3, 2, 1); $this->fillRecord($this->area2, 3, 2, 1); // When $course->remove(self::$conn); // Then $this->assertNotExists(CourseTables::COURSE_TBL, $course->getId()); $this->expectCourseProgress($this->area, 3, 2, 1); $this->expectCourseProgress($this->area2, 3, 2, 1); }
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; }
public function onAreaCreated(AreaEvent $event) { $courseProgress = new CourseProgress($event->getArea()); $courseProgress->insert($this->conn); }
public function findProgress() { return CourseProgress::fetchByArea($this->conn, $this->area); }
public function testUpdatingResultsFromFailedtoFailed() { // Given $record = CourseProgress::fetchByArea(self::$conn, $this->area); $result = $this->getTestResult(Question::RESULT_INVALID); $trial = $this->getTestTrial(Question::RESULT_CORRECT); $this->fillRecord($this->area, 7, 3, 3); // When $record->updateResults(self::$conn, $result, $trial); // Then $this->expectCourseProgress($this->area, 7, 4, 2); }