/**
  * Internal function to return a ReviewFormResponse object from a row.
  * @param $row array
  * @return ReviewFormResponse
  */
 function &_returnReviewFormResponseFromRow(&$row)
 {
     $responseValue = $this->convertFromDB($row['response_value'], $row['response_type']);
     $reviewFormResponse = new ReviewFormResponse();
     $reviewFormResponse->setReviewId($row['review_id']);
     $reviewFormResponse->setReviewFormElementId($row['review_form_element_id']);
     $reviewFormResponse->setValue($responseValue);
     $reviewFormResponse->setResponseType($row['response_type']);
     HookRegistry::call('ReviewFormResponseDAO::_returnReviewFormResponseFromRow', array(&$reviewFormResponse, &$row));
     return $reviewFormResponse;
 }
 /**
  * Save the response.
  */
 function execute()
 {
     $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
     $reviewAssignment =& $reviewAssignmentDao->getById($this->reviewId);
     $reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
     $reviewFormResponseDao =& DAORegistry::getDAO('ReviewFormResponseDAO');
     $reviewFormResponses = $this->getData('reviewFormResponses');
     if (is_array($reviewFormResponses)) {
         foreach ($reviewFormResponses as $reviewFormElementId => $reviewFormResponseValue) {
             $reviewFormResponse =& $reviewFormResponseDao->getReviewFormResponse($this->reviewId, $reviewFormElementId);
             if (!isset($reviewFormResponse)) {
                 $reviewFormResponse = new ReviewFormResponse();
             }
             $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
             $reviewFormElement = $reviewFormElementDao->getReviewFormElement($reviewFormElementId);
             $elementType = $reviewFormElement->getElementType();
             switch ($elementType) {
                 case REVIEW_FORM_ELEMENT_TYPE_SMALL_TEXT_FIELD:
                 case REVIEW_FORM_ELEMENT_TYPE_TEXT_FIELD:
                 case REVIEW_FORM_ELEMENT_TYPE_TEXTAREA:
                     $reviewFormResponse->setResponseType('string');
                     $reviewFormResponse->setValue($reviewFormResponseValue);
                     break;
                 case REVIEW_FORM_ELEMENT_TYPE_RADIO_BUTTONS:
                 case REVIEW_FORM_ELEMENT_TYPE_DROP_DOWN_BOX:
                     $reviewFormResponse->setResponseType('int');
                     $reviewFormResponse->setValue($reviewFormResponseValue);
                     break;
                 case REVIEW_FORM_ELEMENT_TYPE_CHECKBOXES:
                     $reviewFormResponse->setResponseType('object');
                     $reviewFormResponse->setValue($reviewFormResponseValue);
                     break;
             }
             if ($reviewFormResponse->getReviewFormElementId() != null && $reviewFormResponse->getReviewId() != null) {
                 $reviewFormResponseDao->updateObject($reviewFormResponse);
             } else {
                 $reviewFormResponse->setReviewFormElementId($reviewFormElementId);
                 $reviewFormResponse->setReviewId($this->reviewId);
                 $reviewFormResponseDao->insertObject($reviewFormResponse);
             }
         }
     }
 }
 /**
  * @see Form::execute()
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $reviewAssignment =& $this->getReviewAssignment();
     $notificationMgr = new NotificationManager();
     if ($reviewAssignment->getReviewFormId()) {
         $reviewFormResponseDao = DAORegistry::getDAO('ReviewFormResponseDAO');
         $reviewFormResponses = $this->getData('reviewFormResponses');
         if (is_array($reviewFormResponses)) {
             foreach ($reviewFormResponses as $reviewFormElementId => $reviewFormResponseValue) {
                 $reviewFormResponse = $reviewFormResponseDao->getReviewFormResponse($reviewAssignment->getId(), $reviewFormElementId);
                 if (!isset($reviewFormResponse)) {
                     $reviewFormResponse = new ReviewFormResponse();
                 }
                 $reviewFormElementDao = DAORegistry::getDAO('ReviewFormElementDAO');
                 $reviewFormElement = $reviewFormElementDao->getById($reviewFormElementId);
                 $elementType = $reviewFormElement->getElementType();
                 switch ($elementType) {
                     case REVIEW_FORM_ELEMENT_TYPE_SMALL_TEXT_FIELD:
                     case REVIEW_FORM_ELEMENT_TYPE_TEXT_FIELD:
                     case REVIEW_FORM_ELEMENT_TYPE_TEXTAREA:
                         $reviewFormResponse->setResponseType('string');
                         $reviewFormResponse->setValue($reviewFormResponseValue);
                         break;
                     case REVIEW_FORM_ELEMENT_TYPE_RADIO_BUTTONS:
                     case REVIEW_FORM_ELEMENT_TYPE_DROP_DOWN_BOX:
                         $reviewFormResponse->setResponseType('int');
                         $reviewFormResponse->setValue($reviewFormResponseValue);
                         break;
                     case REVIEW_FORM_ELEMENT_TYPE_CHECKBOXES:
                         $reviewFormResponse->setResponseType('object');
                         $reviewFormResponse->setValue($reviewFormResponseValue);
                         break;
                 }
                 if ($reviewFormResponse->getReviewFormElementId() != null && $reviewFormResponse->getReviewId() != null) {
                     $reviewFormResponseDao->updateObject($reviewFormResponse);
                 } else {
                     $reviewFormResponse->setReviewFormElementId($reviewFormElementId);
                     $reviewFormResponse->setReviewId($reviewAssignment->getId());
                     $reviewFormResponseDao->insertObject($reviewFormResponse);
                 }
             }
         }
     } else {
         // Create a comment with the review.
         $submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO');
         $comment = $submissionCommentDao->newDataObject();
         $comment->setCommentType(COMMENT_TYPE_PEER_REVIEW);
         $comment->setRoleId(ROLE_ID_REVIEWER);
         $comment->setAssocId($reviewAssignment->getId());
         $comment->setSubmissionId($reviewAssignment->getSubmissionId());
         $comment->setAuthorId($reviewAssignment->getReviewerId());
         $comment->setComments($this->getData('comments'));
         $comment->setCommentTitle('');
         $comment->setViewable(true);
         $comment->setDatePosted(Core::getCurrentDate());
         // Persist the comment.
         $submissionCommentDao->insertObject($comment);
         $submissionDao = Application::getSubmissionDAO();
         $submission = $submissionDao->getById($reviewAssignment->getSubmissionId());
         $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
         $stageAssignments = $stageAssignmentDao->getBySubmissionAndStageId($submission->getId(), $submission->getStageId());
         $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
         $router = $request->getRouter();
         $context = $router->getContext($request);
         $receivedList = array();
         // Avoid sending twice to the same user.
         while ($stageAssignment = $stageAssignments->next()) {
             $userId = $stageAssignment->getUserId();
             $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId(), $submission->getContextId());
             // Never send reviewer comment notification to authors.
             if ($userGroup->getRoleId() == ROLE_ID_AUTHOR || in_array($userId, $receivedList)) {
                 continue;
             }
             $notificationMgr->createNotification($request, $userId, NOTIFICATION_TYPE_REVIEWER_COMMENT, $submission->getContextId(), ASSOC_TYPE_REVIEW_ASSIGNMENT, $reviewAssignment->getId());
             $receivedList[] = $userId;
         }
     }
     // Set review to next step.
     $this->updateReviewStepAndSaveSubmission($this->getReviewerSubmission());
     // Mark the review assignment as completed.
     $reviewAssignment->setDateCompleted(Core::getCurrentDate());
     $reviewAssignment->stampModified();
     // assign the recommendation to the review assignment, if there was one.
     $reviewAssignment->setRecommendation((int) $this->getData('recommendation'));
     // Persist the updated review assignment.
     $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
     /* @var $reviewAssignmentDao ReviewAssignmentDAO */
     $reviewAssignmentDao->updateObject($reviewAssignment);
     // Update the review round status.
     $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
     /* @var $reviewRoundDao ReviewRoundDAO */
     $reviewRound = $reviewRoundDao->getById($reviewAssignment->getReviewRoundId());
     $reviewAssignments = $reviewAssignmentDao->getByReviewRoundId($reviewRound->getId(), true);
     $reviewRoundDao->updateStatus($reviewRound, $reviewAssignments);
     // Update "all reviews in" notification.
     $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_ALL_REVIEWS_IN), null, ASSOC_TYPE_REVIEW_ROUND, $reviewRound->getId());
     // Remove the task
     $notificationDao = DAORegistry::getDAO('NotificationDAO');
     $notificationDao->deleteByAssoc(ASSOC_TYPE_REVIEW_ASSIGNMENT, $reviewAssignment->getId(), $reviewAssignment->getReviewerId(), NOTIFICATION_TYPE_REVIEW_ASSIGNMENT);
 }