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

controllers/listbuilder/users/ChapterAuthorListbuilderHandler.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
00016 
00017 class ChapterAuthorListbuilderHandler extends ListbuilderHandler {
00019    var $_chapterId;
00020 
00024    function ChapterAuthorListbuilderHandler() {
00025       parent::ListbuilderHandler();
00026       $this->addRoleAssignment(
00027          array(ROLE_ID_AUTHOR, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_MANAGER),
00028          array('fetch', 'fetchRow', 'fetchOptions', 'save')
00029       );
00030    }
00031 
00032    //
00033    // Getters/Setters
00034    //
00039    function getMonograph() {
00040       return $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00041    }
00042 
00047    function setChapterId($chapterId) {
00048       $this->_chapterId = $chapterId;
00049    }
00050 
00055    function getChapterId() {
00056       return $this->_chapterId;
00057    }
00058 
00059    //
00060    // Implement template methods from PKPHandler
00061    //
00068    function authorize(&$request, $args, $roleAssignments) {
00069       import('classes.security.authorization.OmpSubmissionAccessPolicy');
00070       $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00071       return parent::authorize($request, $args, $roleAssignments);
00072    }
00073 
00074    /*
00075     * Configure the grid
00076     * @param PKPRequest $request
00077     */
00078    function initialize(&$request) {
00079       parent::initialize($request);
00080 
00081       // Add locale keys
00082       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
00083 
00084       // Basic configuration
00085       $this->setTitle('submission.submit.addAuthor');
00086       $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
00087       $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
00088       $this->setSaveFieldName('authors');
00089 
00090       // Fetch and authorize chapter
00091       $chapterDao =& DAORegistry::getDAO('ChapterDAO');
00092       $monograph =& $this->getMonograph();
00093       $chapter =& $chapterDao->getChapter(
00094          $request->getUserVar('chapterId'),
00095          $monograph->getId()
00096       );
00097       if ($chapter) {
00098          // This is an existing chapter
00099          $this->setChapterId($chapter->getId());
00100       } else {
00101          // This is a new chapter
00102          $this->setChapterId(null);
00103       }
00104 
00105       // Name column
00106       $nameColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
00107       // We can reuse the User cell provider because getFullName
00108       import('controllers.listbuilder.users.UserListbuilderGridCellProvider');
00109       $nameColumn->setCellProvider(new UserListbuilderGridCellProvider());
00110       $this->addColumn($nameColumn);
00111    }
00112 
00116    function initFeatures($request, $args) {
00117       import('lib.pkp.classes.controllers.grid.feature.OrderListbuilderItemsFeature');
00118       return array(new OrderListbuilderItemsFeature());
00119    }
00120 
00124    function getRequestArgs() {
00125       $monograph =& $this->getMonograph();
00126       return array(
00127          'monographId' => $monograph->getId(),
00128          'chapterId' => $this->getChapterId()
00129       );
00130    }
00131 
00137    function getRowDataElement(&$request, $rowId) {
00138       // fallback on the parent if a rowId is found
00139       if ( !empty($rowId) ) {
00140          return parent::getRowDataElement($request, $rowId);
00141       }
00142       $id = 0;
00143       // Otherwise return from the newRowId
00144       $authorId = $this->getNewRowId($request); // this is an array:  Example: $authorId['name'] => 25
00145       if (isset($authorId['name'])) {
00146          $id = (int) $authorId['name'];
00147       }
00148 
00149       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00150       $monograph =& $this->getMonograph();
00151       $author =& $authorDao->getAuthor($id, $monograph->getId());
00152       return $author;
00153    }
00154 
00158    function getOptions() {
00159       // Initialize the object to return
00160       $items = array(
00161          array()
00162       );
00163 
00164       $monograph =& $this->getMonograph();
00165       $authors =& $monograph->getAuthors();
00166 
00167       foreach ($authors as $author) {
00168          $items[0][$author->getId()] = $author->getFullName();
00169       }
00170       unset($authors);
00171 
00172       return $items;
00173    }
00174 
00175 
00176    //
00177    // Public methods
00178    //
00179    /*
00180     * Load the data for the list builder
00181     * @param PKPRequest $request
00182     */
00183    function loadData(&$request, $filter) {
00184       $monograph =& $this->getMonograph();
00185 
00186       // If it's a new chapter, it has no authors.
00187       if (!$this->getChapterId()) return array();
00188 
00189       // Retrieve the contributors associated with this chapter to be displayed in the grid
00190       $chapterAuthorDao =& DAORegistry::getDAO('ChapterAuthorDAO');
00191       $chapterAuthors =& $chapterAuthorDao->getAuthors($monograph->getId(), $this->getChapterId());
00192 
00193       return $chapterAuthors;
00194    }
00195 }
00196 
00197 ?>

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