public function endCodeReview($id, $fee = 0) { $this->view = null; try { $workitem = new WorkItem($id); $user = User::find(Session::uid()); if (!$user->isEligible() || $workitem->getCRStarted() != 1 || $workitem->getCRCompleted() == 1 || !$this->hasCodeReviewRights($user->getId(), $workitem)) { throw new Exception('Action not allowed'); } $desc = strlen(trim($_POST['desc'])) ? 'Code Review - ' . trim($_POST['desc']) : ''; $journal_message = Fee::add($workitem->getId(), $fee, 'Code Review', $desc, $workitem->getCReviewerId(), '', ''); Utils::systemNotification($journal_message); $workitem->setCRCompleted(1); $workitem->save(); $myRunner = User::find($workitem->getRunnerId()); $myRunner->updateBudget(-$fee, $workitem->getBudget_id()); $journal_message = '@' . $_SESSION['nickname'] . ' has completed their code review for #' . $workitem->getId(); Utils::systemNotification($journal_message); $options = array('type' => 'code-review-completed', 'workitem' => $workitem, 'recipients' => array('runner', 'mechanic', 'followers')); Notification::workitemNotify($options); Notification::workitemNotifyHipchat($options, array('nick' => $_SESSION['nickname'])); echo json_encode(array('success' => true, 'message' => $journal_message)); } catch (Exception $e) { echo json_encode(array('success' => false, 'message' => $e->getMessage())); } }