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

controllers/modals/submissionMetadata/form/SubmissionMetadataViewForm.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 // Use this class to handle the submission metadata.
00018 import('classes.submission.SubmissionMetadataFormImplementation');
00019 
00020 class SubmissionMetadataViewForm extends Form {
00021 
00023    var $_monograph;
00024 
00026    var $_stageId;
00027 
00031    var $_formParams;
00032 
00034    var $_metadataFormImplem;
00035 
00042    function SubmissionMetadataViewForm($monographId, $stageId = null, $formParams = null, $templateName = 'controllers/modals/submissionMetadata/form/submissionMetadataViewForm.tpl') {
00043       parent::Form($templateName);
00044 
00045       $monographDao =& DAORegistry::getDAO('MonographDAO');
00046       $monograph = $monographDao->getById((int) $monographId);
00047       if ($monograph) {
00048          $this->_monograph = $monograph;
00049       }
00050 
00051       $this->_stageId = $stageId;
00052 
00053       $this->_formParams = $formParams;
00054 
00055       $this->_metadataFormImplem = new SubmissionMetadataFormImplementation($this);
00056 
00057       // Validation checks for this form
00058       $this->_metadataFormImplem->addChecks($monograph);
00059       $this->addCheck(new FormValidatorPost($this));
00060    }
00061 
00062    //
00063    // Getters and Setters
00064    //
00069    function &getMonograph() {
00070       return $this->_monograph;
00071    }
00072 
00077    function getStageId() {
00078       return $this->_stageId;
00079    }
00080 
00084    function getFormParams() {
00085       return $this->_formParams;
00086    }
00087 
00088 
00089    //
00090    // Overridden template methods
00091    //
00096    function getLocaleFieldNames() {
00097       $this->_metadataFormImplem->getLocaleFieldNames();
00098    }
00099 
00105    function initData($args, &$request) {
00106       AppLocale::requireComponents(
00107          LOCALE_COMPONENT_APPLICATION_COMMON,
00108          LOCALE_COMPONENT_PKP_SUBMISSION,
00109          LOCALE_COMPONENT_OMP_SUBMISSION
00110       );
00111 
00112       $this->_metadataFormImplem->initData($this->getMonograph());
00113    }
00114 
00120    function fetch(&$request) {
00121       $monograph =& $this->getMonograph();
00122 
00123       $templateMgr =& TemplateManager::getManager();
00124       $templateMgr->assign('monographId', $monograph->getId());
00125       $templateMgr->assign('stageId', $this->getStageId());
00126       $templateMgr->assign('formParams', $this->getFormParams());
00127       $templateMgr->assign('isEditedVolume', $monograph->getWorkType() == WORK_TYPE_EDITED_VOLUME);
00128       $templateMgr->assign('isPublished', $monograph->getDatePublished() != null ? true : false);
00129 
00130       // Get series for this press
00131       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00132       $seriesOptions = array('0' => __('submission.submit.selectSeries')) + $seriesDao->getTitlesByPressId($monograph->getPressId());
00133       $templateMgr->assign('seriesOptions', $seriesOptions);
00134       $templateMgr->assign('seriesId', $monograph->getSeriesId());
00135       $templateMgr->assign('seriesPosition', $monograph->getSeriesPosition());
00136 
00137       // If categories are configured for the press, present the LB.
00138       $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00139       $templateMgr->assign('categoriesExist', $categoryDao->getCountByPressId($monograph->getPressId()) > 0);
00140 
00141       // also include the categories (for read only form views)
00142       $monographDao =& DAORegistry::getDAO('MonographDAO');
00143       $assignedCategories =& $monographDao->getCategories($monograph->getId(), $monograph->getPressId());
00144       $templateMgr->assign('assignedCategories', $assignedCategories->toArray());
00145 
00146       return parent::fetch($request);
00147    }
00148 
00152    function readInputData() {
00153       $this->_metadataFormImplem->readInputData();
00154       $this->readUserVars(array('categories', 'seriesId', 'seriesPosition'));
00155       ListbuilderHandler::unpack($request, $this->getData('categories'));
00156    }
00157 
00162    function execute($request) {
00163       $monograph =& $this->getMonograph();
00164       $monographDao =& DAORegistry::getDAO('MonographDAO');
00165 
00166       // Clean any new release or feature object that may
00167       // exist associated with the current monograph series.
00168       $newReleaseDao =& DAORegistry::getDAO('NewReleaseDAO'); /* @var $newReleaseDao NewReleaseDAO */
00169       $newReleaseDao->deleteNewRelease($monograph->getId(), ASSOC_TYPE_SERIES, $monograph->getSeriesId());
00170 
00171       $featureDao =& DAORegistry::getDAO('FeatureDAO'); /* @var $featureDao FeatureDAO */
00172       $featureDao->deleteFeature($monograph->getId(), ASSOC_TYPE_SERIES, $monograph->getSeriesId());
00173 
00174       // Execute monograph metadata related operations.
00175       $this->_metadataFormImplem->execute($monograph, $request);
00176       $monograph->setSeriesId($this->getData('seriesId'));
00177       $monograph->setSeriesPosition($this->getData('seriesPosition'));
00178       $monographDao->updateMonograph($monograph);
00179 
00180       if ($monograph->getDatePublished()) {
00181          import('classes.search.MonographSearchIndex');
00182          MonographSearchIndex::indexMonographMetadata($monograph);
00183       }
00184    }
00185 
00190    function insertEntry(&$request, $newRowId) {
00191 
00192       $application =& PKPApplication::getApplication();
00193       $request =& $application->getRequest();
00194 
00195       $categoryId = $newRowId['name'];
00196       $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00197       $monographDao =& DAORegistry::getDAO('MonographDAO');
00198       $press =& $request->getPress();
00199       $monograph =& $this->getMonograph();
00200 
00201       $category =& $categoryDao->getById($categoryId, $press->getId());
00202       if (!$category) return true;
00203 
00204       // Associate the category with the monograph
00205       $monographDao->addCategory(
00206          $monograph->getId(),
00207          $categoryId
00208       );
00209    }
00210 
00215    function deleteEntry(&$request, $rowId) {
00216       if ($rowId) {
00217          $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00218          $monographDao =& DAORegistry::getDAO('MonographDAO');
00219          $category =& $categoryDao->getById($rowId);
00220          if (!is_a($category, 'Category')) {
00221             assert(false);
00222             return false;
00223          }
00224          $monograph =& $this->getMonograph();
00225          $monographDao->removeCategory($monograph->getId(), $rowId);
00226       }
00227 
00228       return true;
00229    }
00230 
00235    function updateEntry($request, $rowId, $newRowId) {
00236 
00237       $this->deleteEntry($request, $rowId);
00238       $this->insertEntry($request, $newRowId);
00239    }
00240 }
00241 
00242 ?>

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