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

controllers/grid/catalogEntry/PublicationFormatGridHandler.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.PublicationFormatGridCellProvider');
00021 import('controllers.grid.catalogEntry.PublicationFormatGridRow');
00022 
00023 // Link action & modal classes
00024 import('lib.pkp.classes.linkAction.request.AjaxModal');
00025 
00026 class PublicationFormatGridHandler extends GridHandler {
00028    var $_monograph;
00029 
00031    var $_inCatalogEntryModal;
00032 
00036    function PublicationFormatGridHandler() {
00037       parent::GridHandler();
00038       $this->addRoleAssignment(
00039          array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR),
00040          array(
00041             'fetchGrid', 'fetchRow', 'addFormat',
00042             'editFormat', 'updateFormat', 'deleteFormat',
00043             'setAvailable'
00044          )
00045       );
00046    }
00047 
00048 
00049    //
00050    // Getters/Setters
00051    //
00056    function &getMonograph() {
00057       return $this->_monograph;
00058    }
00059 
00064    function setMonograph($monograph) {
00065       $this->_monograph =& $monograph;
00066    }
00067 
00073    function getInCatalogEntryModal() {
00074       return $this->_inCatalogEntryModal;
00075    }
00076 
00077 
00078    //
00079    // Overridden methods from PKPHandler
00080    //
00087    function authorize(&$request, $args, $roleAssignments) {
00088       import('classes.security.authorization.OmpSubmissionAccessPolicy');
00089       $this->addPolicy(new OmpSubmissionAccessPolicy($request, $args, $roleAssignments));
00090       return parent::authorize($request, $args, $roleAssignments);
00091    }
00092 
00093    /*
00094     * Configure the grid
00095     * @param $request PKPRequest
00096     */
00097    function initialize(&$request) {
00098       parent::initialize($request);
00099 
00100       $this->setTitle('monograph.publicationFormats');
00101       $this->setInstructions('editor.monograph.production.publicationFormatDescription');
00102       $this->_inCatalogEntryModal = (boolean) $request->getUserVar('inCatalogEntryModal');
00103 
00104       // Retrieve the authorized monograph.
00105       $this->setMonograph($this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH));
00106 
00107       // Load submission-specific translations
00108       AppLocale::requireComponents(
00109          LOCALE_COMPONENT_OMP_SUBMISSION,
00110          LOCALE_COMPONENT_PKP_SUBMISSION,
00111          LOCALE_COMPONENT_PKP_USER,
00112          LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS,
00113          LOCALE_COMPONENT_OMP_EDITOR
00114       );
00115 
00116       // Grid actions
00117       $router =& $request->getRouter();
00118       $actionArgs = $this->getRequestArgs();
00119       $this->addAction(
00120          new LinkAction(
00121             'addFormat',
00122             new AjaxModal(
00123                $router->url($request, null, null, 'addFormat', null, $actionArgs),
00124                __('grid.action.addFormat'),
00125                'modal_add_item'
00126             ),
00127             __('grid.action.addFormat'),
00128             'add_item'
00129          )
00130       );
00131 
00132       // Columns
00133       $monograph =& $this->getMonograph();
00134       $cellProvider = new PublicationFormatGridCellProvider($monograph->getId(), $this->getInCatalogEntryModal());
00135       $this->addColumn(
00136          new GridColumn(
00137             'name',
00138             'common.name',
00139             null,
00140             'controllers/grid/gridCell.tpl',
00141             $cellProvider,
00142             array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00143          )
00144       );
00145       $this->addColumn(
00146          new GridColumn(
00147             'proofComplete',
00148             'grid.catalogEntry.proof',
00149             null,
00150             'controllers/grid/common/cell/statusCell.tpl',
00151             $cellProvider
00152          )
00153       );
00154       $this->addColumn(
00155          new GridColumn(
00156             'isApproved',
00157             'payment.directSales.catalog',
00158             null,
00159             'controllers/grid/common/cell/statusCell.tpl',
00160             $cellProvider
00161          )
00162       );
00163       $this->addColumn(
00164          new GridColumn(
00165             'isAvailable',
00166             'grid.catalogEntry.isAvailable',
00167             null,
00168             'controllers/grid/common/cell/statusCell.tpl',
00169             $cellProvider
00170          )
00171       );
00172    }
00173 
00174 
00175    //
00176    // Overridden methods from GridHandler
00177    //
00182    function &getRowInstance() {
00183       $monograph =& $this->getMonograph();
00184       $row = new PublicationFormatGridRow($monograph);
00185       return $row;
00186    }
00187 
00193    function getRequestArgs() {
00194       $monograph =& $this->getMonograph();
00195 
00196       return array(
00197          'monographId' => $monograph->getId(),
00198          'inCatalogEntryModal' => $this->getInCatalogEntryModal()
00199       );
00200    }
00201 
00205    function &loadData($request, $filter = null) {
00206       $monograph =& $this->getMonograph();
00207       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00208       $data =& $publicationFormatDao->getByMonographId($monograph->getId());
00209       return $data->toAssociativeArray();
00210    }
00211 
00212 
00213    //
00214    // Public Publication Format Grid Actions
00215    //
00216 
00217    function addFormat($args, $request) {
00218       return $this->editFormat($args, $request);
00219    }
00220 
00227    function editFormat($args, &$request) {
00228       // Identify the format to be updated
00229       $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00230       $monograph =& $this->getMonograph();
00231 
00232       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00233       $publicationFormat = $publicationFormatDao->getById($publicationFormatId);
00234 
00235       // Form handling
00236       import('controllers.grid.catalogEntry.form.PublicationFormatForm');
00237       $publicationFormatForm = new PublicationFormatForm($monograph, $publicationFormat);
00238       $publicationFormatForm->initData();
00239 
00240       $json = new JSONMessage(true, $publicationFormatForm->fetch($request));
00241       return $json->getString();
00242    }
00243 
00250    function updateFormat($args, &$request) {
00251       // Identify the format to be updated
00252       $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00253       $monograph =& $this->getMonograph();
00254 
00255       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00256       $publicationFormat = $publicationFormatDao->getById($publicationFormatId);
00257 
00258       // Form handling
00259       import('controllers.grid.catalogEntry.form.PublicationFormatForm');
00260       $publicationFormatForm = new PublicationFormatForm($monograph, $publicationFormat);
00261       $publicationFormatForm->readInputData();
00262       if ($publicationFormatForm->validate()) {
00263          $publicationFormatId = $publicationFormatForm->execute($request);
00264 
00265          if(!isset($publicationFormat)) {
00266             // This is a new format
00267             $publicationFormat =& $publicationFormatDao->getById($publicationFormatId);
00268             // New added format action notification content.
00269             $notificationContent = __('notification.addedPublicationFormat');
00270          } else {
00271             // Format edit action notification content.
00272             $notificationContent = __('notification.editedPublicationFormat');
00273          }
00274 
00275          // Create trivial notification.
00276          $currentUser =& $request->getUser();
00277          $notificationMgr = new NotificationManager();
00278          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
00279 
00280          // Prepare the grid row data
00281          $row =& $this->getRowInstance();
00282          $row->setGridId($this->getId());
00283          $row->setId($publicationFormatId);
00284          $row->setData($publicationFormat);
00285          $row->initialize($request);
00286 
00287          // Render the row into a JSON response
00288          return DAO::getDataChangedEvent();
00289 
00290       } else {
00291          $json = new JSONMessage(true, $publicationFormatForm->fetch($request));
00292          return $json->getString();
00293       }
00294    }
00295 
00302    function deleteFormat($args, &$request) {
00303       $press =& $request->getPress();
00304       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00305       $publicationFormat =& $publicationFormatDao->getById(
00306          $request->getUserVar('publicationFormatId'),
00307          null, // $pressId
00308          $press->getId() // Make sure to validate the press context
00309       );
00310       $result = false;
00311       if ($publicationFormat) {
00312          $result = $publicationFormatDao->deleteById($publicationFormat->getId());
00313       }
00314 
00315       if ($result) {
00316          // Create a tombstone for this publication format.
00317          import('classes.publicationFormat.PublicationFormatTombstoneManager');
00318          $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
00319          $press =& $request->getPress();
00320          $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press);
00321 
00322          $currentUser =& $request->getUser();
00323          $notificationMgr = new NotificationManager();
00324          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedPublicationFormat')));
00325 
00326          // log the deletion of the format.
00327          import('classes.log.MonographLog');
00328          import('classes.log.MonographEventLogEntry');
00329          MonographLog::logEvent($request, $this->getMonograph(), MONOGRAPH_LOG_PUBLICATION_FORMAT_REMOVE, 'submission.event.publicationFormatRemoved', array('formatName' => $publicationFormat->getLocalizedName()));
00330 
00331          return DAO::getDataChangedEvent();
00332       } else {
00333          $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00334          return $json->getString();
00335       }
00336 
00337    }
00338 
00345    function setAvailable($args, &$request) {
00346       $press =& $request->getPress();
00347       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00348       $publicationFormat =& $publicationFormatDao->getById(
00349          $request->getUserVar('publicationFormatId'),
00350          null, // $monographId
00351          $press->getId() // Make sure to validate the context.
00352       );
00353 
00354       if ($publicationFormat) {
00355          $newAvailableState = (int) $request->getUserVar('newAvailableState');
00356          $publicationFormat->setIsAvailable($newAvailableState);
00357          $publicationFormatDao->updateObject($publicationFormat);
00358 
00359          // log the state changing of the format.
00360          import('classes.log.MonographLog');
00361          import('classes.log.MonographEventLogEntry');
00362          MonographLog::logEvent(
00363             $request, $this->getMonograph(),
00364             $newAvailableState?MONOGRAPH_LOG_PUBLICATION_FORMAT_AVAILABLE:MONOGRAPH_LOG_PUBLICATION_FORMAT_UNAVAILABLE,
00365             $newAvailableState?'submission.event.publicationFormatMadeAvailable':'submission.event.publicationFormatMadeUnavailable',
00366             array('publicationFormatName' => $publicationFormat->getLocalizedName())
00367          );
00368 
00369          // Update the formats tombstones.
00370          import('classes.publicationFormat.PublicationFormatTombstoneManager');
00371          $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
00372 
00373          if ($newAvailableState) {
00374             // Delete any existing tombstone.
00375             $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats(array($publicationFormat));
00376          } else {
00377             // Create a tombstone for this publication format.
00378             $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press);
00379          }
00380 
00381          return DAO::getDataChangedEvent($publicationFormat->getId());
00382       } else {
00383          $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00384          return $json->getString();
00385       }
00386 
00387    }
00388 }
00389 
00390 ?>

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