• Main Page
  • Modules
  • Classes
  • Files
  • File List

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

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class FileAuditorForm extends Form {
00019    var $_monograph;
00020 
00022    var $_fileStage;
00023 
00025    var $_stageId;
00026 
00028    var $_symbolic;
00029 
00031    var $_eventType;
00032 
00034    var $_assocId;
00035 
00037    var $_publicationFormatId;
00038 
00040    var $_signoffId;
00041 
00043    var $_fileId;
00044 
00048    function FileAuditorForm($monograph, $fileStage, $stageId, $symbolic, $eventType, $assocId = null, $publicationFormatId = null) {
00049       parent::Form('controllers/grid/files/signoff/form/addAuditor.tpl');
00050       $this->_monograph =& $monograph;
00051       $this->_fileStage = $fileStage;
00052       $this->_stageId = $stageId;
00053       $this->_symbolic = $symbolic;
00054       $this->_eventType = $eventType;
00055       $this->_assocId = $assocId;
00056       $this->_publicationFormatId = $publicationFormatId;
00057 
00058       $this->addCheck(new FormValidator($this, 'userId', 'required', 'editor.monograph.fileAuditor.form.userRequired'));
00059       $this->addCheck(new FormValidatorListBuilder($this, 'files', 'editor.monograph.fileAuditor.form.fileRequired'));
00060       $this->addCheck(new FormValidator($this, 'personalMessage', 'required', 'editor.monograph.fileAuditor.form.messageRequired'));
00061       $this->addCheck(new FormValidatorPost($this));
00062    }
00063 
00068    function getMonograph() {
00069       return $this->_monograph;
00070    }
00071 
00076    function getFileStage() {
00077       return $this->_fileStage;
00078    }
00083    function getStageId() {
00084       return $this->_stageId;
00085    }
00086 
00091    function getSymbolic() {
00092       return $this->_symbolic;
00093    }
00094 
00098    function getEventType() {
00099       return $this->_eventType;
00100    }
00101 
00106    function getAssocId() {
00107       return $this->_assocId;
00108    }
00109 
00114    function getPublicationFormatId() {
00115       return $this->_publicationFormatId;
00116    }
00117 
00122    function getSignoffId() {
00123       return $this->_signoffId;
00124    }
00125 
00131    function getFileId() {
00132       return $this->_fileId;
00133    }
00134 
00135 
00136    //
00137    // Overridden template methods
00138    //
00144    function initData($args, &$request) {
00145       $monograph = $this->getMonograph();
00146       $this->setData('monographId', $monograph->getId());
00147       $this->setData('fileStage', $this->getFileStage());
00148       $this->setData('assocId', $this->getAssocId());
00149       if ($this->getPublicationFormatId()) {
00150          $this->setData('publicationFormatId', $this->getPublicationFormatId());
00151       }
00152       import('classes.mail.MonographMailTemplate');
00153       $email = new MonographMailTemplate($monograph, 'AUDITOR_REQUEST');
00154       $user =& $request->getUser();
00155       // Intentionally omit {$auditorName} for now -- see bug #7090
00156       $email->assignParams(array(
00157          'editorialContactSignature' => $user->getContactSignature(),
00158          'monographTitle' => $monograph->getSeriesTitle(),
00159          'weekLaterDate' => strftime(
00160             Config::getVar('general', 'date_format_short'),
00161             time() + 604800 // 60 * 60 * 24 * 7 seconds
00162          ),
00163       ));
00164 
00165       $press =& $request->getPress();
00166       $this->setData('personalMessage', $email->getBody() . "\n" . $press->getSetting('emailSignature'));
00167    }
00168 
00173    function readInputData() {
00174       $this->readUserVars(array('userId-GroupId', 'files', 'responseDueDate', 'personalMessage', 'skipEmail'));
00175 
00176       list($userId, $userGroupId) = explode('-', $this->getData('userId-GroupId'));
00177       $this->setData('userId', $userId);
00178       $this->setData('userGroupId', $userGroupId);
00179    }
00180 
00185    function execute(&$request) {
00186       // Decode the "files" list
00187       import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
00188       ListbuilderHandler::unpack($request, $this->getData('files'));
00189 
00190       // Send the message to the user
00191       $monograph =& $this->getMonograph();
00192       import('classes.mail.MonographMailTemplate');
00193       $email = new MonographMailTemplate($monograph, 'AUDITOR_REQUEST', null, null, null, false);
00194       $email->setBody($this->getData('personalMessage'));
00195 
00196       $userDao =& DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
00197       // FIXME: How to validate user IDs?
00198       $user =& $userDao->getById($this->getData('userId'));
00199       import('controllers.grid.submissions.SubmissionsListGridCellProvider');
00200       list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $monograph, $user->getId());
00201 
00202       $dispatcher =& $request->getDispatcher();
00203       $auditUrl = $dispatcher->url($request, ROUTE_PAGE, null, $page, $operation, array('monographId' => $monograph->getId()));
00204 
00205       // Other parameters assigned above; see bug #7090.
00206       $email->assignParams(array(
00207          'auditorName' => $user->getFullName(),
00208          'auditorUserName' => $user->getUsername(),
00209          'auditUrl' => $auditUrl,
00210       ));
00211 
00212       $email->addRecipient($user->getEmail(), $user->getFullName());
00213       $email->setEventType($this->getEventType());
00214       if (!$this->getData('skipEmail')) {
00215          $email->send($request);
00216       }
00217    }
00218 
00223    function insertEntry(&$request, $newRowId) {
00224       // Fetch and validate the file ID
00225       $fileId = (int) $newRowId['name'];
00226       $monograph =& $this->getMonograph();
00227       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00228       $monographFile =& $submissionFileDao->getLatestRevision($fileId, null, $monograph->getId());
00229       assert($monographFile);
00230 
00231       // FIXME: How to validate user IDs?
00232       $userId = (int) $this->getData('userId');
00233 
00234       // Fetch and validate user group ID
00235       $userGroupId = (int) $this->getData('userGroupId');
00236       $press =& $request->getPress();
00237       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00238       $userGroup =& $userGroupDao->getById($userGroupId, $press->getId());
00239 
00240       // Build the signoff.
00241       $monographFileSignoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00242       $signoff =& $monographFileSignoffDao->build(
00243          $this->getSymbolic(),
00244          $monographFile->getFileId(),
00245          $userId, $userGroup->getId()
00246       ); /* @var $signoff Signoff */
00247 
00248       // Set the date notified
00249       $signoff->setDateNotified(Core::getCurrentDate());
00250 
00251       // Set the date response due (stored as date underway in signoffs table)
00252       $dueDateParts = explode('-', $this->getData('responseDueDate'));
00253       $signoff->setDateUnderway(date('Y-m-d H:i:s', mktime(0, 0, 0, $dueDateParts[0], $dueDateParts[1], $dueDateParts[2])));
00254       $monographFileSignoffDao->updateObject($signoff);
00255 
00256       $this->_signoffId = $signoff->getId();
00257       $this->_fileId = $signoff->getAssocId();
00258 
00259       // Update NOTIFICATION_TYPE_AUDITOR_REQUEST.
00260       $notificationMgr = new NotificationManager();
00261       $notificationMgr->updateAuditorRequestNotification($signoff, $request);
00262 
00263       // log the add auditor event.
00264       import('classes.log.MonographFileLog');
00265       import('classes.log.MonographFileEventLogEntry'); // constants
00266       $userDao =& DAORegistry::getDAO('UserDAO');
00267       $user =& $userDao->getById($userId);
00268       if (isset($user)) {
00269          MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_AUDITOR_ASSIGN, 'submission.event.fileAuditorAdded', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
00270       }
00271       // Update NOTIFICATION_TYPE_SIGNOFF_...
00272       $notificationMgr->updateSignoffNotification($signoff, $request);
00273    }
00274 
00279    function deleteEntry(&$request, $rowId) {
00280       return true;
00281    }
00282 }
00283 
00284 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1