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

pages/manageCatalog/ManageCatalogHandler.inc.php

00001 <?php
00002 
00015 import('classes.handler.Handler');
00016 
00017 // import UI base classes
00018 import('lib.pkp.classes.linkAction.LinkAction');
00019 import('lib.pkp.classes.core.JSONMessage');
00020 
00021 class ManageCatalogHandler extends Handler {
00025    function ManageCatalogHandler() {
00026       parent::Handler();
00027 
00028       $this->addRoleAssignment(
00029          array(ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_MANAGER),
00030          array(
00031             'index', // Container
00032             'homepage', 'search',
00033             'getCategories', 'category', // By category
00034             'getSeries', 'series', // By series
00035             'toggle'
00036          )
00037       );
00038    }
00039 
00040 
00041    //
00042    // Implement template methods from PKPHandler
00043    //
00050    function authorize(&$request, $args, $roleAssignments) {
00051       import('lib.pkp.classes.security.authorization.PKPSiteAccessPolicy');
00052       $this->addPolicy(new PKPSiteAccessPolicy($request, null, $roleAssignments));
00053       return parent::authorize($request, $args, $roleAssignments);
00054    }
00055 
00059    function initialize(&$request, $args) {
00060       $this->setupTemplate($request);
00061 
00062       // Call parent method.
00063       parent::initialize($request, $args);
00064    }
00065 
00066 
00067    //
00068    // Public handler methods
00069    //
00075    function index($args, &$request) {
00076       // Render the view.
00077       $templateMgr =& TemplateManager::getManager();
00078 
00079       import('controllers.modals.submissionMetadata.linkAction.MonographlessCatalogEntryLinkAction');
00080       $catalogEntryAction = new MonographlessCatalogEntryLinkAction($request);
00081       $templateMgr->assign('catalogEntryAction', $catalogEntryAction);
00082 
00083       import('lib.pkp.classes.linkAction.LinkAction');
00084       import('lib.pkp.classes.linkAction.request.AjaxModal');
00085 
00086       $dispatcher =& $request->getDispatcher();
00087 
00088       $manageCategoriesLinkAction =
00089          new LinkAction(
00090             'manageCategories',
00091             new AjaxModal(
00092                $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'categories'),
00093                __('catalog.manage.manageCategories'),
00094                'modal_manage',
00095                true
00096             ),
00097             __('catalog.manage.manageCategories'),
00098             'manage'
00099          );
00100 
00101       $manageSeriesLinkAction =
00102          new LinkAction(
00103             'manageSeries',
00104             new AjaxModal(
00105                $dispatcher->url($request, ROUTE_PAGE, null, 'management', 'series'),
00106                __('catalog.manage.manageSeries'),
00107                'modal_manage',
00108                true
00109             ),
00110             __('catalog.manage.manageSeries'),
00111             'manage'
00112          );
00113 
00114       $templateMgr->assign('manageCategoriesLinkAction', $manageCategoriesLinkAction);
00115       $templateMgr->assign('manageSeriesLinkAction', $manageSeriesLinkAction);
00116       $templateMgr->display('manageCatalog/index.tpl');
00117    }
00118 
00124    function homepage($args, &$request) {
00125       // Set up the monograph list template
00126       $press =& $request->getPress();
00127       $this->_setupMonographsTemplate(
00128          true, 'homepage', 'catalog.manage.homepageDescription',
00129          ASSOC_TYPE_PRESS, $press->getId()
00130       );
00131 
00132       $templateMgr =& TemplateManager::getManager();
00133 
00134       // Fetch the monographs to display
00135       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00136       $publishedMonographs =& $publishedMonographDao->getByPressId($press->getId());
00137       $templateMgr->assign('publishedMonographs', $publishedMonographs);
00138 
00139       // Display the monograph list
00140       $templateMgr->display('manageCatalog/monographs.tpl');
00141    }
00142 
00149    function getCategories($args, &$request) {
00150       $press =& $request->getPress();
00151       $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00152       $categoryIterator =& $categoryDao->getByPressId($press->getId());
00153       $categoryArray = array();
00154       while ($category =& $categoryIterator->next()) {
00155          $categoryArray[$category->getPath()] = $category->getLocalizedTitle();
00156          unset($category);
00157       }
00158       $json = new JSONMessage(true, $categoryArray);
00159       return $json->getString();
00160    }
00161 
00168    function getSeries($args, &$request) {
00169       $press =& $request->getPress();
00170       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00171       $seriesIterator =& $seriesDao->getByPressId($press->getId());
00172       $seriesArray = array();
00173       while ($series =& $seriesIterator->next()) {
00174          $seriesArray[$series->getPath()] = $series->getLocalizedTitle();
00175          unset($series);
00176       }
00177       $json = new JSONMessage(true, $seriesArray);
00178       return $json->getString();
00179    }
00180 
00187    function category($args, &$request) {
00188       $templateMgr =& TemplateManager::getManager();
00189       $press =& $request->getPress();
00190 
00191       // Get the category
00192       $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00193       $categoryPath = array_shift($args);
00194       $category =& $categoryDao->getByPath($categoryPath, $press->getId());
00195       $templateMgr->assign('category', $category);
00196 
00197       // Set up the monograph list template
00198       $this->_setupMonographsTemplate(
00199          true, 'category', 'catalog.manage.categoryDescription',
00200          ASSOC_TYPE_CATEGORY, $category->getId()
00201       );
00202 
00203       // Fetch the monographs to display
00204       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00205       $publishedMonographs =& $publishedMonographDao->getByCategoryId($category->getId(), $press->getId());
00206       $templateMgr->assign('publishedMonographs', $publishedMonographs);
00207 
00208       // Fetch the current features
00209       $featureDao =& DAORegistry::getDAO('FeatureDAO');
00210       $features = $featureDao->getSequencesByAssoc(ASSOC_TYPE_CATEGORY, $category->getId());
00211       $templateMgr->assign('features', $features);
00212 
00213       // Return the monograph list as a JSON message
00214       $json = new JSONMessage(true, $templateMgr->fetch('manageCatalog/monographs.tpl'));
00215       return $json->getString();
00216    }
00217 
00224    function series($args, &$request) {
00225       $templateMgr =& TemplateManager::getManager();
00226       $press =& $request->getPress();
00227 
00228       // Get the series
00229       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00230       $seriesPath = array_shift($args);
00231       $series =& $seriesDao->getByPath($seriesPath, $press->getId());
00232       $templateMgr->assign('series', $series);
00233 
00234       // Set up the monograph list template
00235       $this->_setupMonographsTemplate(
00236          true, 'series', 'catalog.manage.seriesDescription',
00237          ASSOC_TYPE_SERIES, $series->getId()
00238       );
00239 
00240       // Fetch the monographs to display
00241       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00242       $publishedMonographs =& $publishedMonographDao->getBySeriesId($series->getId(), $press->getId());
00243       $templateMgr->assign('publishedMonographs', $publishedMonographs);
00244 
00245       // Return the monograph list as a JSON message
00246       $json = new JSONMessage(true, $templateMgr->fetch('manageCatalog/monographs.tpl'));
00247       return $json->getString();
00248    }
00249 
00255    function search($args, &$request) {
00256       $searchText = array_shift($args);
00257       $this->_setupMonographsTemplate(false, 'search');
00258 
00259       $templateMgr =& TemplateManager::getManager();
00260       $press =& $request->getPress();
00261 
00262       // Fetch the monographs to display
00263       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00264       $publishedMonographs =& $publishedMonographDao->getByPressId($press->getId(), $searchText);
00265       $templateMgr->assign('publishedMonographs', $publishedMonographs);
00266 
00267       // Display the monograph list
00268       $templateMgr->display('manageCatalog/monographs.tpl');
00269    }
00270 
00277    function toggle($args, &$request) {
00278       $press =& $request->getPress();
00279 
00280       // Identification of item to set new state state on
00281       $monographId = (int) array_shift($args);
00282       $assocType = (int) array_shift($args);
00283       $assocId = (int) array_shift($args);
00284 
00285       // toggle type
00286       $toggleType = array_shift($args);
00287 
00288       // Description of new state
00289       $newState = (int) array_shift($args);
00290       $newSeq = (int) array_shift($args);
00291 
00292       // Validate the monograph ID
00293       // FIXME: Can this be done with the auth framework without
00294       // needing the policy throughout?
00295       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00296       $publishedMonograph =& $publishedMonographDao->getById($monographId, $press->getId());
00297       if (!$publishedMonograph) fatalError('Invalid monograph!');
00298 
00299       // Determine the assoc type and ID to be used.
00300       switch ($assocType) {
00301          case ASSOC_TYPE_PRESS:
00302             // Force assocId to press
00303             $assocId = $press->getId();
00304             break;
00305          case ASSOC_TYPE_CATEGORY:
00306             // Validate specified assocId
00307             $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00308             $category =& $categoryDao->getById($assocId, $press->getId());
00309             if (!$category) fatalError('Invalid category!');
00310             break;
00311          case ASSOC_TYPE_SERIES:
00312             // Validate specified assocId
00313             $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00314             $series =& $seriesDao->getById($assocId, $press->getId());
00315             if (!$series) fatalError('Invalid series!');
00316             break;
00317          default:
00318             fatalError('Invalid feature specified.');
00319       }
00320 
00321       $returner = null;
00322 
00323       switch ($toggleType) {
00324          case 'setFeatured':
00325             $featureDao =& DAORegistry::getDAO('FeatureDAO');
00326             $featureDao->deleteFeature($monographId, $assocType, $assocId);
00327 
00328             // If necessary, insert the new featured state and resequence.
00329             if ($newState) {
00330                $featureDao->insertFeature($monographId, $assocType, $assocId, $newSeq);
00331                $returner = $featureDao->resequenceByAssoc($assocType, $assocId);
00332             } else {
00333                $returner = null;
00334             }
00335             break;
00336          case 'setNewRelease':
00337             $newReleaseDao =& DAORegistry::getDAO('NewReleaseDAO');
00338             $newReleaseDao->deleteNewRelease($monographId, $assocType, $assocId);
00339             if ($newState) {
00340                $newReleaseDao->insertNewRelease($monographId, $assocType, $assocId);
00341                $returner = true;
00342             }
00343             break;
00344          default:
00345             fatalError('Invalid toggle type specified.');
00346       }
00347 
00348       $json = new JSONMessage(true, $returner);
00349       return $json->getString();
00350    }
00351 
00352    //
00353    // Private functions
00354    //
00365    function _setupMonographsTemplate($includeFeatureAction, $listName, $messageKey = null, $assocType = null, $assocId = null) {
00366       // Loadubmission locale content for monograph listing
00367       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_SUBMISSION);
00368 
00369       $templateMgr =& TemplateManager::getManager();
00370       import('lib.pkp.classes.linkAction.request.NullAction');
00371 
00372       // Feature action (if enabled)
00373       $templateMgr->assign('includeFeatureAction', $includeFeatureAction);
00374 
00375       // Add the list name, for ID differentiation
00376       $templateMgr->assign('listName', $listName);
00377 
00378       // Include the message locale key displayed at the top of the tab
00379       $templateMgr->assign('messageKey', $messageKey);
00380 
00381       // Expose the featured monograph IDs and associated params
00382       if ($assocType) {
00383          $featureDao =& DAORegistry::getDAO('FeatureDAO');
00384          $featuredMonographIds = $featureDao->getSequencesByAssoc($assocType, $assocId);
00385          $templateMgr->assign('featuredMonographIds', $featuredMonographIds);
00386 
00387          $newReleaseDao =& DAORegistry::getDAO('NewReleaseDAO');
00388          $newReleaseMonographIds =& $newReleaseDao->getMonographIdsByAssoc($assocType, $assocId);
00389          $templateMgr->assign('newReleaseMonographIds', $newReleaseMonographIds);
00390       }
00391 
00392       $templateMgr->assign('assocType', $assocType);
00393       $templateMgr->assign('assocId', $assocId);
00394    }
00395 }
00396 
00397 ?>

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