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

controllers/informationCenter/SubmissionInformationCenterHandler.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 SubmissionInformationCenterHandler extends InformationCenterHandler {
00021    var $_monograph;
00022 
00026    function SubmissionInformationCenterHandler() {
00027       parent::InformationCenterHandler();
00028    }
00029 
00033    function initialize(&$request, $args = null) {
00034       parent::initialize($request, $args);
00035 
00036       // Fetch the monograph to display information about
00037       $this->_monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00038    }
00039 
00045    function metadata($args, &$request) {
00046       $this->setupTemplate($request);
00047 
00048       import('controllers.modals.submissionMetadata.form.SubmissionMetadataViewForm');
00049       // prevent anyone but managers and editors from submitting the catalog entry form
00050       $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
00051       $params = array();
00052       if (!array_intersect(array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR), $userRoles)) {
00053          $params['hideSubmit'] = true;
00054          $params['readOnly'] = true;
00055       }
00056       $submissionMetadataViewForm = new SubmissionMetadataViewForm($this->_monograph->getId(), null, $params);
00057       $submissionMetadataViewForm->initData($args, $request);
00058 
00059       $json = new JSONMessage(true, $submissionMetadataViewForm->fetch($request));
00060       return $json->getString();
00061    }
00062 
00068    function saveForm($args, &$request) {
00069       $this->setupTemplate($request);
00070 
00071       import('controllers.modals.submissionMetadata.form.SubmissionMetadataViewForm');
00072       $submissionMetadataViewForm = new SubmissionMetadataViewForm($this->_monograph->getId());
00073 
00074       $json = new JSONMessage();
00075 
00076       // Try to save the form data.
00077       $submissionMetadataViewForm->readInputData($request);
00078       if($submissionMetadataViewForm->validate()) {
00079          $submissionMetadataViewForm->execute($request);
00080          // Create trivial notification.
00081          $notificationManager = new NotificationManager();
00082          $user =& $request->getUser();
00083          $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.savedSubmissionMetadata')));
00084       } else {
00085          $json->setStatus(false);
00086       }
00087 
00088       return $json->getString();
00089    }
00090 
00096    function viewInformationCenter($args, &$request) {
00097       // Get the latest history item to display in the header
00098       $monographEventLogDao =& DAORegistry::getDAO('MonographEventLogDAO');
00099       $monographEvents =& $monographEventLogDao->getByMonographId($this->_monograph->getId());
00100       $lastEvent =& $monographEvents->next();
00101 
00102       // Assign variables to the template manager and display
00103       $templateMgr =& TemplateManager::getManager();
00104       if(isset($lastEvent)) {
00105          $templateMgr->assign_by_ref('lastEvent', $lastEvent);
00106 
00107          // Get the user who posted the last note
00108          $userDao =& DAORegistry::getDAO('UserDAO');
00109          $user =& $userDao->getById($lastEvent->getUserId());
00110          $templateMgr->assign_by_ref('lastEventUser', $user);
00111       }
00112 
00113       return parent::viewInformationCenter($request);
00114    }
00115 
00121    function viewNotes($args, &$request) {
00122       $this->setupTemplate($request);
00123 
00124       import('controllers.informationCenter.form.NewMonographNoteForm');
00125       $notesForm = new NewMonographNoteForm($this->_monograph->getId());
00126       $notesForm->initData();
00127 
00128       $json = new JSONMessage(true, $notesForm->fetch($request));
00129       return $json->getString();
00130    }
00131 
00137    function saveNote($args, &$request) {
00138       $this->setupTemplate($request);
00139 
00140       import('controllers.informationCenter.form.NewMonographNoteForm');
00141       $notesForm = new NewMonographNoteForm($this->_monograph->getId());
00142       $notesForm->readInputData();
00143 
00144       if ($notesForm->validate()) {
00145          $notesForm->execute($request);
00146          $json = new JSONMessage(true);
00147 
00148          // Save to event log
00149          $user =& $request->getUser();
00150          $userId = $user->getId();
00151          $this->_logEvent($request, MONOGRAPH_LOG_NOTE_POSTED);
00152       } else {
00153          // Return a JSON string indicating failure
00154          $json = new JSONMessage(false);
00155       }
00156 
00157       return $json->getString();
00158    }
00159 
00165    function viewNotify($args, &$request) {
00166       $this->setupTemplate($request);
00167 
00168       import('controllers.informationCenter.form.InformationCenterNotifyForm');
00169       $notifyForm = new InformationCenterNotifyForm($this->_monograph->getId(), ASSOC_TYPE_MONOGRAPH);
00170       $notifyForm->initData();
00171 
00172       $json = new JSONMessage(true, $notifyForm->fetch($request));
00173       return $json->getString();
00174    }
00175 
00181    function fetchTemplateBody($args, &$request) {
00182       $templateId = $request->getUserVar('template');
00183       import('classes.mail.MonographMailTemplate');
00184       $template = new MonographMailTemplate($this->_monograph, $templateId);
00185       if ($template) {
00186          $user =& $request->getUser();
00187          $dispatcher =& $request->getDispatcher();
00188          $press =& $request->getPress();
00189          $template->assignParams(array(
00190             'pressUrl' => $dispatcher->url($request, ROUTE_PAGE, $press->getPath()),
00191             'editorialContactSignature' => $user->getContactSignature(),
00192             'signatureFullName' => $user->getFullname(),
00193          ));
00194 
00195          $json = new JSONMessage(true, $template->getBody() . "\n" . $press->getSetting('emailSignature'));
00196          return $json->getString();
00197       }
00198    }
00199 
00205    function sendNotification ($args, &$request) {
00206       $this->setupTemplate($request);
00207 
00208       import('controllers.informationCenter.form.InformationCenterNotifyForm');
00209       $notifyForm = new InformationCenterNotifyForm($this->_monograph->getId(), ASSOC_TYPE_MONOGRAPH);
00210       $notifyForm->readInputData();
00211 
00212       if ($notifyForm->validate()) {
00213          $noteId = $notifyForm->execute($request);
00214          // Return a JSON string indicating success
00215          // (will clear the form on return)
00216          $json = new JSONMessage(true);
00217 
00218          $this->_logEvent($request, MONOGRAPH_LOG_MESSAGE_SENT);
00219          // Create trivial notification.
00220          $currentUser =& $request->getUser();
00221          $notificationMgr = new NotificationManager();
00222          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('informationCenter.history.messageSent')));
00223       } else {
00224          // Return a JSON string indicating failure
00225          $json = new JSONMessage(false);
00226       }
00227 
00228       return $json->getString();
00229    }
00230 
00236    function listHistory($args, &$request) {
00237       $this->setupTemplate($request);
00238       $templateMgr =& TemplateManager::getManager();
00239 
00240       // Get all monograph events
00241       $monographEventLogDao =& DAORegistry::getDAO('MonographEventLogDAO');
00242       $monographEvents =& $monographEventLogDao->getByMonographId($this->_monograph->getId());
00243       $templateMgr->assign_by_ref('eventLogEntries', $monographEvents);
00244       $templateMgr->assign('historyListId', 'historyList');
00245       return $templateMgr->fetchJson('controllers/informationCenter/historyList.tpl');
00246    }
00247 
00253    function _logEvent ($request, $eventType) {
00254       // Get the log event message
00255       switch($eventType) {
00256          case MONOGRAPH_LOG_NOTE_POSTED:
00257             $logMessage = 'informationCenter.history.notePosted';
00258             break;
00259          case MONOGRAPH_LOG_MESSAGE_SENT:
00260             $logMessage = 'informationCenter.history.messageSent';
00261             break;
00262          default:
00263             assert(false);
00264       }
00265 
00266       import('classes.log.MonographLog');
00267       MonographLog::logEvent($request, $this->_monograph, $eventType, $logMessage);
00268    }
00269 
00275    function _getLinkParams() {
00276       return array('monographId' => $this->_monograph->getId());
00277    }
00278 
00283    function _getAssocId() {
00284       return $this->_monograph->getId();
00285    }
00286 
00291    function _getAssocType() {
00292       return ASSOC_TYPE_MONOGRAPH;
00293    }
00294 }
00295 
00296 ?>

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