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

controllers/informationCenter/InformationCenterHandler.inc.php

00001 <?php
00002 
00015 import('classes.handler.Handler');
00016 import('lib.pkp.classes.core.JSONMessage');
00017 import('classes.log.MonographEventLogEntry');
00018 
00019 class InformationCenterHandler extends Handler {
00023    function InformationCenterHandler() {
00024       parent::Handler();
00025 
00026       // Author can do everything except delete notes.
00027       // (Review-related log entries are hidden from the author, but
00028       // that's not implemented here.)
00029       $this->addRoleAssignment(
00030          array(ROLE_ID_AUTHOR),
00031          $authorOps = array(
00032             'viewInformationCenter', // Information Center
00033             'fetchTemplateBody', // Notify tab
00034             'metadata', 'saveForm', // Metadata
00035             'viewNotes', 'listNotes', 'saveNote', // Notes
00036             'viewNotify', 'sendNotification', // Notify tab
00037             'viewHistory', 'listHistory', // History tab
00038          )
00039       );
00040       $this->addRoleAssignment(
00041          array(ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_MANAGER, ROLE_ID_PRESS_ASSISTANT),
00042          array_merge($authorOps, array(
00043             'deleteNote' // Notes tab
00044          ))
00045       );
00046    }
00047 
00048 
00049    //
00050    // Implement template methods from PKPHandler.
00051    //
00058    function authorize(&$request, $args, $roleAssignments) {
00059       import('classes.security.authorization.OmpSubmissionAccessPolicy');
00060       $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00061       return parent::authorize($request, $args, $roleAssignments);
00062    }
00063 
00064 
00065    //
00066    // Public operations
00067    //
00072    function viewInformationCenter(&$request) {
00073       $this->setupTemplate($request);
00074       $templateMgr =& TemplateManager::getManager();
00075       return $templateMgr->fetchJson('controllers/informationCenter/informationCenter.tpl');
00076    }
00077 
00083    function metadata($args, &$request) {
00084       assert(false);
00085    }
00086 
00092    function saveForm($args, &$request) {
00093       assert(false);
00094    }
00095 
00100    function viewNotes($args, &$request) {
00101       assert(false);
00102    }
00103 
00110    function saveNote($args, &$request) {
00111       assert(false);
00112    }
00113 
00119    function listNotes($args, &$request) {
00120       $this->setupTemplate($request);
00121 
00122       $templateMgr =& TemplateManager::getManager();
00123       $noteDao =& DAORegistry::getDAO('NoteDAO');
00124       $templateMgr->assign('notes', $noteDao->getByAssoc($this->_getAssocType(), $this->_getAssocId()));
00125 
00126       $user =& $request->getUser();
00127       $templateMgr->assign('currentUserId', $user->getId());
00128       $templateMgr->assign('notesDeletable', true);
00129 
00130       $templateMgr->assign('notesListId', 'notesList');
00131       $json = new JSONMessage(true, $templateMgr->fetch('controllers/informationCenter/notesList.tpl'));
00132       $json->setEvent('dataChanged');
00133       return $json->getString();
00134    }
00135 
00141    function deleteNote($args, &$request) {
00142       $this->setupTemplate($request);
00143 
00144       $noteId = (int) $request->getUserVar('noteId');
00145       $noteDao =& DAORegistry::getDAO('NoteDAO');
00146       $note =& $noteDao->getById($noteId);
00147       if (!$note || $note->getAssocType() != $this->_getAssocType() || $note->getAssocId() != $this->_getAssocId()) fatalError('Invalid note!');
00148       $noteDao->deleteById($noteId);
00149 
00150       $user =& $request->getUser();
00151       NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedNote')));
00152 
00153       $json = new JSONMessage(true);
00154       return $json->getString();
00155    }
00156 
00163    function viewNotify ($args, &$request) {
00164       assert(false);
00165    }
00166 
00173    function sendNotification ($args, &$request) {
00174       assert(false);
00175    }
00176 
00182    function viewHistory($args, &$request) {
00183       $this->setupTemplate($request);
00184 
00185       $templateMgr =& TemplateManager::getManager();
00186       return $templateMgr->fetchJson('controllers/informationCenter/history.tpl');
00187    }
00188 
00195    function listHistory($args, &$request) {
00196       assert(false);
00197    }
00198 
00205    function _logEvent ($itemId, $eventType, $userId) {
00206       assert(false);
00207    }
00208 
00214    function _getLinkParams() {
00215       assert(false);
00216    }
00217 
00218    function setupTemplate(&$request) {
00219       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
00220 
00221       $linkParams = $this->_getLinkParams();
00222       $templateMgr =& TemplateManager::getManager();
00223 
00224       // Preselect tab from keywords 'notes', 'notify', 'history'
00225       switch ($request->getUserVar('tab')) {
00226          case 'history':
00227             $templateMgr->assign('selectedTabIndex', 2);
00228             break;
00229          case 'notify':
00230             $userId = (int) $request->getUserVar('userId');
00231             if ($userId) {
00232                $linkParams['userId'] = $userId; // user validated in Listbuilder.
00233             }
00234             $templateMgr->assign('selectedTabIndex', 1);
00235             break;
00236          // notes is default
00237          default:
00238             $templateMgr->assign('selectedTabIndex', 0);
00239             break;
00240       }
00241 
00242       $templateMgr->assign('linkParams', $linkParams);
00243       parent::setupTemplate($request);
00244    }
00245 
00250    function _getAssocId() {
00251       assert(false);
00252    }
00253 
00258    function _getAssocType() {
00259       assert(false);
00260    }
00261 }
00262 
00263 ?>

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