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

controllers/grid/settings/sponsor/SponsorGridHandler.inc.php

00001 <?php
00002 
00015 import('controllers.grid.settings.SetupGridHandler');
00016 import('controllers.grid.settings.sponsor.SponsorGridRow');
00017 
00018 import('lib.pkp.classes.linkAction.request.AjaxModal');
00019 
00020 class SponsorGridHandler extends SetupGridHandler {
00024    function SponsorGridHandler() {
00025       parent::SetupGridHandler();
00026       $this->addRoleAssignment(array(ROLE_ID_PRESS_MANAGER),
00027             array('fetchGrid', 'fetchRow', 'addSponsor', 'editSponsor', 'updateSponsor', 'deleteSponsor'));
00028    }
00029 
00030    //
00031    // Overridden template methods
00032    //
00033    /*
00034     * Configure the grid
00035     * @param $request PKPRequest
00036     */
00037    function initialize(&$request) {
00038       parent::initialize($request);
00039 
00040       // Elements to be displayed in the grid
00041       $router =& $request->getRouter();
00042       $context =& $router->getContext($request);
00043       $sponsors = $context->getSetting('sponsors');
00044       $sponsors = isset($sponsors) ? $sponsors : array();
00045       $this->setGridDataElements($sponsors);
00046 
00047       // Add grid-level actions
00048       $router =& $request->getRouter();
00049       $this->addAction(
00050          new LinkAction(
00051             'addSponsor',
00052             new AjaxModal(
00053                $router->url($request, null, null, 'addSponsor', null, array('gridId' => $this->getId())),
00054                __('grid.action.addSponsor'),
00055                'modal_add_user',
00056                true
00057                ),
00058             __('grid.action.addSponsor'),
00059             'add_user')
00060       );
00061 
00062       // Columns
00063       $this->addColumn(
00064          new GridColumn(
00065             'institution',
00066             'grid.columns.institution',
00067             null,
00068             'controllers/grid/gridCell.tpl',
00069             null,
00070             array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00071          )
00072       );
00073       $this->addColumn(
00074          new GridColumn(
00075             'url',
00076             'grid.columns.url',
00077             null,
00078             'controllers/grid/gridCell.tpl',
00079             null,
00080             array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
00081          )
00082       );
00083    }
00084 
00085    //
00086    // Overridden methods from GridHandler
00087    //
00092    function &getRowInstance() {
00093       $row = new SponsorGridRow();
00094       return $row;
00095    }
00096 
00097    //
00098    // Public Sponsor Grid Actions
00099    //
00105    function addSponsor($args, &$request) {
00106       // Calling editSponsor with an empty row id will add
00107       // a new sponsor.
00108       return $this->editSponsor($args, $request);
00109    }
00110 
00117    function editSponsor($args, &$request) {
00118       $sponsorId = isset($args['rowId'])?$args['rowId']:null;
00119 
00120       import('controllers.grid.settings.sponsor.form.SponsorForm');
00121       $sponsorForm = new SponsorForm($sponsorId);
00122 
00123       if ($sponsorForm->isLocaleResubmit()) {
00124          $sponsorForm->readInputData();
00125       } else {
00126          $sponsorForm->initData($args, $request);
00127       }
00128 
00129       $json = new JSONMessage(true, $sponsorForm->fetch($request));
00130       return $json->getString();
00131    }
00132 
00139    function updateSponsor($args, &$request) {
00140       // -> sponsorId must be present and valid
00141       // -> htmlId must be present and valid
00142       $sponsorId = isset($args['rowId'])?$args['rowId']:null;
00143 
00144       import('controllers.grid.settings.sponsor.form.SponsorForm');
00145       $sponsorForm = new SponsorForm($sponsorId);
00146       $sponsorForm->readInputData();
00147 
00148       if ($sponsorForm->validate()) {
00149          $sponsorForm->execute($request);
00150 
00151          // prepare the grid row data
00152          $row =& $this->getRowInstance();
00153          $row->setGridId($this->getId());
00154          $row->setId($sponsorForm->sponsorId);
00155          $rowData = array('institution' => $sponsorForm->getData('institution'),
00156                      'url' => $sponsorForm->getData('url'));
00157          $row->setData($rowData);
00158          $row->initialize($request);
00159          return DAO::getDataChangedEvent($sponsorForm->sponsorId);
00160       } else {
00161          return new JSONMessage(false);
00162       }
00163    }
00164 
00171    function deleteSponsor($args, &$request) {
00172       $sponsorId = isset($args['rowId'])?$args['rowId']:null;
00173       $router =& $request->getRouter();
00174       $press =& $router->getContext($request);
00175       $pressSettingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00176 
00177       // get all of the sponsors
00178       $sponsors = $pressSettingsDao->getSetting($press->getId(), 'sponsors');
00179 
00180       if (isset($sponsors[$sponsorId])) {
00181          unset($sponsors[$sponsorId]);
00182          $pressSettingsDao->updateSetting($press->getId(), 'sponsors', $sponsors, 'object');
00183          return DAO::getDataChangedEvent($sponsorId);
00184       } else {
00185          return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00186       }
00187    }
00188 }
00189 
00190 ?>

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