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

controllers/grid/catalogEntry/form/PublicationFormatForm.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class PublicationFormatForm extends Form {
00019    var $_monograph;
00020 
00022    var $_publicationFormat;
00023 
00027    function PublicationFormatForm($monograph, $publicationFormat) {
00028       parent::Form('controllers/grid/catalogEntry/form/formatForm.tpl');
00029       $this->setMonograph($monograph);
00030       $this->setPublicationFormat($publicationFormat);
00031 
00032       // Validation checks for this form
00033       $this->addCheck(new FormValidator($this, 'name', 'required', 'grid.catalogEntry.nameRequired'));
00034       $this->addCheck(new FormValidator($this, 'entryKey', 'required', 'grid.catalogEntry.publicationFormatRequired'));
00035       $this->addCheck(new FormValidatorPost($this));
00036    }
00037 
00038    //
00039    // Getters and Setters
00040    //
00045    function &getPublicationFormat() {
00046       return $this->_publicationFormat;
00047    }
00048 
00053    function setPublicationFormat($publicationFormat) {
00054       $this->_publicationFormat =& $publicationFormat;
00055    }
00056 
00061    function &getMonograph() {
00062       return $this->_monograph;
00063    }
00064 
00069    function setMonograph($monograph) {
00070       $this->_monograph =& $monograph;
00071    }
00072 
00073 
00074    //
00075    // Overridden template methods
00076    //
00080    function initData() {
00081       $format =& $this->getPublicationFormat();
00082 
00083       if ($format) {
00084          $this->_data = array(
00085             'entryKey' => $format->getEntryKey(),
00086             'name' => $format->getName(),
00087             'isPhysicalFormat' => $format->getPhysicalFormat()?true:false,
00088          );
00089       } else {
00090          $this->setData('entryKey', 'DA');
00091       }
00092    }
00093 
00098    function fetch(&$request) {
00099       $format =& $this->getPublicationFormat();
00100       $press =& $request->getPress();
00101 
00102 
00103       $templateMgr =& TemplateManager::getManager();
00104       $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00105       $templateMgr->assign('entryKeys', $onixCodelistItemDao->getCodes('List7')); // List7 is for object formats
00106 
00107       $monograph =& $this->getMonograph();
00108       $templateMgr->assign('monographId', $monograph->getId());
00109       $publicationFormat =& $this->getPublicationFormat();
00110       if ($publicationFormat != null) {
00111          $templateMgr->assign('publicationFormatId', $publicationFormat->getId());
00112       }
00113       return parent::fetch($request);
00114    }
00115 
00120    function readInputData() {
00121       $this->readUserVars(array(
00122          'name',
00123          'entryKey',
00124          'isPhysicalFormat',
00125       ));
00126    }
00127 
00133    function execute($request) {
00134       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00135       $monograph = $this->getMonograph();
00136       $publicationFormat =& $this->getPublicationFormat();
00137       if (!$publicationFormat) {
00138          // this is a new format to this published monograph
00139          $publicationFormat = $publicationFormatDao->newDataObject();
00140          $publicationFormat->setMonographId($monograph->getId());
00141          $existingFormat = false;
00142       } else {
00143          $existingFormat = true;
00144          if ($monograph->getId() !== $publicationFormat->getMonographId()) fatalError('Invalid format!');
00145       }
00146 
00147       $publicationFormat->setName($this->getData('name'));
00148       $publicationFormat->setEntryKey($this->getData('entryKey'));
00149       $publicationFormat->setPhysicalFormat($this->getData('isPhysicalFormat')?true:false);
00150 
00151       if ($existingFormat) {
00152          $publicationFormatDao->updateObject($publicationFormat);
00153          $publicationFormatId = $publicationFormat->getId();
00154       } else {
00155          $publicationFormatId = $publicationFormatDao->insertObject($publicationFormat);
00156          // log the creation of the format.
00157          import('classes.log.MonographLog');
00158          import('classes.log.MonographEventLogEntry');
00159          MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_PUBLICATION_FORMAT_CREATE, 'submission.event.publicationFormatCreated', array('formatName' => $publicationFormat->getLocalizedName()));
00160       }
00161 
00162       return $publicationFormatId;
00163    }
00164 }
00165 
00166 ?>

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