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

controllers/informationCenter/FileInformationCenterHandler.inc.php

00001 <?php
00002 
00015 import('controllers.informationCenter.InformationCenterHandler');
00016 import('lib.pkp.classes.core.JSONMessage');
00017 import('classes.log.MonographEventLogEntry');
00018 
00019 class FileInformationCenterHandler extends InformationCenterHandler {
00021    var $monographFile;
00022 
00024    var $monograph;
00025 
00029    function FileInformationCenterHandler() {
00030       parent::InformationCenterHandler();
00031 
00032       $this->addRoleAssignment(
00033          array(
00034             ROLE_ID_AUTHOR,
00035             ROLE_ID_SERIES_EDITOR,
00036             ROLE_ID_PRESS_MANAGER,
00037             ROLE_ID_PRESS_ASSISTANT
00038          ),
00039          array('listPastNotes', 'listPastHistory')
00040       );
00041    }
00042 
00046    function initialize(&$request, $args = null) {
00047       parent::initialize($request, $args);
00048 
00049       // Fetch the monograph and file to display information about
00050       $this->monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00051 
00052       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00053       $this->monographFile =& $submissionFileDao->getLatestRevision($request->getUserVar('fileId'));
00054 
00055       // Ensure data integrity.
00056       if (!$this->monograph || !$this->monographFile || $this->monograph->getId() != $this->monographFile->getMonographId()) fatalError('Unknown or invalid monograph or monograph file!');
00057    }
00058 
00064    function viewInformationCenter($args, &$request) {
00065       $this->setupTemplate($request);
00066 
00067       // Assign variables to the template manager and display
00068       $templateMgr =& TemplateManager::getManager();
00069       $fileName = (($s = $this->monographFile->getLocalizedName()) != '') ? $s : __('common.untitled');
00070       if (($i = $this->monographFile->getRevision()) > 1) $fileName .= " ($i)"; // Add revision number to label
00071       if (empty($fileName) ) $fileName = __('common.untitled');
00072       $templateMgr->assign_by_ref('title', $fileName);
00073       $templateMgr->assign('removeHistoryTab', (int) $request->getUserVar('removeHistoryTab'));
00074 
00075       return parent::viewInformationCenter($request);
00076    }
00077 
00083    function viewNotes($args, &$request) {
00084       $this->setupTemplate($request);
00085 
00086       import('controllers.informationCenter.form.NewFileNoteForm');
00087       $notesForm = new NewFileNoteForm($this->monographFile->getFileId());
00088       $notesForm->initData();
00089 
00090       $json = new JSONMessage(true, $notesForm->fetch($request));
00091       return $json->getString();
00092    }
00093 
00099    function listPastNotes($args, &$request) {
00100       $this->setupTemplate($request);
00101 
00102       $templateMgr =& TemplateManager::getManager();
00103       $noteDao =& DAORegistry::getDAO('NoteDAO');
00104 
00105       $monographFile = $this->monographFile;
00106       $notes = array();
00107       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00108       while (true) {
00109          $monographFile = $submissionFileDao->getRevision($monographFile->getSourceFileId(), $monographFile->getSourceRevision());
00110          if (!$monographFile) break;
00111 
00112          $iterator =& $noteDao->getByAssoc($this->_getAssocType(), $monographFile->getFileId());
00113          $notes += $iterator->toArray();
00114 
00115          unset($iterator);
00116       }
00117       import('lib.pkp.classes.core.ArrayItemIterator');
00118       $templateMgr->assign('notes', new ArrayItemIterator($notes));
00119 
00120       $user =& $request->getUser();
00121       $templateMgr->assign('currentUserId', $user->getId());
00122 
00123       $templateMgr->assign('notesListId', 'pastNotesList');
00124       return $templateMgr->fetchJson('controllers/informationCenter/notesList.tpl');
00125    }
00126 
00132    function saveNote($args, &$request) {
00133       $this->setupTemplate($request);
00134 
00135       import('controllers.informationCenter.form.NewFileNoteForm');
00136       $notesForm = new NewFileNoteForm($this->monographFile->getFileId());
00137       $notesForm->readInputData();
00138 
00139       if ($notesForm->validate()) {
00140          $notesForm->execute($request);
00141          $json = new JSONMessage(true);
00142 
00143          // Save to event log
00144          $this->_logEvent($request, MONOGRAPH_LOG_NOTE_POSTED);
00145 
00146          $user =& $request->getUser();
00147          NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedNote')));
00148       } else {
00149          // Return a JSON string indicating failure
00150          $json = new JSONMessage(false);
00151       }
00152 
00153       return $json->getString();
00154    }
00155 
00161    function viewNotify ($args, &$request) {
00162       $this->setupTemplate($request);
00163 
00164       import('controllers.informationCenter.form.InformationCenterNotifyForm');
00165       $notifyForm = new InformationCenterNotifyForm($this->monographFile->getFileId(), ASSOC_TYPE_MONOGRAPH_FILE);
00166       $notifyForm->initData();
00167 
00168       $json = new JSONMessage(true, $notifyForm->fetch($request));
00169       return $json->getString();
00170    }
00171 
00177    function sendNotification ($args, &$request) {
00178       $this->setupTemplate($request);
00179 
00180       import('controllers.informationCenter.form.InformationCenterNotifyForm');
00181       $notifyForm = new InformationCenterNotifyForm($this->monographFile->getFileId(), ASSOC_TYPE_MONOGRAPH_FILE);
00182       $notifyForm->readInputData();
00183 
00184       if ($notifyForm->validate()) {
00185          $noteId = $notifyForm->execute($request);
00186 
00187          $this->_logEvent($request, MONOGRAPH_LOG_MESSAGE_SENT);
00188          $user =& $request->getUser();
00189          NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.sentNotification')));
00190 
00191          // Success--Return a JSON string indicating so (will clear the form on return, and indicate success)
00192          $json = new JSONMessage(true);
00193       } else {
00194          // Failure--Return a JSON string indicating so
00195          $json = new JSONMessage(false);
00196       }
00197 
00198       return $json->getString();
00199    }
00200 
00206    function listHistory($args, &$request) {
00207       $this->setupTemplate($request);
00208 
00209       // Get all monograph file events
00210       $monographFileEventLogDao =& DAORegistry::getDAO('MonographFileEventLogDAO');
00211       $fileEvents =& $monographFileEventLogDao->getByFileId(
00212          $this->monographFile->getFileId()
00213       );
00214 
00215       $templateMgr =& TemplateManager::getManager();
00216       $templateMgr->assign_by_ref('eventLogEntries', $fileEvents);
00217       $templateMgr->assign('historyListId', 'historyList');
00218       return $templateMgr->fetchJson('controllers/informationCenter/historyList.tpl');
00219    }
00220 
00226    function listPastHistory($args, &$request) {
00227       $this->setupTemplate($request);
00228 
00229       $templateMgr =& TemplateManager::getManager();
00230       $monographFileEventLogDao =& DAORegistry::getDAO('MonographFileEventLogDAO');
00231 
00232       $monographFile = $this->monographFile;
00233       $events = array();
00234       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00235       while (true) {
00236          $monographFile = $submissionFileDao->getRevision($monographFile->getSourceFileId(), $monographFile->getSourceRevision());
00237          if (!$monographFile) break;
00238 
00239          $iterator =& $monographFileEventLogDao->getByFileId($monographFile->getFileId());
00240          $events += $iterator->toArray();
00241 
00242          unset($iterator);
00243       }
00244       import('lib.pkp.classes.core.ArrayItemIterator');
00245       $templateMgr->assign('eventLogEntries', new ArrayItemIterator($events));
00246 
00247       $user =& $request->getUser();
00248       $templateMgr->assign('currentUserId', $user->getId());
00249       $templateMgr->assign('historyListId', 'pastHistoryList');
00250       return $templateMgr->fetchJson('controllers/informationCenter/historyList.tpl');
00251    }
00252 
00258    function _logEvent ($request, $eventType) {
00259       // Get the log event message
00260       switch($eventType) {
00261          case MONOGRAPH_LOG_NOTE_POSTED:
00262             $logMessage = 'informationCenter.history.notePosted';
00263             break;
00264          case MONOGRAPH_LOG_MESSAGE_SENT:
00265             $logMessage = 'informationCenter.history.messageSent';
00266             break;
00267          default:
00268             assert(false);
00269       }
00270 
00271       import('classes.log.MonographFileLog');
00272       MonographFileLog::logEvent($request, $this->monographFile, $eventType, $logMessage);
00273    }
00274 
00280    function _getLinkParams() {
00281       return array(
00282          'fileId' => $this->monographFile->getFileId(),
00283          'monographId' => $this->monograph->getId(),
00284          'stageId' => $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE)
00285       );
00286    }
00287 
00292    function _getAssocId() {
00293       return $this->monographFile->getFileId();
00294    }
00295 
00300    function _getAssocType() {
00301       return ASSOC_TYPE_MONOGRAPH_FILE;
00302    }
00303 
00308    function setupTemplate($request) {
00309       // Provide access to notes from past revisions/file IDs
00310       $templateMgr =& TemplateManager::getManager();
00311       $templateMgr->assign('showEarlierEntries', true);
00312 
00313       // Get the latest history item to display in the header
00314       $monographEventLogDao =& DAORegistry::getDAO('MonographFileEventLogDAO');
00315       $fileEvents =& $monographEventLogDao->getByFileId($this->monographFile->getFileId());
00316       $lastEvent =& $fileEvents->next();
00317       if(isset($lastEvent)) {
00318          $templateMgr->assign_by_ref('lastEvent', $lastEvent);
00319 
00320          // Get the user who created the last event.
00321          $userDao =& DAORegistry::getDAO('UserDAO');
00322          $user =& $userDao->getById($lastEvent->getUserId());
00323          $templateMgr->assign_by_ref('lastEventUser', $user);
00324       }
00325 
00326       return parent::setupTemplate($request);
00327    }
00328 }
00329 
00330 ?>

Generated on Mon Sep 17 2012 13:00:01 for Open Monograph Press by  doxygen 1.7.1