Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPFileAuditorForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class PKPFileAuditorForm extends Form {
21 
23  var $_fileStage;
24 
26  var $_stageId;
27 
29  var $_symbolic;
30 
32  var $_eventType;
33 
35  var $_assocId;
36 
38  var $_signoffId;
39 
41  var $_fileId;
42 
46  function PKPFileAuditorForm($submission, $fileStage, $stageId, $symbolic, $eventType, $assocId = null, $publicationFormatId = null) {
47  parent::Form('controllers/grid/files/signoff/form/addAuditor.tpl');
48  $this->_submission = $submission;
49  $this->_fileStage = $fileStage;
50  $this->_stageId = $stageId;
51  $this->_symbolic = $symbolic;
52  $this->_eventType = $eventType;
53  $this->_assocId = $assocId;
54 
55  $this->addCheck(new FormValidator($this, 'userId', 'required', 'editor.submission.fileAuditor.form.userRequired'));
56  $this->addCheck(new FormValidatorListBuilder($this, 'files', 'editor.submission.fileAuditor.form.fileRequired'));
57  $this->addCheck(new FormValidator($this, 'personalMessage', 'required', 'editor.submission.fileAuditor.form.messageRequired'));
58  $this->addCheck(new FormValidatorPost($this));
59  }
60 
65  function getSubmission() {
66  return $this->_submission;
67  }
68 
73  function getFileStage() {
74  return $this->_fileStage;
75  }
80  function getStageId() {
81  return $this->_stageId;
82  }
83 
88  function getSymbolic() {
89  return $this->_symbolic;
90  }
91 
95  function getEventType() {
96  return $this->_eventType;
97  }
98 
103  function getAssocId() {
104  return $this->_assocId;
105  }
106 
111  function getSignoffId() {
112  return $this->_signoffId;
113  }
114 
120  function getFileId() {
121  return $this->_fileId;
122  }
123 
125  //
126  // Overridden template methods
127  //
133  function initData($args, $request) {
134  $submission = $this->getSubmission();
135  $this->setData('submissionId', $submission->getId());
136  $this->setData('fileStage', $this->getFileStage());
137  $this->setData('assocId', $this->getAssocId());
138 
139  import('lib.pkp.classes.mail.SubmissionMailTemplate');
140  $email = new SubmissionMailTemplate($submission, 'AUDITOR_REQUEST');
141  $user = $request->getUser();
142  // Intentionally omit {$auditorName} for now -- see bug #7090
143  $email->assignParams(array(
144  'editorialContactSignature' => $user->getContactSignature(),
145  'weekLaterDate' => strftime(
146  Config::getVar('general', 'date_format_short'),
147  time() + 604800 // 60 * 60 * 24 * 7 seconds
148  ),
149  ));
150 
151  $context = $request->getContext();
152  $this->setData('personalMessage', $email->getBody() . "\n" . $context->getSetting('emailSignature'));
153  }
159  function readInputData() {
160  $this->readUserVars(array('userId-GroupId', 'files', 'responseDueDate', 'personalMessage', 'skipEmail'));
161 
162  list($userId, $userGroupId) = explode('-', $this->getData('userId-GroupId'));
163  $this->setData('userId', $userId);
164  $this->setData('userGroupId', $userGroupId);
165  }
166 
171  function execute($request) {
172  // Decode the "files" list
173  import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
174  ListbuilderHandler::unpack($request, $this->getData('files'));
175 
176  // Send the message to the user
177  $submission = $this->getSubmission();
178  import('lib.pkp.classes.mail.SubmissionMailTemplate');
179  $email = new SubmissionMailTemplate($submission, 'AUDITOR_REQUEST', null, null, null, false);
180  $email->setBody($this->getData('personalMessage'));
181 
182  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
183  // FIXME: How to validate user IDs?
184  $user = $userDao->getById($this->getData('userId'));
185  import('lib.pkp.controllers.grid.submissions.SubmissionsListGridCellProvider');
186  list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $submission, $user->getId());
187 
188  $dispatcher = $request->getDispatcher();
189  $auditUrl = $dispatcher->url($request, ROUTE_PAGE, null, $page, $operation, array('submissionId' => $submission->getId()));
190 
191  // Other parameters assigned above; see bug #7090.
192  $email->assignParams(array(
193  'auditorName' => $user->getFullName(),
194  'auditorUserName' => $user->getUsername(),
195  'auditUrl' => $auditUrl,
196  ));
197 
198  $email->addRecipient($user->getEmail(), $user->getFullName());
199  $email->setEventType($this->getEventType());
200  if (!$this->getData('skipEmail')) {
201  $email->send($request);
202  }
203  }
204 
209  function insertEntry($request, $newRowId) {
210  // Fetch and validate the file ID
211  $fileId = (int) $newRowId['name'];
212  $submission = $this->getSubmission();
213  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
214  $submissionFile = $submissionFileDao->getLatestRevision($fileId, null, $submission->getId());
215  assert($submissionFile);
216 
217  // FIXME: How to validate user IDs?
218  $userId = (int) $this->getData('userId');
219 
220  // Fetch and validate user group ID
221  $userGroupId = (int) $this->getData('userGroupId');
222  $context = $request->getContext();
223  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
224  $userGroup = $userGroupDao->getById($userGroupId, $context->getId());
225 
226  // Build the signoff.
227  $submissionFileSignoffDao = DAORegistry::getDAO('SubmissionFileSignoffDAO');
228  $signoff = $submissionFileSignoffDao->build(
229  $this->getSymbolic(),
230  $submissionFile->getFileId(),
231  $userId, $userGroup->getId()
232  ); /* @var $signoff Signoff */
233 
234  // Set the date notified
235  $signoff->setDateNotified(Core::getCurrentDate());
236 
237  // Set the date response due (stored as date underway in signoffs table)
238  $dueDateParts = explode('-', $this->getData('responseDueDate'));
239  $signoff->setDateUnderway(date('Y-m-d H:i:s', mktime(0, 0, 0, $dueDateParts[0], $dueDateParts[1], $dueDateParts[2])));
240  $submissionFileSignoffDao->updateObject($signoff);
241 
242  $this->_signoffId = $signoff->getId();
243  $this->_fileId = $signoff->getAssocId();
244 
245  $notificationMgr = new NotificationManager();
246  $notificationMgr->updateNotification(
247  $request,
248  array(NOTIFICATION_TYPE_AUDITOR_REQUEST),
249  array($signoff->getUserId()),
250  ASSOC_TYPE_SIGNOFF,
251  $signoff->getId()
252  );
253 
254  // log the add auditor event.
255  import('lib.pkp.classes.log.SubmissionFileLog');
256  import('lib.pkp.classes.log.SubmissionFileEventLogEntry'); // constants
257  $userDao = DAORegistry::getDAO('UserDAO');
258  $user = $userDao->getById($userId);
259  if (isset($user)) {
260  SubmissionFileLog::logEvent($request, $submissionFile, SUBMISSION_LOG_FILE_AUDITOR_ASSIGN, 'submission.event.fileAuditorAdded', array('file' => $submissionFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
261  }
262 
263  $notificationMgr->updateNotification(
264  $request,
265  array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF),
266  array($signoff->getUserId()),
267  ASSOC_TYPE_SUBMISSION,
268  $submission->getId()
269  );
270  }
271 
276  function deleteEntry($request, $rowId) {
277  return true;
278  }
279 }
280 
281 ?>
Subclass of MailTemplate for sending emails related to submissions.
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Base form for Signoffs.
setData($key, $value)
Definition: Form.inc.php:219
static logEvent($request, &$submissionFile, $eventType, $messageKey, $params=array())
Form validation check to make sure the form is POSTed.
deleteEntry($request, $rowId)
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
insertEntry($request, $newRowId)
initData()
Definition: Form.inc.php:227
getData($key)
Definition: Form.inc.php:210
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
static getPageAndOperationByUserRoles($request, $submission, $userId=null)
Class to represent a form validation check.
unpack($request, $data, $deletionCallback=null, $insertionCallback=null, $updateCallback=null)
PKPFileAuditorForm($submission, $fileStage, $stageId, $symbolic, $eventType, $assocId=null, $publicationFormatId=null)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95