public function actionWriteForUnit($id) { $unit = $this->setupCourseRegistry($this->unitRepository->find($id)); $this->deliver($unit); if (!$unit->isCurrentPhase(Unit::REVIEWS) and !$this->user->isAllowed('review', 'writeAnytime')) { throw new \Nette\Application\BadRequestException('Forbidden', 403); } $this->template->uploadPath = $this->uploadStorage->path; $this->deliver($unit->course); $solution = null; try { // needs splitting into readable methods $reviewer = $this->userRepository->find($this->user->id); if (!($review = $this->reviewRepository->findUnfinishedReview($unit, $reviewer))) { if ($solution = $this->solutionRepository->findSolutionToReview($unit, $reviewer)) { $review = $this->reviewRepository->createReview($solution, $reviewer); $review = $this->reviewRepository->find($review->id); // fetching all columns $this->logEvent($review, 'create'); } else { return; } } else { $solution = $review->solution; } $this->template->review = $this->setupCourseRegistry($review); $this->template->solution = $solution; $assignment = $solution->assignment; $this->template->assignment = $this->produce($assignment); } catch (\Model\Repository\SolutionToReviewNotFoundException $e) { $this->template->message = $this->translator->translate('messages.unit.noSolutionAvailable'); } catch (\Model\Repository\ReviewLimitReachedException $e) { $this->template->message = $this->translator->translate('messages.unit.enoughReviews', NULL, array('count' => $unit->course->reviewCount)); } }
public function addReviewFormSucceeded(Form $form, $values) { $reviewer = $this->userRepository->find($values->user_id); $solution = $this->courseRegistry->solution; $review = $this->reviewRepository->createReview($solution, $reviewer); $review->status = Review::PROBLEM; $this->reviewRepository->persist($review); $comment = new ReviewComment(); $comment->comment = '<span style="color:#aaa">— ' . $this->translator->translate('messages.review.addedAdHoc') . ' —</span>'; $comment->review = $review; $comment->review_status = $review->status; $comment->author = $this->userRepository->find($this->user->id); $comment->submitted_at = new DateTime(); $this->reviewCommentRepository->persist($comment); $this->redirect('this'); }