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

controllers/grid/settings/series/SeriesGridHandler.inc.php

00001 <?php
00002 
00015 import('controllers.grid.settings.SetupGridHandler');
00016 import('controllers.grid.settings.series.SeriesGridRow');
00017 
00018 class SeriesGridHandler extends SetupGridHandler {
00022    function SeriesGridHandler() {
00023       parent::SetupGridHandler();
00024       $this->addRoleAssignment(
00025          array(ROLE_ID_PRESS_MANAGER),
00026          array('fetchGrid', 'fetchRow', 'addSeries', 'editSeries', 'updateSeries', 'deleteSeries')
00027       );
00028    }
00029 
00030 
00031    //
00032    // Overridden template methods
00033    //
00034    /*
00035     * Configure the grid
00036     * @param $request PKPRequest
00037     */
00038    function initialize(&$request) {
00039       parent::initialize($request);
00040       $press =& $request->getPress();
00041 
00042       // FIXME are these all required?
00043       AppLocale::requireComponents(
00044          LOCALE_COMPONENT_OMP_MANAGER,
00045          LOCALE_COMPONENT_PKP_COMMON,
00046          LOCALE_COMPONENT_PKP_USER,
00047          LOCALE_COMPONENT_APPLICATION_COMMON
00048       );
00049 
00050       // Set the grid title.
00051       $this->setTitle('catalog.manage.series');
00052 
00053       $this->setInstructions('manager.setup.series.description');
00054 
00055       // Elements to be displayed in the grid
00056       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00057       $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00058       $seriesEditorsDao =& DAORegistry::getDAO('SeriesEditorsDAO');
00059       $seriesIterator = $seriesDao->getByPressId($press->getId());
00060 
00061       $gridData = array();
00062       while ($series =& $seriesIterator->next()) {
00063          // Get the categories data for the row
00064          $categories = $seriesDao->getCategories($series->getId(), $press->getId());
00065          $categoriesString = null;
00066          while ($category =& $categories->next()) {
00067             if (!empty($categoriesString)) $categoriesString .= ', ';
00068             $categoriesString .= $category->getLocalizedTitle();
00069             unset($category);
00070          }
00071          if (empty($categoriesString)) $categoriesString = __('common.none');
00072 
00073          // Get the series editors data for the row
00074          $assignedSeriesEditors =& $seriesEditorsDao->getEditorsBySeriesId($series->getId(), $press->getId());
00075          if(empty($assignedSeriesEditors)) {
00076             $editorsString = __('common.none');
00077          } else {
00078             $editors = array();
00079             foreach ($assignedSeriesEditors as $seriesEditor) {
00080                $user = $seriesEditor['user'];
00081                $editors[] = $user->getLastName();
00082             }
00083             $editorsString = implode(', ', $editors);
00084          }
00085 
00086          $seriesId = $series->getId();
00087          $gridData[$seriesId] = array(
00088             'title' => $series->getLocalizedTitle(),
00089             'categories' => $categoriesString,
00090             'editors' => $editorsString
00091          );
00092          unset($series);
00093          unset($editorsString);
00094       }
00095 
00096       $this->setGridDataElements($gridData);
00097 
00098       // Add grid-level actions
00099       $router =& $request->getRouter();
00100       import('lib.pkp.classes.linkAction.request.AjaxModal');
00101       $this->addAction(
00102          new LinkAction(
00103             'addSeries',
00104             new AjaxModal(
00105                $router->url($request, null, null, 'addSeries', null, array('gridId' => $this->getId())),
00106                __('grid.action.addSeries'),
00107                'modal_manage'
00108             ),
00109             __('grid.action.addSeries'),
00110             'add_category'
00111          )
00112       );
00113 
00114       // Columns
00115       $this->addColumn(
00116          new GridColumn(
00117             'title',
00118             'common.title',
00119             null,
00120             'controllers/grid/gridCell.tpl'
00121          )
00122       );
00123       $this->addColumn(new GridColumn('categories', 'grid.category.categories'));
00124       $this->addColumn(new GridColumn('editors', 'user.role.editors'));
00125    }
00126 
00127    //
00128    // Overridden methods from GridHandler
00129    //
00134    function &getRowInstance() {
00135       $row = new SeriesGridRow();
00136       return $row;
00137    }
00138 
00139    //
00140    // Public Series Grid Actions
00141    //
00147    function addSeries($args, &$request) {
00148       // Calling editSeries with an empty ID will add
00149       // a new series.
00150       return $this->editSeries($args, $request);
00151    }
00152 
00159    function editSeries($args, &$request) {
00160       $seriesId = isset($args['seriesId']) ? $args['seriesId'] : null;
00161       $this->setupTemplate();
00162 
00163       import('controllers.grid.settings.series.form.SeriesForm');
00164       $seriesForm = new SeriesForm($seriesId);
00165       $seriesForm->initData($args, $request);
00166       $json = new JSONMessage(true, $seriesForm->fetch($request));
00167       return $json->getString();
00168    }
00169 
00176    function updateSeries($args, &$request) {
00177       $seriesId = $request->getUserVar('seriesId');
00178       $press =& $request->getPress();
00179 
00180       import('controllers.grid.settings.series.form.SeriesForm');
00181       $seriesForm = new SeriesForm($seriesId);
00182       $seriesForm->readInputData();
00183 
00184       if ($seriesForm->validate()) {
00185          $seriesForm->execute($args, $request);
00186          return DAO::getDataChangedEvent($seriesForm->getSeriesId());
00187       } else {
00188          $json = new JSONMessage(false);
00189          return $json->getString();
00190       }
00191    }
00192 
00199    function deleteSeries($args, &$request) {
00200       $press =& $request->getPress();
00201 
00202       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00203       $series = $seriesDao->getById(
00204          $request->getUserVar('seriesId'),
00205          $press->getId()
00206       );
00207 
00208       if (isset($series)) {
00209          $seriesDao->deleteObject($series);
00210          return DAO::getDataChangedEvent($series->getId());
00211       } else {
00212          AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER); // manager.setup.errorDeletingItem
00213          $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
00214       }
00215       return $json->getString();
00216    }
00217 }
00218 
00219 ?>

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