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

controllers/modals/signoff/form/SignoffFileUploadForm.inc.php

00001 <?php
00002 
00016 import('lib.pkp.classes.form.Form');
00017 
00018 class SignoffFileUploadForm extends Form {
00019    var $_monographId;
00020    var $_stageId;
00021    var $_symbolic;
00022    var $_signoffId;
00023 
00034    function SignoffFileUploadForm($monographId, $stageId, $symbolic, $signoffId = null) {
00035       $this->_monographId = $monographId;
00036       $this->_stageId = $stageId;
00037       $this->_symbolic = $symbolic;
00038       $this->_signoffId = $signoffId;
00039 
00040       parent::Form('controllers/modals/signoff/form/signoffFileUploadForm.tpl');
00041    }
00042 
00043    //
00044    // Getters/Setters
00045    //
00049    function getMonographId() {
00050       return $this->_monographId;
00051    }
00052 
00057    function getStageId() {
00058       return $this->_stageId;
00059    }
00060 
00065    function getSymbolic() {
00066       return $this->_symbolic;
00067    }
00068 
00069    /*
00070     * Get the Signoff ID for this form
00071     */
00072    function getSignoffId() {
00073       return $this->_signoffId;
00074    }
00075 
00076    //
00077    // Implement template methods from Form
00078    //
00082    function initData(&$request) {
00083       $this->setData('monographId', $this->getMonographId());
00084       $this->setData('stageId', $this->getStageId());
00085    }
00086 
00087 
00091    function fetch($request) {
00092       $templateMgr =& TemplateManager::getManager();
00093       $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO'); /* @var $signoffDao MonographFileSignoffDAO */
00094       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00095 
00096       $signoffId = $this->getSignoffId();
00097       if ($signoffId) {
00098          $signoff =& $signoffDao->getById($signoffId);
00099       }
00100 
00101       // Signoff specified. Find related file and show file name
00102       if (isset($signoff)) {
00103          $templateMgr->assign('signoffId', $signoff->getId());
00104 
00105          $submissionFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00106          assert(is_a($submissionFile, 'MonographFile'));
00107 
00108          $templateMgr->assign('signoffFileName', $submissionFile->getLocalizedName());
00109       } else {
00110          // No signoff specified, look at all available signoffs
00111          $user =& $request->getUser();
00112          $signoffs =& $signoffDao->getAllByMonograph($this->getMonographId(), $this->getSymbolic(), $user->getId(), null, true);
00113          $availableSignoffs = array();
00114          while ($signoff =& $signoffs->next()) {
00115             $submissionFile =& $submissionFileDao->getLatestRevision($signoff->getAssocId());
00116             assert(is_a($submissionFile, 'MonographFile'));
00117 
00118             $availableSignoffs[$signoff->getId()] = $submissionFile->getLocalizedName();
00119             unset($signoff);
00120          }
00121 
00122          // Only one, act as if it had been specified originally.
00123          if (count($availableSignoffs) == 1) {
00124             // Array as quick way of getting key and value. Only one element anyway.
00125             foreach ($availableSignoffs as $signoffId => $fileName) {
00126                $templateMgr->assign('signoffId', $signoffId);
00127                $templateMgr->assign('signoffFileName', $fileName);
00128             }
00129          } else {
00130             // Should let user choose from all available.
00131             $templateMgr->assign('availableSignoffs', $availableSignoffs);
00132          }
00133       }
00134 
00135       return parent::fetch($request);
00136    }
00137 
00141    function readInputData() {
00142       $this->readUserVars(array('signoffId', 'newNote', 'temporaryFileId'));
00143    }
00144 
00148    function validate(&$request) {
00149       // FIXME: this should go in a FormValidator in the constructor.
00150       $signoffId = $this->getSignoffId();
00151       return (is_numeric($signoffId) && $signoffId > 0);
00152    }
00153 
00154    //
00155    // Override from SubmissionFileUploadForm
00156    //
00162    function execute($request) {
00163       $user =& $request->getUser();
00164 
00165       // Retrieve the signoff we're working with.
00166       $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00167       $signoff =& $signoffDao->getById($this->getData('signoffId'));
00168       assert(is_a($signoff, 'Signoff'));
00169 
00170       // Insert the note, if existing content and/or file.
00171       $temporaryFileId = $this->getData('temporaryFileId');
00172       if ($temporaryFileId || $this->getData('newNote')) {
00173          $user =& $request->getUser();
00174 
00175          $noteDao =& DAORegistry::getDAO('NoteDAO');
00176          $note = $noteDao->newDataObject();
00177 
00178          $note->setUserId($user->getId());
00179          $note->setContents($this->getData('newNote'));
00180          $note->setAssocType(ASSOC_TYPE_SIGNOFF);
00181          $note->setAssocId($signoff->getId());
00182          $noteId = $noteDao->insertObject($note);
00183          $note->setId($noteId);
00184 
00185          // Upload the file, if any, and associate it with the note.
00186          if ($temporaryFileId) {
00187             // Fetch the temporary file storing the uploaded library file
00188             $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
00189             $temporaryFile =& $temporaryFileDao->getTemporaryFile(
00190                $temporaryFileId,
00191                $user->getId()
00192             );
00193 
00194             // Upload the file.
00195             // Bring in the MONOGRAPH_FILE_* constants
00196             import('classes.monograph.MonographFile');
00197 
00198             $press =& $request->getPress();
00199             import('classes.file.MonographFileManager');
00200             $monographFileManager = new MonographFileManager($press->getId(), $this->getMonographId());
00201             $signoffFileId = $monographFileManager->temporaryFileToMonographFile(
00202                $temporaryFile,
00203                MONOGRAPH_FILE_NOTE, $signoff->getUserId(),
00204                $signoff->getUserGroupId(), $signoff->getAssocId(), null,
00205                ASSOC_TYPE_NOTE, $noteId
00206             );
00207 
00208 
00209             // FIXME: Currently the code allows for a signoff to be
00210             // added many times (if the option is presented in the
00211             // form). Need to delete previous files uploaded to this
00212             // signoff. Partially due to #6799.
00213 
00214             // Mark ALL the signoffs for this user as completed with this file upload.
00215             if ($signoffFileId) {
00216                $signoff->setFileId($signoffFileId);
00217                $signoff->setFileRevision(1);
00218             }
00219          }
00220 
00221          // Now mark the signoff as completed (we have a note with content
00222          // or a file or both).
00223          $signoff->setDateCompleted(Core::getCurrentDate());
00224          $signoffDao->updateObject($signoff);
00225 
00226          // Update NOTIFICATION_TYPE_AUDITOR_REQUEST.
00227          $notificationMgr = new NotificationManager();
00228          $notificationMgr->updateAuditorRequestNotification($signoff, $request);
00229 
00230          // Update NOTIFICATION_TYPE_SIGNOFF_...
00231          $notificationMgr->updateSignoffNotification($signoff, $request);
00232 
00233          // log the event.
00234          import('classes.log.MonographFileLog');
00235          import('classes.log.MonographFileEventLogEntry'); // constants
00236          $monographDao =& DAORegistry::getDAO('MonographDAO');
00237          $monograph =& $monographDao->getById($this->getMonographId());
00238          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00239          $monographFile =& $submissionFileDao->getLatestRevision($signoff->getFileId());
00240 
00241          if (isset($monographFile)) {
00242             MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_AUDIT_UPLOAD, 'submission.event.fileAuditUploaded', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
00243          }
00244          return $signoff->getId();
00245       }
00246    }
00247 }
00248 
00249 ?>

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