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

controllers/grid/catalogEntry/PublicationDateGridHandler.inc.php

00001 <?php
00002 
00015 // import grid base classes
00016 import('lib.pkp.classes.controllers.grid.GridHandler');
00017 
00018 
00019 // import format grid specific classes
00020 import('controllers.grid.catalogEntry.PublicationDateGridCellProvider');
00021 import('controllers.grid.catalogEntry.PublicationDateGridRow');
00022 
00023 // Link action & modal classes
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025 
00026 class PublicationDateGridHandler extends GridHandler {
00028    var $_monograph;
00029 
00031    var $_publicationFormat;
00032 
00036    function PublicationDateGridHandler() {
00037       parent::GridHandler();
00038       $this->addRoleAssignment(
00039             array(ROLE_ID_PRESS_MANAGER),
00040             array('fetchGrid', 'fetchRow', 'addDate', 'editDate',
00041             'updateDate', 'deleteDate'));
00042    }
00043 
00044 
00045    //
00046    // Getters/Setters
00047    //
00052    function &getMonograph() {
00053       return $this->_monograph;
00054    }
00055 
00060    function setMonograph($monograph) {
00061       $this->_monograph =& $monograph;
00062    }
00063 
00068    function &getPublicationFormat() {
00069       return $this->_publicationFormat;
00070    }
00071 
00076    function setPublicationFormat($publicationFormat) {
00077       $this->_publicationFormat =& $publicationFormat;
00078    }
00079 
00080    //
00081    // Overridden methods from PKPHandler
00082    //
00089    function authorize(&$request, $args, $roleAssignments) {
00090       import('classes.security.authorization.OmpSubmissionAccessPolicy');
00091       $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00092       return parent::authorize($request, $args, $roleAssignments);
00093    }
00094 
00095    /*
00096     * Configure the grid
00097     * @param $request PKPRequest
00098     */
00099    function initialize(&$request) {
00100       parent::initialize($request);
00101 
00102       // Retrieve the authorized monograph.
00103       $this->setMonograph($this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH));
00104       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00105       $publicationFormatId = null;
00106 
00107       // Retrieve the associated publication format for this grid.
00108       $publicationDateId = (int) $request->getUserVar('publicationDateId'); // set if editing or deleting a date
00109 
00110       if ($publicationDateId != '') {
00111          $publicationDateDao =& DAORegistry::getDAO('PublicationDateDAO');
00112          $publicationDate =& $publicationDateDao->getById($publicationDateId, $this->getMonograph()->getId());
00113          if ($publicationDate) {
00114             $publicationFormatId =& $publicationDate->getPublicationFormatId();
00115          }
00116       } else { // empty form for new Date
00117          $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00118       }
00119 
00120       $monograph =& $this->getMonograph();
00121       $publicationFormat =& $publicationFormatDao->getById($publicationFormatId, $monograph->getId());
00122 
00123       if ($publicationFormat) {
00124          $this->setPublicationFormat($publicationFormat);
00125       } else {
00126          fatalError('The publication format is not assigned to authorized monograph!');
00127       }
00128 
00129       // Load submission-specific translations
00130       AppLocale::requireComponents(
00131          LOCALE_COMPONENT_OMP_SUBMISSION,
00132          LOCALE_COMPONENT_PKP_SUBMISSION,
00133          LOCALE_COMPONENT_PKP_USER,
00134          LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS
00135       );
00136 
00137       // Basic grid configuration
00138       $this->setTitle('grid.catalogEntry.publicationDates');
00139 
00140       // Grid actions
00141       $router =& $request->getRouter();
00142       $actionArgs = $this->getRequestArgs();
00143       $this->addAction(
00144          new LinkAction(
00145             'addDate',
00146             new AjaxModal(
00147                $router->url($request, null, null, 'addDate', null, $actionArgs),
00148                __('grid.action.addDate'),
00149                'modal_add_item'
00150             ),
00151             __('grid.action.addDate'),
00152             'add_item'
00153          )
00154       );
00155 
00156       // Columns
00157       $cellProvider = new PublicationDateGridCellProvider();
00158       $this->addColumn(
00159          new GridColumn(
00160             'value',
00161             'grid.catalogEntry.dateValue',
00162             null,
00163             'controllers/grid/gridCell.tpl',
00164             $cellProvider,
00165             array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00166          )
00167       );
00168       $this->addColumn(
00169          new GridColumn(
00170             'code',
00171             'grid.catalogEntry.dateRole',
00172             null,
00173             'controllers/grid/gridCell.tpl',
00174             $cellProvider
00175          )
00176       );
00177    }
00178 
00179 
00180    //
00181    // Overridden methods from GridHandler
00182    //
00187    function &getRowInstance() {
00188       $row = new PublicationDateGridRow($this->getMonograph());
00189       return $row;
00190    }
00191 
00197    function getRequestArgs() {
00198       $monograph =& $this->getMonograph();
00199       $publicationFormat =& $this->getPublicationFormat();
00200 
00201       return array(
00202          'monographId' => $monograph->getId(),
00203          'publicationFormatId' => $publicationFormat->getId()
00204       );
00205    }
00206 
00210    function &loadData($request, $filter = null) {
00211       $publicationFormat =& $this->getPublicationFormat();
00212       $publicationDateDao =& DAORegistry::getDAO('PublicationDateDAO');
00213       $data =& $publicationDateDao->getByPublicationFormatId($publicationFormat->getId());
00214       return $data->toArray();
00215    }
00216 
00217 
00218    //
00219    // Public Date Grid Actions
00220    //
00221 
00222    function addDate($args, $request) {
00223       return $this->editDate($args, $request);
00224    }
00225 
00232    function editDate($args, &$request) {
00233       // Identify the date to be updated
00234       $publicationDateId = (int) $request->getUserVar('publicationDateId');
00235       $monograph =& $this->getMonograph();
00236 
00237       $publicationDateDao =& DAORegistry::getDAO('PublicationDateDAO');
00238       $publicationDate = $publicationDateDao->getById($publicationDateId, $monograph->getId());
00239 
00240       // Form handling
00241       import('controllers.grid.catalogEntry.form.PublicationDateForm');
00242       $publicationDateForm = new PublicationDateForm($monograph, $publicationDate);
00243       $publicationDateForm->initData();
00244 
00245       $json = new JSONMessage(true, $publicationDateForm->fetch($request));
00246       return $json->getString();
00247    }
00248 
00255    function updateDate($args, &$request) {
00256       // Identify the code to be updated
00257       $publicationDateId = $request->getUserVar('publicationDateId');
00258       $monograph =& $this->getMonograph();
00259 
00260       $publicationDateDao =& DAORegistry::getDAO('PublicationDateDAO');
00261       $publicationDate = $publicationDateDao->getById($publicationDateId, $monograph->getId());
00262 
00263       // Form handling
00264       import('controllers.grid.catalogEntry.form.PublicationDateForm');
00265       $publicationDateForm = new PublicationDateForm($monograph, $publicationDate);
00266       $publicationDateForm->readInputData();
00267       if ($publicationDateForm->validate()) {
00268          $publicationDateId = $publicationDateForm->execute();
00269 
00270          if(!isset($publicationDate)) {
00271             // This is a new code
00272             $publicationDate =& $publicationDateDao->getById($publicationDateId, $monograph->getId());
00273             // New added code action notification content.
00274             $notificationContent = __('notification.addedPublicationDate');
00275          } else {
00276             // code edit action notification content.
00277             $notificationContent = __('notification.editedPublicationDate');
00278          }
00279 
00280          // Create trivial notification.
00281          $currentUser =& $request->getUser();
00282          $notificationMgr = new NotificationManager();
00283          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00284 
00285          // Prepare the grid row data
00286          $row =& $this->getRowInstance();
00287          $row->setGridId($this->getId());
00288          $row->setId($publicationDateId);
00289          $row->setData($publicationDate);
00290          $row->initialize($request);
00291 
00292          // Render the row into a JSON response
00293          return DAO::getDataChangedEvent();
00294 
00295       } else {
00296          $json = new JSONMessage(true, $publicationDateForm->fetch($request));
00297          return $json->getString();
00298       }
00299    }
00300 
00307    function deleteDate($args, &$request) {
00308 
00309       // Identify the code to be deleted
00310       $publicationDateId = $request->getUserVar('publicationDateId');
00311 
00312       $publicationDateDao =& DAORegistry::getDAO('PublicationDateDAO');
00313       $publicationDate =& $publicationDateDao->getById($publicationDateId, $this->getMonograph()->getId());
00314       if ($publicationDate != null) { // authorized
00315 
00316          $result = $publicationDateDao->deleteObject($publicationDate);
00317 
00318          if ($result) {
00319             $currentUser =& $request->getUser();
00320             $notificationMgr = new NotificationManager();
00321             $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedPublicationDate')));
00322             return DAO::getDataChangedEvent();
00323          } else {
00324             $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00325             return $json->getString();
00326          }
00327       }
00328    }
00329 }
00330 
00331 ?>

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