Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
MarketForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class MarketForm extends Form {
21 
23  var $_market;
24 
28  function MarketForm($monograph, $market) {
29  parent::Form('controllers/grid/catalogEntry/form/marketForm.tpl');
30  $this->setMonograph($monograph);
31  $this->setMarket($market);
32 
33  // Validation checks for this form
34  $this->addCheck(new FormValidator($this, 'publicationFormatId', 'required', 'grid.catalogEntry.publicationFormatRequired'));
35  $this->addCheck(new FormValidator($this, 'date', 'required', 'grid.catalogEntry.dateRequired'));
36  $this->addCheck(new FormValidator($this, 'price', 'required', 'grid.catalogEntry.priceRequired'));
37  $this->addCheck(new FormValidatorPost($this));
38  }
39 
40  //
41  // Getters and Setters
42  //
47  function getMarket() {
48  return $this->_market;
49  }
50 
55  function setMarket($market) {
56  $this->_market = $market;
57  }
58 
63  function getMonograph() {
64  return $this->_monograph;
65  }
66 
71  function setMonograph($monograph) {
72  $this->_monograph = $monograph;
73  }
74 
75 
76  //
77  // Overridden template methods
78  //
82  function initData() {
83  $market = $this->getMarket();
84 
85  if ($market) {
86  $this->_data = array(
87  'marketId' => $market->getId(),
88  'countriesIncluded' => $market->getCountriesIncluded(),
89  'countriesExcluded' => $market->getCountriesExcluded(),
90  'regionsIncluded' => $market->getRegionsIncluded(),
91  'regionsExcluded' => $market->getRegionsExcluded(),
92  'date' => $market->getDate(),
93  'dateFormat' => $market->getDateFormat(),
94  'discount' => $market->getDiscount(),
95  'dateRole' => $market->getDateRole(),
96  'agentId' => $market->getAgentId(),
97  'supplierId' => $market->getSupplierId(),
98  );
99  }
100  }
101 
106  function fetch($request) {
107 
108  $templateMgr = TemplateManager::getManager($request);
109  $publicationFormatId = null;
110 
111  $monograph = $this->getMonograph();
112  $templateMgr->assign('submissionId', $monograph->getId());
113  $market = $this->getMarket();
114  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
115  $templateMgr->assign('countryCodes', $onixCodelistItemDao->getCodes('List91')); // countries (CA, US, GB, etc)
116  $templateMgr->assign('regionCodes', $onixCodelistItemDao->getCodes('List49')); // regions (British Columbia, England, etc)
117  $templateMgr->assign('publicationDateFormats', $onixCodelistItemDao->getCodes('List55')); // YYYYMMDD, YYMMDD, etc
118  $templateMgr->assign('publicationDateRoles', $onixCodelistItemDao->getCodes('List163'));
119  $templateMgr->assign('currencyCodes', $onixCodelistItemDao->getCodes('List96')); // GBP, USD, CAD, etc
120  $templateMgr->assign('priceTypeCodes', $onixCodelistItemDao->getCodes('List58')); // without tax, with tax, etc
121  $templateMgr->assign_by_ref('extentTypeCodes',$onixCodelistItemDao->getCodes('List23')); // word count, FM page count, BM page count, main page count, etc
122  $templateMgr->assign_by_ref('taxRateCodes', $onixCodelistItemDao->getCodes('List62')); // higher rate, standard rate, zero rate
123  $templateMgr->assign_by_ref('taxTypeCodes', $onixCodelistItemDao->getCodes('List171')); // VAT, GST
124 
125  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
126  $publishedMonograph = $publishedMonographDao->getById($monograph->getId());
127  $availableAgents = $publishedMonograph->getAgents();
128  $agentOptions = array();
129  while ($agent = $availableAgents->next()) {
130  $agentOptions[$agent->getId()] = $agent->getName();
131  }
132  $templateMgr->assign('availableAgents', $agentOptions);
133 
134  $availableSuppliers = $publishedMonograph->getSuppliers();
135  $supplierOptions = array();
136  while ($supplier = $availableSuppliers->next()) {
137  $supplierOptions[$supplier->getId()] = $supplier->getName();
138  }
139  $templateMgr->assign('availableSuppliers', $supplierOptions);
140 
141  if ($market) {
142  $publicationFormatId = $market->getPublicationFormatId();
143  $templateMgr->assign('marketId', $market->getId());
144  $templateMgr->assign('countriesIncluded', $market->getCountriesIncluded());
145  $templateMgr->assign('countriesExcluded', $market->getCountriesExcluded());
146  $templateMgr->assign('regionsIncluded', $market->getRegionsIncluded());
147  $templateMgr->assign('regionsExcluded', $market->getRegionsExcluded());
148  $templateMgr->assign('date', $market->getDate());
149  $templateMgr->assign('dateRole', $market->getDateRole());
150  $templateMgr->assign('dateFormat', $market->getDateFormat());
151  $templateMgr->assign('discount', $market->getDiscount());
152  $templateMgr->assign('price', $market->getPrice());
153  $templateMgr->assign('priceTypeCode', $market->getPriceTypeCode());
154  $templateMgr->assign('currencyCode', $market->getCurrencyCode() != '' ? $market->getCurrencyCode() : 'CAD');
155  $templateMgr->assign('taxRateCode', $market->getTaxRateCode());
156  $templateMgr->assign('taxTypeCode', $market->getTaxTypeCode() != '' ? $market->getTaxTypeCode() : '02');
157  $templateMgr->assign('agentId', $market->getAgentId());
158  $templateMgr->assign('supplierId', $market->getSupplierId());
159 
160  $publicationFormatId = $market->getPublicationFormatId();
161  } else { // loading a blank form
162  $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
163  $templateMgr->assign('dateFormat', '20'); // YYYYMMDD Onix code as a default
164  $templateMgr->assign('dateRole', '01'); // 'Date of Publication' as default
165  $templateMgr->assign('currencyCode', 'CAD');
166  }
167 
168  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
169  $publicationFormat = $publicationFormatDao->getById($publicationFormatId, $monograph->getId());
170 
171  if ($publicationFormat) { // the format exists for this monograph
172  $templateMgr->assign('publicationFormatId', $publicationFormatId);
173  } else {
174  fatalError('Format not in authorized monograph');
175  }
176 
177  return parent::fetch($request);
178  }
179 
184  function readInputData() {
185  $this->readUserVars(array(
186  'marketId',
187  'publicationFormatId',
188  'countriesIncluded',
189  'countriesExcluded',
190  'regionsIncluded',
191  'regionsExcluded',
192  'date',
193  'dateFormat',
194  'dateRole',
195  'discount',
196  'price',
197  'priceTypeCode',
198  'currencyCode',
199  'taxRateCode',
200  'taxTypeCode',
201  'agentId',
202  'supplierId',
203  ));
204  }
205 
210  function execute() {
211  $marketDao = DAORegistry::getDAO('MarketDAO');
212  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
213 
214  $monograph = $this->getMonograph();
215  $market = $this->getMarket();
216  $publicationFormat = $publicationFormatDao->getById($this->getData('publicationFormatId'), $monograph->getId());
217 
218  if (!$market) {
219  // this is a new assigned format to this published monograph
220  $market = $marketDao->newDataObject();
221  if ($publicationFormat != null) { // ensure this assigned format is in this monograph
222  $market->setPublicationFormatId($publicationFormat->getId());
223  $existingFormat = false;
224  } else {
225  fatalError('This assigned format not in authorized monograph context!');
226  }
227  } else {
228  $existingFormat = true;
229  if ($publicationFormat->getId() !== $market->getPublicationFormatId()) fatalError('Invalid format!');
230  }
231 
232  $market->setCountriesIncluded($this->getData('countriesIncluded') ? $this->getData('countriesIncluded') : array());
233  $market->setCountriesExcluded($this->getData('countriesExcluded') ? $this->getData('countriesExcluded') : array());
234  $market->setRegionsIncluded($this->getData('regionsIncluded') ? $this->getData('regionsIncluded') : array());
235  $market->setRegionsExcluded($this->getData('regionsExcluded') ? $this->getData('regionsExcluded') : array());
236  $market->setDate($this->getData('date'));
237  $market->setDateFormat($this->getData('dateFormat'));
238  $market->setDiscount($this->getData('discount'));
239  $market->setDateRole($this->getData('dateRole'));
240  $market->setPrice($this->getData('price'));
241  $market->setPriceTypeCode($this->getData('priceTypeCode'));
242  $market->setCurrencyCode($this->getData('currencyCode'));
243  $market->setTaxRateCode($this->getData('taxRateCode'));
244  $market->setTaxTypeCode($this->getData('taxTypeCode'));
245  $market->setAgentId($this->getData('agentId'));
246  $market->setSupplierId($this->getData('supplierId'));
247 
248  if ($existingFormat) {
249  $marketDao->updateObject($market);
250  $marketId = $market->getId();
251  } else {
252  $marketId = $marketDao->insertObject($market);
253  }
254 
255  return $marketId;
256  }
257 }
258 
259 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Form validation check to make sure the form is POSTed.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
getData($key)
Definition: Form.inc.php:210
Form for adding/editing a market region entry.
MarketForm($monograph, $market)
fetch($request)
setMonograph($monograph)
Class to represent a form validation check.
setMarket($market)