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

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

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class MarketForm extends Form {
00019    var $_monograph;
00020 
00022    var $_market;
00023 
00027    function MarketForm($monograph, $market) {
00028       parent::Form('controllers/grid/catalogEntry/form/marketForm.tpl');
00029       $this->setMonograph($monograph);
00030       $this->setMarket($market);
00031 
00032       // Validation checks for this form
00033       $this->addCheck(new FormValidator($this, 'publicationFormatId', 'required', 'grid.catalogEntry.publicationFormatRequired'));
00034       $this->addCheck(new FormValidator($this, 'date', 'required', 'grid.catalogEntry.dateRequired'));
00035       $this->addCheck(new FormValidator($this, 'price', 'required', 'grid.catalogEntry.priceRequired'));
00036       $this->addCheck(new FormValidatorPost($this));
00037    }
00038 
00039    //
00040    // Getters and Setters
00041    //
00046    function &getMarket() {
00047       return $this->_market;
00048    }
00049 
00054    function setMarket($market) {
00055       $this->_market =& $market;
00056    }
00057 
00062    function &getMonograph() {
00063       return $this->_monograph;
00064    }
00065 
00070    function setMonograph($monograph) {
00071       $this->_monograph =& $monograph;
00072    }
00073 
00074 
00075    //
00076    // Overridden template methods
00077    //
00081    function initData() {
00082       $market =& $this->getMarket();
00083 
00084       if ($market) {
00085          $this->_data = array(
00086             'marketId' => $market->getId(),
00087             'countriesIncluded' => $market->getCountriesIncluded(),
00088             'countriesExcluded' => $market->getCountriesExcluded(),
00089             'regionsIncluded' => $market->getRegionsIncluded(),
00090             'regionsExcluded' => $market->getRegionsExcluded(),
00091             'date' => $market->getDate(),
00092             'dateFormat' => $market->getDateFormat(),
00093             'discount' => $market->getDiscount(),
00094             'dateRole' => $market->getDateRole(),
00095             'agentId' => $market->getAgentId(),
00096             'supplierId' => $market->getSupplierId(),
00097          );
00098       }
00099    }
00100 
00105    function fetch(&$request) {
00106 
00107       $templateMgr =& TemplateManager::getManager();
00108       $publicationFormatId = null;
00109 
00110       $monograph =& $this->getMonograph();
00111       $templateMgr->assign('monographId', $monograph->getId());
00112       $market =& $this->getMarket();
00113       $onixCodelistItemDao =& DAORegistry::getDAO('ONIXCodelistItemDAO');
00114       $templateMgr->assign_by_ref('countryCodes', $onixCodelistItemDao->getCodes('List91')); // countries (CA, US, GB, etc)
00115       $templateMgr->assign_by_ref('regionCodes', $onixCodelistItemDao->getCodes('List49')); // regions (British Columbia, England, etc)
00116       $templateMgr->assign_by_ref('publicationDateFormats', $onixCodelistItemDao->getCodes('List55')); // YYYYMMDD, YYMMDD, etc
00117       $templateMgr->assign_by_ref('publicationDateRoles', $onixCodelistItemDao->getCodes('List163'));
00118       $templateMgr->assign_by_ref('currencyCodes', $onixCodelistItemDao->getCodes('List96')); // GBP, USD, CAD, etc
00119       $templateMgr->assign_by_ref('priceTypeCodes', $onixCodelistItemDao->getCodes('List58')); // without tax, with tax, etc
00120       $templateMgr->assign_by_ref('extentTypeCodes',$onixCodelistItemDao->getCodes('List23')); // word count, FM page count, BM page count, main page count, etc
00121       $templateMgr->assign_by_ref('taxRateCodes', $onixCodelistItemDao->getCodes('List62')); // higher rate, standard rate, zero rate
00122       $templateMgr->assign_by_ref('taxTypeCodes', $onixCodelistItemDao->getCodes('List171')); // VAT, GST
00123 
00124       $publishedMonographDao =& DAORegistry::getDAO('PublishedMonographDAO');
00125       $publishedMonograph =& $publishedMonographDao->getById($monograph->getId());
00126       $availableAgents =& $publishedMonograph->getAgents();
00127       $agentOptions = array();
00128       while ($agent =& $availableAgents->next()) {
00129          $agentOptions[$agent->getId()] = $agent->getName();
00130       }
00131       $templateMgr->assign_by_ref('availableAgents', $agentOptions);
00132 
00133       $availableSuppliers =& $publishedMonograph->getSuppliers();
00134       $supplierOptions = array();
00135       while ($supplier =& $availableSuppliers->next()) {
00136          $supplierOptions[$supplier->getId()] = $supplier->getName();
00137       }
00138       $templateMgr->assign_by_ref('availableSuppliers', $supplierOptions);
00139 
00140       if ($market) {
00141          $publicationFormatId = $market->getPublicationFormatId();
00142          $templateMgr->assign('marketId', $market->getId());
00143          $templateMgr->assign('countriesIncluded', $market->getCountriesIncluded());
00144          $templateMgr->assign('countriesExcluded', $market->getCountriesExcluded());
00145          $templateMgr->assign('regionsIncluded', $market->getRegionsIncluded());
00146          $templateMgr->assign('regionsExcluded', $market->getRegionsExcluded());
00147          $templateMgr->assign('date', $market->getDate());
00148          $templateMgr->assign('dateRole', $market->getDateRole());
00149          $templateMgr->assign('dateFormat', $market->getDateFormat());
00150          $templateMgr->assign('discount', $market->getDiscount());
00151          $templateMgr->assign('price', $market->getPrice());
00152          $templateMgr->assign('priceTypeCode', $market->getPriceTypeCode());
00153          $templateMgr->assign('currencyCode', $market->getCurrencyCode() != '' ? $market->getCurrencyCode() : 'CAD');
00154          $templateMgr->assign('taxRateCode', $market->getTaxRateCode());
00155          $templateMgr->assign('taxTypeCode', $market->getTaxTypeCode() != '' ? $market->getTaxTypeCode() : '02');
00156          $templateMgr->assign('agentId', $market->getAgentId());
00157          $templateMgr->assign('supplierId', $market->getSupplierId());
00158 
00159          $publicationFormatId = $market->getPublicationFormatId();
00160       } else { // loading a blank form
00161          $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
00162          $templateMgr->assign('dateFormat', '20'); // YYYYMMDD Onix code as a default
00163          $templateMgr->assign('dateRole', '01'); // 'Date of Publication' as default
00164          $templateMgr->assign('currencyCode', 'CAD');
00165       }
00166 
00167       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00168       $publicationFormat =& $publicationFormatDao->getById($publicationFormatId, $monograph->getId());
00169 
00170       if ($publicationFormat) { // the format exists for this monograph
00171          $templateMgr->assign('publicationFormatId', $publicationFormatId);
00172       } else {
00173          fatalError('Format not in authorized monograph');
00174       }
00175 
00176       return parent::fetch($request);
00177    }
00178 
00183    function readInputData() {
00184       $this->readUserVars(array(
00185          'marketId',
00186          'publicationFormatId',
00187          'countriesIncluded',
00188          'countriesExcluded',
00189          'regionsIncluded',
00190          'regionsExcluded',
00191          'date',
00192          'dateFormat',
00193          'dateRole',
00194          'discount',
00195          'price',
00196          'priceTypeCode',
00197          'currencyCode',
00198          'taxRateCode',
00199          'taxTypeCode',
00200          'agentId',
00201          'supplierId',
00202       ));
00203    }
00204 
00209    function execute() {
00210       $marketDao =& DAORegistry::getDAO('MarketDAO');
00211       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00212 
00213       $monograph = $this->getMonograph();
00214       $market =& $this->getMarket();
00215       $publicationFormat =& $publicationFormatDao->getById($this->getData('publicationFormatId'), $monograph->getId());
00216 
00217       if (!$market) {
00218          // this is a new assigned format to this published monograph
00219          $market = $marketDao->newDataObject();
00220          if ($publicationFormat != null) { // ensure this assigned format is in this monograph
00221             $market->setPublicationFormatId($publicationFormat->getId());
00222             $existingFormat = false;
00223          } else {
00224             fatalError('This assigned format not in authorized monograph context!');
00225          }
00226       } else {
00227          $existingFormat = true;
00228          if ($publicationFormat->getId() !== $market->getPublicationFormatId()) fatalError('Invalid format!');
00229       }
00230 
00231       $market->setCountriesIncluded($this->getData('countriesIncluded') ? $this->getData('countriesIncluded') : array());
00232       $market->setCountriesExcluded($this->getData('countriesExcluded') ? $this->getData('countriesExcluded') : array());
00233       $market->setRegionsIncluded($this->getData('regionsIncluded') ? $this->getData('regionsIncluded') : array());
00234       $market->setRegionsExcluded($this->getData('regionsExcluded') ? $this->getData('regionsExcluded') : array());
00235       $market->setDate($this->getData('date'));
00236       $market->setDateFormat($this->getData('dateFormat'));
00237       $market->setDiscount($this->getData('discount'));
00238       $market->setDateRole($this->getData('dateRole'));
00239       $market->setPrice($this->getData('price'));
00240       $market->setPriceTypeCode($this->getData('priceTypeCode'));
00241       $market->setCurrencyCode($this->getData('currencyCode'));
00242       $market->setTaxRateCode($this->getData('taxRateCode'));
00243       $market->setTaxTypeCode($this->getData('taxTypeCode'));
00244       $market->setAgentId($this->getData('agentId'));
00245       $market->setSupplierId($this->getData('supplierId'));
00246 
00247       if ($existingFormat) {
00248          $marketDao->updateObject($market);
00249          $marketId = $market->getId();
00250       } else {
00251          $marketId = $marketDao->insertObject($market);
00252       }
00253 
00254       return $marketId;
00255    }
00256 }
00257 
00258 ?>

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