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

controllers/tab/catalogEntry/form/CatalogEntryPublicationMetadataForm.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class CatalogEntryPublicationMetadataForm extends Form {
00018 
00020    var $_monograph;
00021 
00023    var $_stageId;
00024 
00026    var $_publicationFormatId;
00027 
00029    var $_isPhysicalFormat;
00030 
00034    var $_formParams;
00035 
00044    function CatalogEntryPublicationMetadataForm($monographId, $publicationFormatId, $isPhysicalFormat = true, $stageId = null, $formParams = null) {
00045       parent::Form('controllers/tab/catalogEntry/form/publicationMetadataFormFields.tpl');
00046       $monographDao =& DAORegistry::getDAO('MonographDAO');
00047       $this->_monograph = $monographDao->getById($monographId);
00048 
00049       $this->_stageId = $stageId;
00050       $this->_publicationFormatId = $publicationFormatId;
00051       $this->_isPhysicalFormat = $isPhysicalFormat;
00052       $this->_formParams = $formParams;
00053 
00054       $this->addCheck(new FormValidator($this, 'productAvailabilityCode', 'required', 'grid.catalogEntry.productAvailabilityRequired'));
00055       $this->addCheck(new FormValidatorRegExp($this, 'directSalesPrice', 'optional', 'grid.catalogEntry.validPriceRequired', '/^[0-9]*(\.[0-9]+)?$/'));
00056       $this->addCheck(new FormValidator($this, 'productCompositionCode', 'required', 'grid.catalogEntry.productCompositionRequired'));
00057       $this->addCheck(new FormValidatorPost($this));
00058    }
00059 
00065    function fetch(&$request) {
00066       $monograph =& $this->getMonograph();
00067       $press =& $request->getPress();
00068 
00069       $templateMgr =& TemplateManager::getManager();
00070       $templateMgr->assign('monographId', $monograph->getId());
00071       $templateMgr->assign('publicationFormatId', (int) $this->getPublicationFormatId());
00072       $templateMgr->assign('isPhysicalFormat', (int) $this->getPhysicalFormat()); // included to load format-specific template
00073       $templateMgr->assign('stageId', $this->getStageId());
00074       $templateMgr->assign('formParams', $this->getFormParams());
00075       $templateMgr->assign('submissionApproved', $monograph->getDatePublished());
00076 
00077       $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00078 
00079       // Check if e-commerce is available
00080       import('classes.payment.omp.OMPPaymentManager');
00081       $ompPaymentManager = new OMPPaymentManager($request);
00082       if ($ompPaymentManager->isConfigured()) {
00083          $templateMgr->assign('paymentConfigured', true);
00084          $templateMgr->assign('pressCurrency', $press->getSetting('pressCurrency'));
00085       }
00086 
00087       // get the lists associated with the select elements on these publication format forms.
00088       $codes = array(
00089          'productCompositionCodes' => 'List2', // single item, multiple item, trade-only, etc
00090          'measurementUnitCodes' => 'List50', // grams, inches, millimeters
00091          'weightUnitCodes' => 'List95', // pounds, grams, ounces
00092          'measurementTypeCodes' => 'List48', // height, width, depth
00093          'productFormDetailCodes' => 'List175', // refinement of product form (SACD, Mass market (rack) paperback, etc)
00094          'productAvailabilityCodes' => 'List65', // Available, In Stock, Print On Demand, Not Yet Available, etc
00095          'technicalProtectionCodes' => 'List144', // None, DRM, Apple DRM, etc
00096          'returnableIndicatorCodes' => 'List66', // No, not returnable, Yes, full copies only, (required for physical items only)
00097          'countriesIncludedCodes' => 'List91', // country region codes
00098       );
00099 
00100       foreach ($codes as $templateVarName => $list) {
00101          $templateMgr->assign_by_ref($templateVarName, $onixCodelistItemDao->getCodes($list));
00102       }
00103 
00104       // Notification options.
00105       $notificationRequestOptions = array(
00106          NOTIFICATION_LEVEL_NORMAL => array(
00107             NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD => array(ASSOC_TYPE_PRESS, $press->getId()),
00108             NOTIFICATION_TYPE_FORMAT_NEEDS_APPROVED_SUBMISSION => array(ASSOC_TYPE_MONOGRAPH, $monograph->getId())),
00109          NOTIFICATION_LEVEL_TRIVIAL => array()
00110       );
00111 
00112       $templateMgr->assign('notificationRequestOptions', $notificationRequestOptions);
00113 
00114       return parent::fetch($request);
00115    }
00116 
00120    function initData() {
00121       AppLocale::requireComponents(
00122          LOCALE_COMPONENT_APPLICATION_COMMON,
00123          LOCALE_COMPONENT_PKP_SUBMISSION,
00124          LOCALE_COMPONENT_OMP_SUBMISSION
00125       );
00126 
00127       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00128       $monograph =& $this->getMonograph();
00129       $publicationFormat =& $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId());
00130       assert($publicationFormat);
00131 
00132       $this->_data = array(
00133          'fileSize' => (boolean) $publicationFormat->getFileSize() ? $publicationFormat->getFileSize() : $publicationFormat->getCalculatedFileSize(),
00134          'override' => (boolean) $publicationFormat->getData('fileSize') ? true : false,
00135          'frontMatter' => $publicationFormat->getFrontMatter(),
00136          'backMatter' => $publicationFormat->getBackMatter(),
00137          'height' => $publicationFormat->getHeight(),
00138          'heightUnitCode' => $publicationFormat->getHeightUnitCode() != '' ? $publicationFormat->getHeightUnitCode() : 'mm',
00139          'width' => $publicationFormat->getWidth(),
00140          'widthUnitCode' => $publicationFormat->getWidthUnitCode() != '' ? $publicationFormat->getWidthUnitCode() : 'mm',
00141          'thickness' => $publicationFormat->getThickness(),
00142          'thicknessUnitCode' => $publicationFormat->getThicknessUnitCode() != '' ? $publicationFormat->getThicknessUnitCode() : 'mm',
00143          'weight' => $publicationFormat->getWeight(),
00144          'weightUnitCode' => $publicationFormat->getWeightUnitCode() != '' ? $publicationFormat->getWeightUnitCode() : 'gr',
00145          'productCompositionCode' => $publicationFormat->getProductCompositionCode(),
00146          'productFormDetailCode' => $publicationFormat->getProductFormDetailCode(),
00147          'countryManufactureCode' => $publicationFormat->getCountryManufactureCode() != '' ? $publicationFormat->getCountryManufactureCode() : 'CA',
00148          'imprint' => $publicationFormat->getImprint(),
00149          'productAvailabilityCode' => $publicationFormat->getProductAvailabilityCode() != '' ? $publicationFormat->getProductAvailabilityCode() : '20',
00150          'technicalProtectionCode' => $publicationFormat->getTechnicalProtectionCode() != '' ? $publicationFormat->getTechnicalProtectionCode() : '00',
00151          'returnableIndicatorCode' => $publicationFormat->getReturnableIndicatorCode() != '' ? $publicationFormat->getReturnableIndicatorCode() : 'Y',
00152          'isApproved' => (bool) $publicationFormat->getIsApproved(),
00153       );
00154    }
00155 
00159    function readInputData() {
00160       $this->readUserVars(array(
00161          'directSalesPrice',
00162          'fileSize',
00163          'override',
00164          'frontMatter',
00165          'backMatter',
00166          'height',
00167          'heightUnitCode',
00168          'width',
00169          'widthUnitCode',
00170          'thickness',
00171          'thicknessUnitCode',
00172          'weight',
00173          'weightUnitCode',
00174          'productCompositionCode',
00175          'productFormDetailCode',
00176          'countryManufactureCode',
00177          'imprint',
00178          'productAvailabilityCode',
00179          'technicalProtectionCode',
00180          'returnableIndicatorCode',
00181          'isApproved'
00182       ));
00183    }
00184 
00188    function execute(&$request) {
00189       parent::execute();
00190 
00191       $monograph =& $this->getMonograph();
00192       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00193       $publicationFormat =& $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId());
00194       assert($publicationFormat);
00195 
00196       // Manage tombstones for the publication format.
00197       if ($publicationFormat->getIsApproved() && !$this->getData('isApproved')) {
00198          // Publication format was approved and its being disabled. Create
00199          // a tombstone for it.
00200          $press =& $request->getPress();
00201          import('classes.publicationFormat.PublicationFormatTombstoneManager');
00202          $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
00203          $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press);
00204 
00205          // Log unpublish event.
00206          import('classes.log.MonographLog');
00207          MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_PUBLICATION_FORMAT_UNPUBLISH, 'submission.event.publicationFormatUnpublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
00208       } elseif (!$publicationFormat->getIsApproved() && $this->getData('isApproved')) {
00209          // Wasn't approved and now it is. Delete tombstone.
00210          $tombstoneDao =& DAORegistry::getDAO('DataObjectTombstoneDAO');
00211          $tombstoneDao->deleteByDataObjectId($publicationFormat->getId());
00212 
00213          // Log publish event.
00214          import('classes.log.MonographLog');
00215          MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_PUBLICATION_FORMAT_PUBLISH, 'submission.event.publicationFormatPublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
00216       }
00217 
00218       // populate the published monograph with the cataloging metadata
00219       $publicationFormat->setFileSize($this->getData('override') ? $this->getData('fileSize'):null);
00220       $publicationFormat->setFrontMatter($this->getData('frontMatter'));
00221       $publicationFormat->setBackMatter($this->getData('backMatter'));
00222       $publicationFormat->setHeight($this->getData('height'));
00223       $publicationFormat->setHeightUnitCode($this->getData('heightUnitCode'));
00224       $publicationFormat->setWidth($this->getData('width'));
00225       $publicationFormat->setWidthUnitCode($this->getData('widthUnitCode'));
00226       $publicationFormat->setThickness($this->getData('thickness'));
00227       $publicationFormat->setThicknessUnitCode($this->getData('thicknessUnitCode'));
00228       $publicationFormat->setWeight($this->getData('weight'));
00229       $publicationFormat->setWeightUnitCode($this->getData('weightUnitCode'));
00230       $publicationFormat->setProductCompositionCode($this->getData('productCompositionCode'));
00231       $publicationFormat->setProductFormDetailCode($this->getData('productFormDetailCode'));
00232       $publicationFormat->setCountryManufactureCode($this->getData('countryManufactureCode'));
00233       $publicationFormat->setImprint($this->getData('imprint'));
00234       $publicationFormat->setProductAvailabilityCode($this->getData('productAvailabilityCode'));
00235       $publicationFormat->setTechnicalProtectionCode($this->getData('technicalProtectionCode'));
00236       $publicationFormat->setReturnableIndicatorCode($this->getData('returnableIndicatorCode'));
00237       $publicationFormat->setIsApproved($this->getData('isApproved')?true:false);
00238 
00239       $publicationFormatDao->updateObject($publicationFormat);
00240    }
00241 
00242    //
00243    // Getters and Setters
00244    //
00249    function &getMonograph() {
00250       return $this->_monograph;
00251    }
00252 
00257    function getStageId() {
00258       return $this->_stageId;
00259    }
00260 
00265    function getPhysicalFormat() {
00266       return $this->_isPhysicalFormat;
00267    }
00272    function getPublicationFormatId() {
00273       return $this->_publicationFormatId;
00274    }
00275 
00279    function getFormParams() {
00280       return $this->_formParams;
00281    }
00282 }
00283 
00284 ?>

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