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

controllers/grid/catalogEntry/SalesRightsGridHandler.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.SalesRightsGridCellProvider');
00021 import('controllers.grid.catalogEntry.SalesRightsGridRow');
00022 
00023 // Link action & modal classes
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025 
00026 class SalesRightsGridHandler extends GridHandler {
00028    var $_monograph;
00029 
00031    var $_publicationFormat;
00032 
00036    function SalesRightsGridHandler() {
00037       parent::GridHandler();
00038       $this->addRoleAssignment(
00039             array(ROLE_ID_PRESS_MANAGER),
00040             array('fetchGrid', 'fetchRow', 'addRights', 'editRights',
00041             'updateRights', 'deleteRights'));
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       $salesRightsId = (int) $request->getUserVar('salesRightsId'); // set if editing or deleting a sales rights entry
00109 
00110       if ($salesRightsId != '') {
00111          $salesRightsDao =& DAORegistry::getDAO('SalesRightsDAO');
00112          $salesRights =& $salesRightsDao->getById($salesRightsId, $this->getMonograph()->getId());
00113          if ($salesRights) {
00114             $publicationFormatId =& $salesRights->getPublicationFormatId();
00115          }
00116       } else { // empty form for new SalesRights
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.salesRights');
00139 
00140       // Grid actions
00141       $router =& $request->getRouter();
00142       $actionArgs = $this->getRequestArgs();
00143       $this->addAction(
00144          new LinkAction(
00145             'addRights',
00146             new AjaxModal(
00147                $router->url($request, null, null, 'addRights', null, $actionArgs),
00148                __('grid.action.addRights'),
00149                'modal_add_item'
00150             ),
00151             __('grid.action.addRights'),
00152             'add_item'
00153          )
00154       );
00155 
00156       // Columns
00157       $cellProvider = new SalesRightsGridCellProvider();
00158       $this->addColumn(
00159          new GridColumn(
00160             'type',
00161             'grid.catalogEntry.salesRightsType',
00162             null,
00163             'controllers/grid/gridCell.tpl',
00164             $cellProvider
00165          )
00166       );
00167       $this->addColumn(
00168          new GridColumn(
00169             'ROW',
00170             'grid.catalogEntry.salesRightsROW',
00171             null,
00172             'controllers/grid/common/cell/checkMarkCell.tpl',
00173             $cellProvider
00174          )
00175       );
00176    }
00177 
00178 
00179    //
00180    // Overridden methods from GridHandler
00181    //
00186    function &getRowInstance() {
00187       $row = new SalesRightsGridRow($this->getMonograph());
00188       return $row;
00189    }
00190 
00196    function getRequestArgs() {
00197       $monograph =& $this->getMonograph();
00198       $publicationFormat =& $this->getPublicationFormat();
00199 
00200       return array(
00201          'monographId' => $monograph->getId(),
00202          'publicationFormatId' => $publicationFormat->getId()
00203       );
00204    }
00205 
00209    function &loadData($request, $filter = null) {
00210       $publicationFormat =& $this->getPublicationFormat();
00211       $salesRightsDao =& DAORegistry::getDAO('SalesRightsDAO');
00212       $data =& $salesRightsDao->getByPublicationFormatId($publicationFormat->getId());
00213       return $data->toArray();
00214    }
00215 
00216 
00217    //
00218    // Public Sales Rights Grid Actions
00219    //
00220 
00221    function addRights($args, $request) {
00222       return $this->editRights($args, $request);
00223    }
00224 
00231    function editRights($args, &$request) {
00232       // Identify the sales rights entry to be updated
00233       $salesRightsId = (int) $request->getUserVar('salesRightsId');
00234       $monograph =& $this->getMonograph();
00235 
00236       $salesRightsDao =& DAORegistry::getDAO('SalesRightsDAO');
00237       $salesRights = $salesRightsDao->getById($salesRightsId, $monograph->getId());
00238 
00239       // Form handling
00240       import('controllers.grid.catalogEntry.form.SalesRightsForm');
00241       $salesRightsForm = new SalesRightsForm($monograph, $salesRights);
00242       $salesRightsForm->initData();
00243 
00244       $json = new JSONMessage(true, $salesRightsForm->fetch($request));
00245       return $json->getString();
00246    }
00247 
00254    function updateRights($args, &$request) {
00255       // Identify the sales rights entry to be updated
00256       $salesRightsId = $request->getUserVar('salesRightsId');
00257       $monograph =& $this->getMonograph();
00258 
00259       $salesRightsDao =& DAORegistry::getDAO('SalesRightsDAO');
00260       $salesRights = $salesRightsDao->getById($salesRightsId, $monograph->getId());
00261 
00262       // Form handling
00263       import('controllers.grid.catalogEntry.form.SalesRightsForm');
00264       $salesRightsForm = new SalesRightsForm($monograph, $salesRights);
00265       $salesRightsForm->readInputData();
00266       if ($salesRightsForm->validate()) {
00267          $salesRightsId = $salesRightsForm->execute();
00268 
00269          if(!isset($salesRights)) {
00270             // This is a new entry
00271             $salesRights =& $salesRightsDao->getById($salesRightsId, $monograph->getId());
00272             // New added entry action notification content.
00273             $notificationContent = __('notification.addedSalesRights');
00274          } else {
00275             // entry edit action notification content.
00276             $notificationContent = __('notification.editedSalesRights');
00277          }
00278 
00279          // Create trivial notification.
00280          $currentUser =& $request->getUser();
00281          $notificationMgr = new NotificationManager();
00282          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00283 
00284          // Prepare the grid row data
00285          $row =& $this->getRowInstance();
00286          $row->setGridId($this->getId());
00287          $row->setId($salesRightsId);
00288          $row->setData($salesRights);
00289          $row->initialize($request);
00290 
00291          // Render the row into a JSON response
00292          return DAO::getDataChangedEvent();
00293 
00294       } else {
00295          $json = new JSONMessage(true, $salesRightsForm->fetch($request));
00296          return $json->getString();
00297       }
00298    }
00299 
00306    function deleteRights($args, &$request) {
00307 
00308       // Identify the sales rights entry to be deleted
00309       $salesRightsId = $request->getUserVar('salesRightsId');
00310 
00311       $salesRightsDao =& DAORegistry::getDAO('SalesRightsDAO');
00312       $salesRights =& $salesRightsDao->getById($salesRightsId, $this->getMonograph()->getId());
00313       if ($salesRights != null) { // authorized
00314 
00315          $result = $salesRightsDao->deleteObject($salesRights);
00316 
00317          if ($result) {
00318             $currentUser =& $request->getUser();
00319             $notificationMgr = new NotificationManager();
00320             $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedSalesRights')));
00321             return DAO::getDataChangedEvent();
00322          } else {
00323             $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00324             return $json->getString();
00325          }
00326       }
00327    }
00328 }
00329 
00330 ?>

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