/** * Upload a file and render the modified upload wizard. * @param $args array * @param $request Request * @return JSONMessage JSON object */ function uploadFile($args, $request) { // Instantiate the file upload form. $submission = $this->getSubmission(); import('lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadForm'); $uploadForm = new SubmissionFilesUploadForm($request, $submission->getId(), $this->getStageId(), null, null, $this->getFileStage(), $this->getRevisionOnly(), $this->getReviewRound(), null, $this->getAssocType(), $this->getAssocId()); $uploadForm->readInputData(); // Validate the form and upload the file. if (!$uploadForm->validate($request)) { return new JSONMessage(false, array_pop($uploadForm->getErrorsArray())); } $uploadedFile = $uploadForm->execute($request); /* @var $uploadedFile SubmissionFile */ if (!is_a($uploadedFile, 'SubmissionFile')) { return new JSONMessage(false, __('common.uploadFailed')); } $this->_attachEntities($uploadedFile); // Retrieve file info to be used in a JSON response. $uploadedFileInfo = $this->_getUploadedFileInfo($uploadedFile); $reviewRound = $this->getReviewRound(); // If no revised file id was given then try out whether // the user maybe accidentally didn't identify this file as a revision. if (!$uploadForm->getRevisedFileId()) { $revisedFileId = $this->_checkForRevision($uploadedFile, $uploadForm->getSubmissionFiles()); if ($revisedFileId) { // Instantiate the revision confirmation form. import('lib.pkp.controllers.wizard.fileUpload.form.SubmissionFilesUploadConfirmationForm'); $confirmationForm = new SubmissionFilesUploadConfirmationForm($request, $submission->getId(), $this->getStageId(), $this->getFileStage(), $reviewRound, $revisedFileId, $this->getAssocType(), $this->getAssocId(), $uploadedFile); $confirmationForm->initData($args, $request); // Render the revision confirmation form. return new JSONMessage(true, $confirmationForm->fetch($request), '0', $uploadedFileInfo); } } // Advance to the next step (i.e. meta-data editing). return new JSONMessage(true, '', '0', $uploadedFileInfo); }
/** * Upload a file and render the modified upload wizard. * @param $args array * @param $request Request * @return string a serialized JSON object */ function uploadFile($args, &$request, $fileModifyCallback = null) { // Instantiate the file upload form. $monograph =& $this->getMonograph(); import('controllers.wizard.fileUpload.form.SubmissionFilesUploadForm'); $uploadForm = new SubmissionFilesUploadForm($request, $monograph->getId(), $this->getStageId(), null, $this->getFileStage(), $this->getRevisionOnly(), $this->getReviewType(), $this->getRound(), null); $uploadForm->readInputData(); // Validate the form and upload the file. if ($uploadForm->validate($request)) { if (is_a($uploadedFile =& $uploadForm->execute($request), 'MonographFile')) { // Retrieve file info to be used in a JSON response. $uploadedFileInfo = $this->_getUploadedFileInfo($uploadedFile); // If no revised file id was given then try out whether // the user maybe accidentally didn't identify this file as a revision. if (!$uploadForm->getRevisedFileId()) { $revisedFileId = $this->_checkForRevision($uploadedFile, $uploadForm->getMonographFiles()); if ($revisedFileId) { // Instantiate the revision confirmation form. import('controllers.wizard.fileUpload.form.SubmissionFilesUploadConfirmationForm'); $confirmationForm = new SubmissionFilesUploadConfirmationForm($request, $monograph->getId(), $this->getFileStage(), $revisedFileId, $uploadedFile); $confirmationForm->initData($args, $request); // Render the revision confirmation form. $json = new JSON(true, $confirmationForm->fetch($request), false, '0', $uploadedFileInfo); return $json->getString(); } } // Advance to the next step (i.e. meta-data editing). $json = new JSON(true, '', false, '0', $uploadedFileInfo); } else { $json = new JSON(false, Locale::translate('common.uploadFailed')); } } else { $json = new JSON(false, array_pop($uploadForm->getErrorsArray())); } return $json->getString(); }