Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ManageSubmissionFilesForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 import('lib.pkp.classes.submission.SubmissionFile');
18 
21  var $_submissionId;
22 
28  function ManageSubmissionFilesForm($submissionId, $template) {
29  parent::Form($template);
30  $this->_submissionId = (int)$submissionId;
31 
32  $this->addCheck(new FormValidatorPost($this));
33  }
34 
35 
36  //
37  // Getters / Setters
38  //
43  function getSubmissionId() {
44  return $this->_submissionId;
45  }
46 
47  //
48  // Overridden template methods
49  //
55  function initData($args, $request) {
56  $this->setData('submissionId', $this->_submissionId);
57  }
58 
63  function readInputData() {
64  $this->readUserVars(array('selectedFiles'));
65  }
66 
74  function execute($args, $request, $stageSubmissionFiles, $fileStage) {
75  $selectedFiles = (array)$this->getData('selectedFiles');
76  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
77  $submissionFiles = $submissionFileDao->getLatestRevisions($this->getSubmissionId());
78 
79  foreach ($submissionFiles as $submissionFile) {
80  // Get the viewable flag value.
81  $isViewable = in_array(
82  $submissionFile->getFileId(),
83  $selectedFiles);
84 
85  // If this is a submission file that belongs to the current stage id...
86  if (array_key_exists($submissionFile->getFileId(), $stageSubmissionFiles)) {
87  // ...update the "viewable" flag accordingly.
88  $submissionFile->setViewable($isViewable);
89  } else {
90  // If the viewable flag is set to true...
91  if ($isViewable) {
92  // Make a copy of the file to the current file stage.
93  import('lib.pkp.classes.file.SubmissionFileManager');
94  $context = $request->getContext();
95  $submissionFileManager = new SubmissionFileManager($context->getId(), $submissionFile->getSubmissionId());
96  // Split the file into file id and file revision.
97  $fileId = $submissionFile->getFileId();
98  $revision = $submissionFile->getRevision();
99  list($newFileId, $newRevision) = $submissionFileManager->copyFileToFileStage($fileId, $revision, $fileStage, null, true);
100  if ($fileStage == SUBMISSION_FILE_REVIEW_FILE) {
101  $submissionFileDao->assignRevisionToReviewRound($newFileId, $newRevision, $this->getReviewRound());
102  }
103  $submissionFile = $submissionFileDao->getRevision($newFileId, $newRevision);
104  }
105  }
106  $submissionFileDao->updateObject($submissionFile);
107  }
108  }
109 }
110 
111 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
Form validation check to make sure the form is POSTed.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
initData()
Definition: Form.inc.php:227
getData($key)
Definition: Form.inc.php:210
execute($args, $request, $stageSubmissionFiles, $fileStage)
Form for add or removing files from a review.
ManageSubmissionFilesForm($submissionId, $template)