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

controllers/grid/admin/press/PressGridHandler.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.controllers.grid.GridHandler');
00016 
00017 import('controllers.grid.admin.press.PressGridRow');
00018 import('controllers.grid.admin.press.form.PressSiteSettingsForm');
00019 
00020 class PressGridHandler extends GridHandler {
00024    function PressGridHandler() {
00025       parent::GridHandler();
00026       $this->addRoleAssignment(array(
00027          ROLE_ID_SITE_ADMIN),
00028          array('fetchGrid', 'fetchRow', 'createPress', 'editPress', 'updatePress',
00029             'deletePress', 'saveSequence')
00030       );
00031    }
00032 
00033 
00034    //
00035    // Implement template methods from PKPHandler.
00036    //
00040    function authorize(&$request, $args, $roleAssignments) {
00041       import('lib.pkp.classes.security.authorization.PolicySet');
00042       $rolePolicy = new PolicySet(COMBINING_PERMIT_OVERRIDES);
00043 
00044       import('lib.pkp.classes.security.authorization.RoleBasedHandlerOperationPolicy');
00045       foreach($roleAssignments as $role => $operations) {
00046          $rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
00047       }
00048       $this->addPolicy($rolePolicy);
00049 
00050       return parent::authorize($request, $args, $roleAssignments);
00051    }
00052 
00056    function initialize(&$request) {
00057       parent::initialize($request);
00058 
00059       // Load user-related translations.
00060       AppLocale::requireComponents(
00061          LOCALE_COMPONENT_PKP_USER,
00062          LOCALE_COMPONENT_OMP_ADMIN,
00063          LOCALE_COMPONENT_OMP_MANAGER,
00064          LOCALE_COMPONENT_APPLICATION_COMMON
00065       );
00066 
00067       // Basic grid configuration.
00068       $this->setTitle('press.presses');
00069 
00070       // Grid actions.
00071       $router =& $request->getRouter();
00072 
00073       import('lib.pkp.classes.linkAction.request.AjaxModal');
00074       $this->addAction(
00075          new LinkAction(
00076             'createPress',
00077             new AjaxModal(
00078                $router->url($request, null, null, 'createPress', null, null),
00079                __('admin.presses.addPress'),
00080                'modal_add_item',
00081                true
00082                ),
00083             __('admin.presses.addPress'),
00084             'add_item')
00085       );
00086 
00087       //
00088       // Grid columns.
00089       //
00090       import('controllers.grid.admin.press.PressGridCellProvider');
00091       $pressGridCellProvider = new PressGridCellProvider();
00092 
00093       // Press name.
00094       $this->addColumn(
00095          new GridColumn(
00096             'name',
00097             'manager.setup.pressName',
00098             null,
00099             'controllers/grid/gridCell.tpl',
00100             $pressGridCellProvider
00101          )
00102       );
00103 
00104       // Press path.
00105       $this->addColumn(
00106          new GridColumn(
00107             'path',
00108             'press.path',
00109             null,
00110             'controllers/grid/gridCell.tpl',
00111             $pressGridCellProvider
00112          )
00113       );
00114    }
00115 
00116 
00117    //
00118    // Implement methods from GridHandler.
00119    //
00124    function &getRowInstance() {
00125       $row = new PressGridRow();
00126       return $row;
00127    }
00128 
00134    function loadData(&$request) {
00135       // Get all presses.
00136       $pressDao =& DAORegistry::getDAO('PressDAO');
00137       $presses =& $pressDao->getPresses();
00138 
00139       return $presses->toAssociativeArray('pressId');
00140    }
00141 
00145    function getRowDataElementSequence(&$press) {
00146       return $press->getSequence();
00147    }
00148 
00152    function saveRowDataElementSequence(&$request, $rowId, &$press, $newSequence) {
00153       $pressDao = DAORegistry::getDAO('PressDAO'); /* @var $pressDao PressDAO */
00154       $press->setSequence($newSequence);
00155       $pressDao->updateObject($press);
00156    }
00157 
00161    function initFeatures($request, $args) {
00162       import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
00163       return array(new OrderGridItemsFeature());
00164    }
00165 
00171    function getPublishChangeEvents() {
00172       return array('updateHeader');
00173    }
00174 
00175 
00176    //
00177    // Public grid actions.
00178    //
00184    function createPress($args, &$request) {
00185       // Calling editPress with an empty row id will add a new press.
00186       return $this->editPress($args, $request);
00187    }
00188 
00195    function editPress($args, &$request) {
00196 
00197       // Identify the press Id.
00198       $pressId = $request->getUserVar('rowId');
00199 
00200       // Form handling.
00201       $settingsForm = new PressSiteSettingsForm(!isset($pressId) || empty($pressId) ? null : $pressId);
00202       $settingsForm->initData();
00203       $json = new JSONMessage(true, $settingsForm->fetch($args, $request));
00204 
00205       return $json->getString();
00206    }
00207 
00214    function updatePress($args, &$request) {
00215       // Identify the press Id.
00216       $pressId = $request->getUserVar('pressId');
00217 
00218       // Form handling.
00219       $settingsForm = new PressSiteSettingsForm($pressId);
00220       $settingsForm->readInputData();
00221 
00222       if ($settingsForm->validate()) {
00223          PluginRegistry::loadCategory('blocks');
00224 
00225          // The press settings form will return a press path in two cases:
00226          // 1 - if a new press was created;
00227          // 2 - if a press path of an existing press was edited.
00228          $newPressPath = $settingsForm->execute($request);
00229 
00230          // Create the notification.
00231          $notificationMgr = new NotificationManager();
00232          $user =& $request->getUser();
00233          $notificationMgr->createTrivialNotification($user->getId());
00234 
00235          // Check for the two cases above.
00236          if ($newPressPath) {
00237             $context = $request->getContext();
00238 
00239             if (is_null($pressId)) {
00240                // CASE 1: new press created.
00241                // Create notification related to payment method configuration.
00242                $pressDao =& DAORegistry::getDAO('PressDAO');
00243                $newPress =& $pressDao->getByPath($newPressPath);
00244                $notificationMgr->createNotification($request, null, NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD,
00245                   $newPress->getId(), ASSOC_TYPE_PRESS, $newPress->getId(), NOTIFICATION_LEVEL_NORMAL);
00246 
00247                // redirect and set the parameter to open the press
00248                // setting wizard modal after redirection.
00249                return $this->_getRedirectEvent(&$request, $newPressPath, true);
00250             } else {
00251                // CASE 2: check if user is in the context of
00252                // the press being edited.
00253                if ($context->getId() == $pressId) {
00254                   return $this->_getRedirectEvent(&$request, $newPressPath, false);
00255                }
00256             }
00257          }
00258          return DAO::getDataChangedEvent($pressId);
00259       } else {
00260          $json = new JSONMessage(false);
00261       }
00262       return $json->getString();
00263    }
00264 
00271    function deletePress($args, &$request) {
00272       // Identify the current context.
00273       $context =& $request->getContext();
00274 
00275       // Identify the press Id.
00276       $pressId = $request->getUserVar('rowId');
00277       $pressDao =& DAORegistry::getDAO('PressDAO');
00278       $press =& $pressDao->getById($pressId);
00279 
00280       $json = new JSONMessage();
00281 
00282       if ($pressId) {
00283          if ($pressDao->deleteById($pressId)) {
00284             // Add publication formats tombstones for all press published monographs.
00285             import('classes.publicationFormat.PublicationFormatTombstoneManager');
00286             $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
00287             $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
00288 
00289             // Delete press file tree
00290             // FIXME move this somewhere better.
00291             import('classes.file.PressFileManager');
00292             $pressFileManager = new PressFileManager($pressId);
00293             $pressFileManager->rmtree($pressFileManager->getBasePath());
00294 
00295             import('classes.file.PublicFileManager');
00296             $publicFileManager = new PublicFileManager();
00297             $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId));
00298 
00299             // If user is deleting the same press where he is...
00300             if($context->getId() == $pressId) {
00301                // return a redirect js event to index handler.
00302                $dispatcher =& $request->getDispatcher();
00303                $url = $dispatcher->url($request, ROUTE_PAGE, null, 'index');
00304                return $request->redirectUrlJson($url);
00305             }
00306 
00307             return DAO::getDataChangedEvent($pressId);
00308          } else {
00309             $json->setStatus(false);
00310          }
00311       }
00312 
00313       return $json->getString();
00314    }
00315 
00316 
00317    //
00318    // Private helper methods.
00319    //
00326    function _getRedirectEvent(&$request, $newPressPath, $openWizard) {
00327       $dispatcher =& $request->getDispatcher();
00328 
00329       $url = $dispatcher->url($request, ROUTE_PAGE, $newPressPath, 'admin', 'presses', null, array('openWizard' => $openWizard));
00330       return $request->redirectUrlJson($url);
00331    }
00332 }
00333 ?>

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