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

controllers/grid/files/fileSignoff/form/NewSignoffNoteForm.inc.php

00001 <?php
00002 
00016 import('controllers.informationCenter.form.NewNoteForm');
00017 
00018 class NewSignoffNoteForm extends NewNoteForm {
00020    var $signoffId;
00021 
00023    var $_monographId;
00024 
00026    var $_symbolic;
00027 
00029    var $_stageId;
00030 
00032    var $_actionArgs;
00033 
00037    function NewSignoffNoteForm($signoffId, $monographId, $signoffSymbolic, $stageId) {
00038       parent::NewNoteForm();
00039 
00040       $this->signoffId = $signoffId;
00041       $this->_monographId = $monographId;
00042       $this->_symbolic = $signoffSymbolic;
00043       $this->_stageId = $stageId;
00044       $this->_actionArgs = array(
00045          'signoffId' => $signoffId,
00046          'monographId' => $monographId,
00047          'stageId' => $stageId
00048       );
00049    }
00050 
00055    function getAssocType() {
00056       return ASSOC_TYPE_SIGNOFF;
00057    }
00058 
00063    function getAssocId() {
00064       return $this->signoffId;
00065    }
00066 
00070    function getNewNoteFormTemplate() {
00071       return 'controllers/informationCenter/newFileUploadNoteForm.tpl';
00072    }
00073 
00077    function getSubmitNoteLocaleKey() {
00078       return 'monograph.task.addNote';
00079    }
00080 
00084    function readInputData() {
00085       $this->readUserVars(array('signoffId', 'temporaryFileId'));
00086       parent::readInputData();
00087    }
00088 
00092    function validate() {
00093       // FIXME: this should go in a FormValidator in the constructor.
00094       $signoffId = $this->signoffId;
00095       return (is_numeric($signoffId) && $signoffId > 0);
00096    }
00097 
00101    function fetch($request) {
00102       $templateMgr =& TemplateManager::getManager();
00103       $templateMgr->assign('linkParams', $this->_actionArgs);
00104       $templateMgr->assign('showEarlierEntries', false);
00105       $templateMgr->assign('signoffId', $this->signoffId);
00106       $templateMgr->assign('symbolic', $this->_symbolic);
00107       $templateMgr->assign('stageId', $this->_stageId);
00108       $templateMgr->assign('monographId', $this->_monographId);
00109 
00110       return parent::fetch($request);
00111    }
00112 
00113    function execute($request, $userRoles) {
00114       $user =& $request->getUser();
00115 
00116       // Retrieve the signoff we're working with.
00117       $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00118       $signoff =& $signoffDao->getById($this->getData('signoffId'));
00119       assert(is_a($signoff, 'Signoff'));
00120 
00121       // Insert the note, if existing content and/or file.
00122       $temporaryFileId = $this->getData('temporaryFileId');
00123       if ($temporaryFileId || $this->getData('newNote')) {
00124          $user =& $request->getUser();
00125 
00126          $noteDao =& DAORegistry::getDAO('NoteDAO');
00127          $note = $noteDao->newDataObject();
00128 
00129          $note->setUserId($user->getId());
00130          $note->setContents($this->getData('newNote'));
00131          $note->setAssocType(ASSOC_TYPE_SIGNOFF);
00132          $note->setAssocId($signoff->getId());
00133          $noteId = $noteDao->insertObject($note);
00134          $note->setId($noteId);
00135 
00136          // Upload the file, if any, and associate it with the note.
00137          if ($temporaryFileId) {
00138             // Fetch the temporary file storing the uploaded library file
00139             $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
00140             $temporaryFile =& $temporaryFileDao->getTemporaryFile(
00141                $temporaryFileId,
00142                $user->getId()
00143             );
00144 
00145             // Upload the file.
00146             // Bring in the MONOGRAPH_FILE_* constants
00147             import('classes.monograph.MonographFile');
00148 
00149             $press =& $request->getPress();
00150             import('classes.file.MonographFileManager');
00151             $monographFileManager = new MonographFileManager($press->getId(), $this->_monographId);
00152 
00153             // Get the monograph file that is associated with the signoff.
00154             $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); 
00155             $signoffFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00156             assert(is_a($signoffFile, 'MonographFile'));
00157 
00158             $noteFileId = $monographFileManager->temporaryFileToMonographFile(
00159                $temporaryFile,
00160                MONOGRAPH_FILE_NOTE, $signoff->getUserId(),
00161                $signoff->getUserGroupId(), null, $signoffFile->getGenreId(),
00162                ASSOC_TYPE_NOTE, $noteId
00163             );
00164          }
00165 
00166          if ($user->getId() == $signoff->getUserId() && !$signoff->getDateCompleted()) {
00167             // Considered as a signoff response.
00168             // Mark the signoff as completed (we have a note with content
00169             // or a file or both).
00170             $signoff->setDateCompleted(Core::getCurrentDate());
00171             $signoffDao->updateObject($signoff);
00172 
00173             // Update NOTIFICATION_TYPE_AUDITOR_REQUEST.
00174             $notificationMgr = new NotificationManager();
00175             $notificationMgr->updateAuditorRequestNotification($signoff, $request);
00176 
00177             // Update NOTIFICATION_TYPE_SIGNOFF_...
00178             $notificationMgr->updateSignoffNotification($signoff, $request);
00179 
00180             // Define the success trivial notification locale key.
00181             $successLocaleKey = 'notification.uploadedResponse';
00182 
00183             // log the event.
00184             import('classes.log.MonographFileLog');
00185             import('classes.log.MonographFileEventLogEntry'); // constants
00186             $monographDao =& DAORegistry::getDAO('MonographDAO');
00187             $monograph =& $monographDao->getById($this->_monographId);
00188             $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00189             $monographFile =& $submissionFileDao->getLatestRevision($signoff->getFileId());
00190 
00191             if (isset($monographFile)) {
00192                MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_AUDIT_UPLOAD, 'submission.event.fileAuditUploaded', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
00193             }
00194          } else {
00195             // Common note addition.
00196             if ($user->getId() !== $signoff->getUserId() &&
00197                   array_intersect($userRoles, array(ROLE_ID_PRESS_MANAGER, ROLE_ID_PRESS_ASSISTANT, ROLE_ID_SERIES_EDITOR))) {
00198                // If the current user is a press/series editor or assistant, open the signoff again.
00199                if ($signoff->getDateCompleted()) {
00200                   $signoff->setDateCompleted(null);
00201                   $signoffDao->updateObject($signoff);
00202 
00203                   // Update NOTIFICATION_TYPE_AUDITOR_REQUEST.
00204                   $notificationMgr = new NotificationManager();
00205                   $notificationMgr->updateAuditorRequestNotification($signoff, $request);
00206 
00207                   // Update NOTIFICATION_TYPE_SIGNOFF_...
00208                   $notificationMgr->updateSignoffNotification($signoff, $request);
00209                }
00210             }
00211             $successLocaleKey = 'notification.addedNote';
00212          }
00213 
00214          NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __($successLocaleKey)));
00215 
00216          return $signoff->getId();
00217       }
00218    }
00219 }
00220 
00221 ?>

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