PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/controllers/grid/files/signoff/form/FileAuditorForm.inc.php

https://github.com/mbehiels/omp
PHP | 225 lines | 113 code | 35 blank | 77 comment | 1 complexity | afe53fdded6b21c64c69c733d2252361 MD5 | raw file
  1. <?php
  2. /**
  3. * @file controllers/grid/files/copyedit/form/CopyeditingUserForm.inc.php
  4. *
  5. * Copyright (c) 2003-2011 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class CopyeditingUserForm
  9. * @ingroup controllers_grid_files_copyedit
  10. *
  11. * @brief Form to add files to the final draft files grid
  12. */
  13. import('lib.pkp.classes.form.Form');
  14. class FileAuditorForm extends Form {
  15. /** The monograph associated with the submission contributor being edited **/
  16. var $_monograph;
  17. /* @var int */
  18. var $_fileStage;
  19. /* @var int */
  20. var $_stageId;
  21. /* @var string */
  22. var $_symbolic;
  23. /* @var string */
  24. var $_eventType;
  25. /* @var int */
  26. var $_assocId;
  27. /**
  28. * Constructor.
  29. */
  30. function FileAuditorForm($monograph, $fileStage, $stageId, $symbolic, $eventType, $assocId = null) {
  31. parent::Form('controllers/grid/files/signoff/form/addAuditor.tpl');
  32. $this->_monograph =& $monograph;
  33. $this->_fileStage = $fileStage;
  34. $this->_stageId = $stageId;
  35. $this->_symbolic = $symbolic;
  36. $this->_eventType = $eventType;
  37. $this->_assocId = $assocId;
  38. $this->addCheck(new FormValidator($this, 'userId', 'required', 'editor.monograph.fileAuditor.form.userRequired'));
  39. $this->addCheck(new FormValidator($this, 'files', 'required', 'editor.monograph.fileAuditor.form.fileRequired'));
  40. $this->addCheck(new FormValidator($this, 'personalMessage', 'required', 'editor.monograph.fileAuditor.form.messageRequired'));
  41. $this->addCheck(new FormValidatorPost($this));
  42. }
  43. /**
  44. * Get the monograph
  45. * @return Monograph
  46. */
  47. function getMonograph() {
  48. return $this->_monograph;
  49. }
  50. /**
  51. * Get the file stage.
  52. * @return integer
  53. */
  54. function getFileStage() {
  55. return $this->_fileStage;
  56. }
  57. /**
  58. * Get the workflow stage id.
  59. * @return integer
  60. */
  61. function getStageId() {
  62. return $this->_stageId;
  63. }
  64. /**
  65. * Get the signoff's symbolic
  66. * @return string
  67. */
  68. function getSymbolic() {
  69. return $this->_symbolic;
  70. }
  71. /**
  72. * Get the email key
  73. */
  74. function getEventType() {
  75. return $this->_eventType;
  76. }
  77. /**
  78. * Get the assoc id
  79. */
  80. function getAssocId() {
  81. return $this->_assocId;
  82. }
  83. //
  84. // Overridden template methods
  85. //
  86. /**
  87. * Initialize variables
  88. * @param $args array
  89. * @param $request PKPRequest
  90. */
  91. function initData($args, &$request) {
  92. $monograph = $this->getMonograph();
  93. $this->setData('monographId', $monograph->getId());
  94. $this->setData('fileStage', $this->getFileStage());
  95. $this->setData('assocId', $this->getAssocId());
  96. import('classes.mail.MonographMailTemplate');
  97. $email = new MonographMailTemplate($monograph, 'AUDITOR_REQUEST');
  98. $this->setData('personalMessage', $email->getBody());
  99. }
  100. /**
  101. * Assign form data to user-submitted data.
  102. * @see Form::readInputData()
  103. */
  104. function readInputData() {
  105. $this->readUserVars(array('userId-GroupId', 'files', 'responseDueDate', 'personalMessage', 'skipEmail'));
  106. list($userId, $userGroupId) = explode('-', $this->getData('userId-GroupId'));
  107. $this->setData('userId', $userId);
  108. $this->setData('userGroupId', $userGroupId);
  109. }
  110. /**
  111. * Assign user to copyedit the selected files
  112. * @see Form::execute()
  113. */
  114. function execute(&$request) {
  115. // Decode the "files" list
  116. import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
  117. $changedFileData = $this->getData('files');
  118. ListBuilderHandler::unpack($request, $changedFileData);
  119. // Send the message to the user
  120. $monograph =& $this->getMonograph();
  121. import('classes.mail.MonographMailTemplate');
  122. $email = new MonographMailTemplate($monograph, 'AUDITOR_REQUEST');
  123. $email->setBody($this->getData('personalMessage'));
  124. $dateFormatShort = Config::getVar('general', 'date_format_short');
  125. $weekLaterDate = time() + 604800;
  126. $weekLaterDate = strftime($dateFormatShort, $weekLaterDate);
  127. $userDao =& DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
  128. $user =& $request->getUser();
  129. $contactSignature = $user->getContactSignature();
  130. // FIXME: Bug #6199: How to validate user IDs?
  131. $user =& $userDao->getUser($this->getData('userId'));
  132. $paramArray = array(
  133. 'auditorName' => $user->getFullName(),
  134. 'editorialContactSignature' => $contactSignature,
  135. 'monographTitle' => $monograph->getSeriesTitle(),
  136. 'weekLaterDate' => $weekLaterDate
  137. );
  138. $email->assignParams($paramArray);
  139. $email->addRecipient($user->getEmail(), $user->getFullName());
  140. $email->setEventType($this->getEventType());
  141. if (!$this->getData('skipEmail')) {
  142. $email->send($request);
  143. }
  144. }
  145. /**
  146. * Persist a signoff insertion
  147. * @see ListbuilderHandler::insertEntry
  148. */
  149. function insertEntry(&$request, $newRowId) {
  150. // Fetch and validate the file ID
  151. $fileId = (int) $newRowId['name'];
  152. $monograph =& $this->getMonograph();
  153. $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
  154. $monographFile =& $submissionFileDao->getLatestRevision($fileId, null, $monograph->getId());
  155. assert($monographFile);
  156. // FIXME: Bug #6199: How to validate user IDs?
  157. $userId = (int) $this->getData('userId');
  158. // Fetch and validate user group ID
  159. $userGroupId = (int) $this->getData('userGroupId');
  160. $press =& $request->getPress();
  161. $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
  162. $userGroup =& $userGroupDao->getById($userGroupId, $press->getId());
  163. // Build the signoff.
  164. $monographFileSignoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
  165. $signoff =& $monographFileSignoffDao->build(
  166. $this->getSymbolic(),
  167. $monographFile->getFileId(),
  168. $userId, $userGroup->getId()
  169. ); /* @var $signoff Signoff */
  170. // Set the date notified
  171. $signoff->setDateNotified(Core::getCurrentDate());
  172. // Set the date response due (stored as date underway in signoffs table)
  173. $dueDateParts = explode('-', $this->getData('responseDueDate'));
  174. $signoff->setDateUnderway(date('Y-m-d H:i:s', mktime(0, 0, 0, $dueDateParts[0], $dueDateParts[1], $dueDateParts[2])));
  175. $monographFileSignoffDao->updateObject($signoff);
  176. // Update NOTIFICATION_TYPE_AUDITOR_REQUEST.
  177. $notificationMgr = new NotificationManager();
  178. $notificationMgr->updateAuditorRequestNotification($signoff, $request);
  179. // Update NOTIFICATION_TYPE_SIGNOFF_...
  180. $notificationMgr->updateSignoffNotification($signoff, $request);
  181. }
  182. /**
  183. * Delete a signoff
  184. * FIXME: it was throwing a warning when this was not specified. We just want client side delete.
  185. */
  186. function deleteEntry(&$request, $rowId) {
  187. return true;
  188. }
  189. }
  190. ?>