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

controllers/grid/users/author/AuthorGridHandler.inc.php

00001 <?php
00002 
00015 // import grid base classes
00016 import('lib.pkp.classes.controllers.grid.GridHandler');
00017 
00018 
00019 // import author grid specific classes
00020 import('controllers.grid.users.author.AuthorGridCellProvider');
00021 import('controllers.grid.users.author.AuthorGridRow');
00022 
00023 // Link action & modal classes
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025 
00026 class AuthorGridHandler extends GridHandler {
00028    var $_monograph;
00029 
00031    var $_readOnly;
00032 
00036    function AuthorGridHandler() {
00037       parent::GridHandler();
00038       $this->addRoleAssignment(
00039             array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT, ROLE_ID_AUTHOR),
00040             array('fetchGrid', 'fetchRow', 'addAuthor', 'editAuthor',
00041             'updateAuthor', 'deleteAuthor'));
00042       $this->addRoleAssignment(ROLE_ID_REVIEWER, array('fetchGrid', 'fetchRow'));
00043       $this->addRoleAssignment(array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT), array('addUser'));
00044    }
00045 
00046 
00047    //
00048    // Getters/Setters
00049    //
00054    function &getMonograph() {
00055       return $this->_monograph;
00056    }
00057 
00062    function setMonograph($monograph) {
00063       $this->_monograph =& $monograph;
00064    }
00065 
00070    function getReadOnly() {
00071       return $this->_readOnly;
00072    }
00073 
00078    function setReadOnly($readOnly) {
00079       $this->_readOnly =& $readOnly;
00080    }
00081 
00082 
00083    //
00084    // Overridden methods from PKPHandler
00085    //
00092    function authorize(&$request, $args, $roleAssignments) {
00093       import('classes.security.authorization.OmpSubmissionAccessPolicy');
00094       $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00095       return parent::authorize($request, $args, $roleAssignments);
00096    }
00097 
00098    /*
00099     * Configure the grid
00100     * @param $request PKPRequest
00101     */
00102    function initialize(&$request) {
00103       parent::initialize($request);
00104 
00105       $this->setTitle('submission.contributors');
00106       $this->setInstructions('submission.contributorsDescription');
00107 
00108       // Retrieve the authorized monograph.
00109       $this->setMonograph($this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH));
00110 
00111       // Load submission-specific translations
00112       AppLocale::requireComponents(
00113          LOCALE_COMPONENT_OMP_SUBMISSION,
00114          LOCALE_COMPONENT_PKP_SUBMISSION,
00115          LOCALE_COMPONENT_PKP_USER,
00116          LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS
00117       );
00118 
00119       $monograph =& $this->getMonograph();
00120       $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
00121 
00122       if ($monograph->getDateSubmitted() == null || array_intersect(array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR), $userRoles)) {
00123          $this->setReadOnly(false);
00124          // Grid actions
00125          $router =& $request->getRouter();
00126          $actionArgs = $this->getRequestArgs();
00127          $this->addAction(
00128             new LinkAction(
00129                'addAuthor',
00130                new AjaxModal(
00131                   $router->url($request, null, null, 'addAuthor', null, $actionArgs),
00132                   __('listbuilder.contributors.addContributor'),
00133                   'modal_add_user'
00134                ),
00135                __('listbuilder.contributors.addContributor'),
00136                'add_user'
00137             )
00138          );
00139       } else {
00140          $this->setReadOnly(true);
00141       }
00142 
00143       // Columns
00144       $cellProvider = new AuthorGridCellProvider();
00145       $this->addColumn(
00146          new GridColumn(
00147             'name',
00148             'author.users.contributor.name',
00149             null,
00150             'controllers/grid/gridCell.tpl',
00151             $cellProvider,
00152             array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00153          )
00154       );
00155       $this->addColumn(
00156          new GridColumn(
00157             'email',
00158             'author.users.contributor.email',
00159             null,
00160             'controllers/grid/gridCell.tpl',
00161             $cellProvider
00162          )
00163       );
00164       $this->addColumn(
00165          new GridColumn(
00166             'role',
00167             'author.users.contributor.role',
00168             null,
00169             'controllers/grid/gridCell.tpl',
00170             $cellProvider
00171          )
00172       );
00173       $this->addColumn(
00174          new GridColumn(
00175             'principalContact',
00176             'author.users.contributor.principalContact',
00177             null,
00178             'controllers/grid/users/author/primaryContact.tpl',
00179             $cellProvider
00180          )
00181       );
00182    }
00183 
00184 
00185    //
00186    // Overridden methods from GridHandler
00187    //
00192    function &getRowInstance() {
00193       $monograph =& $this->getMonograph();
00194       $row = new AuthorGridRow($monograph, $this->getReadOnly());
00195       return $row;
00196    }
00197 
00203    function getRequestArgs() {
00204       $monograph =& $this->getMonograph();
00205       return array(
00206          'monographId' => $monograph->getId()
00207       );
00208    }
00209 
00213    function &loadData($request, $filter = null) {
00214       $monograph =& $this->getMonograph();
00215       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00216       $data =& $authorDao->getAuthorsBySubmissionId($monograph->getId(), true);
00217       return $data;
00218    }
00219 
00220    //
00221    // Public Author Grid Actions
00222    //
00228    function addAuthor($args, &$request) {
00229       // Calling editAuthor() with an empty row id will add
00230       // a new author.
00231       return $this->editAuthor($args, $request);
00232    }
00233 
00240    function editAuthor($args, &$request) {
00241       // Identify the author to be updated
00242       $authorId = $request->getUserVar('authorId');
00243       $monograph =& $this->getMonograph();
00244 
00245       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00246       $author = $authorDao->getAuthor($authorId, $monograph->getId());
00247 
00248       // Form handling
00249       import('controllers.grid.users.author.form.AuthorForm');
00250       $authorForm = new AuthorForm($monograph, $author);
00251       $authorForm->initData();
00252 
00253       $json = new JSONMessage(true, $authorForm->fetch($request));
00254       return $json->getString();
00255    }
00256 
00263    function updateAuthor($args, &$request) {
00264       // Identify the author to be updated
00265       $authorId = $request->getUserVar('authorId');
00266       $monograph =& $this->getMonograph();
00267 
00268       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00269       $author =& $authorDao->getAuthor($authorId, $monograph->getId());
00270 
00271       // Form handling
00272       import('controllers.grid.users.author.form.AuthorForm');
00273       $authorForm = new AuthorForm($monograph, $author);
00274       $authorForm->readInputData();
00275       if ($authorForm->validate()) {
00276          $authorId = $authorForm->execute();
00277 
00278          if(!isset($author)) {
00279             // This is a new contributor
00280             $author =& $authorDao->getAuthor($authorId, $monograph->getId());
00281             // New added author action notification content.
00282             $notificationContent = __('notification.addedAuthor');
00283          } else {
00284             // Author edition action notification content.
00285             $notificationContent = __('notification.editedAuthor');
00286          }
00287 
00288          // Create trivial notification.
00289          $currentUser =& $request->getUser();
00290          $notificationMgr = new NotificationManager();
00291          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00292 
00293          // Prepare the grid row data
00294          $row =& $this->getRowInstance();
00295          $row->setGridId($this->getId());
00296          $row->setId($authorId);
00297          $row->setData($author);
00298          $row->initialize($request);
00299 
00300          // Render the row into a JSON response
00301          if($author->getPrimaryContact()) {
00302             // If this is the primary contact, redraw the whole grid
00303             // so that it takes the checkbox off other rows.
00304             return DAO::getDataChangedEvent();
00305          } else {
00306             return DAO::getDataChangedEvent($authorId);
00307          }
00308       } else {
00309          $json = new JSONMessage(true, $authorForm->fetch($request));
00310          return $json->getString();
00311       }
00312    }
00313 
00320    function deleteAuthor($args, &$request) {
00321       // Identify the submission Id
00322       $monographId = $request->getUserVar('monographId');
00323       // Identify the author to be deleted
00324       $authorId = $request->getUserVar('authorId');
00325 
00326       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00327       $result = $authorDao->deleteAuthorById($authorId, $monographId);
00328 
00329       if ($result) {
00330          return DAO::getDataChangedEvent($authorId);
00331       } else {
00332          $json = new JSONMessage(false, __('submission.submit.errorDeletingAuthor'));
00333          return $json->getString();
00334       }
00335    }
00336 
00343    function addUser($args, &$request) {
00344       // Identify the author Id.
00345       $authorId = $request->getUserVar('authorId');
00346 
00347       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00348       $userDao =& DAORegistry::getDAO('UserDAO');
00349       $author =& $authorDao->getAuthor($authorId);
00350 
00351       if ($author !== null && $userDao->userExistsByEmail($author->getEmail())) {
00352          // We don't have administrative rights over this user.
00353          $json = new JSONMessage(false, __('grid.user.cannotAdminister'));
00354       } else {
00355          // Form handling.
00356          import('controllers.grid.settings.user.form.UserDetailsForm');
00357          $userForm = new UserDetailsForm($request, null, $author);
00358          $userForm->initData($args, $request);
00359 
00360          $json = new JSONMessage(true, $userForm->display($args, $request));
00361       }
00362       return $json->getString();
00363    }
00364 }
00365 
00366 ?>

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