16 import(
'lib.pkp.classes.form.Form');
28 public function __construct($submission, $publication, $market) {
29 parent::__construct(
'controllers/grid/catalogEntry/form/marketForm.tpl');
35 $this->
addCheck(
new FormValidator($this,
'representationId',
'required',
'grid.catalogEntry.publicationFormatRequired'));
58 $this->_market = $market;
74 $this->_submission = $submission;
82 return $this->_publication;
90 $this->_publication = $publication;
104 $this->_data = array(
105 'marketId' => $market->getId(),
106 'countriesIncluded' => $market->getCountriesIncluded(),
107 'countriesExcluded' => $market->getCountriesExcluded(),
108 'regionsIncluded' => $market->getRegionsIncluded(),
109 'regionsExcluded' => $market->getRegionsExcluded(),
110 'date' => $market->getDate(),
111 'dateFormat' => $market->getDateFormat(),
112 'discount' => $market->getDiscount(),
113 'dateRole' => $market->getDateRole(),
114 'agentId' => $market->getAgentId(),
115 'supplierId' => $market->getSupplierId(),
123 public function fetch($request, $template =
null, $display =
false) {
126 $templateMgr->assign(
'submissionId', $submission->getId());
127 $templateMgr->assign(
'publicationId', $this->
getPublication()->getId());
130 $templateMgr->assign(array(
131 'countryCodes' => $onixCodelistItemDao->getCodes(
'List91'),
132 'regionCodes' => $onixCodelistItemDao->getCodes(
'List49'),
133 'publicationDateFormats' => $onixCodelistItemDao->getCodes(
'List55'),
134 'publicationDateRoles' => $onixCodelistItemDao->getCodes(
'List163'),
135 'currencyCodes' => $onixCodelistItemDao->getCodes(
'List96'),
136 'priceTypeCodes' => $onixCodelistItemDao->getCodes(
'List58'),
137 'extentTypeCodes' => $onixCodelistItemDao->getCodes(
'List23'),
138 'taxRateCodes' => $onixCodelistItemDao->getCodes(
'List62'),
139 'taxTypeCodes' => $onixCodelistItemDao->getCodes(
'List171'),
142 $availableAgents =
DAORegistry::getDAO(
'RepresentativeDAO')->getAgentsByMonographId($submission->getId());
143 $agentOptions = array();
144 while ($agent = $availableAgents->next()) {
145 $agentOptions[$agent->getId()] = $agent->getName();
147 $templateMgr->assign(
'availableAgents', $agentOptions);
149 $availableSuppliers =
DAORegistry::getDAO(
'RepresentativeDAO')->getSuppliersByMonographId($submission->getId());
150 $supplierOptions = array();
151 while ($supplier = $availableSuppliers->next()) {
152 $supplierOptions[$supplier->getId()] = $supplier->getName();
154 $templateMgr->assign(
'availableSuppliers', $supplierOptions);
157 $templateMgr->assign(array(
158 'marketId' => $market->getId(),
159 'countriesIncluded' => $market->getCountriesIncluded(),
160 'countriesExcluded' => $market->getCountriesExcluded(),
161 'regionsIncluded' => $market->getRegionsIncluded(),
162 'regionsExcluded' => $market->getRegionsExcluded(),
163 'date' => $market->getDate(),
164 'dateRole' => $market->getDateRole(),
165 'dateFormat' => $market->getDateFormat(),
166 'discount' => $market->getDiscount(),
167 'price' => $market->getPrice(),
168 'priceTypeCode' => $market->getPriceTypeCode(),
169 'currencyCode' => $market->getCurrencyCode() !=
'' ? $market->getCurrencyCode() :
'CAD',
170 'taxRateCode' => $market->getTaxRateCode(),
171 'taxTypeCode' => $market->getTaxTypeCode() !=
'' ? $market->getTaxTypeCode() :
'02',
172 'agentId' => $market->getAgentId(),
173 'supplierId' => $market->getSupplierId(),
176 $representationId = $market->getPublicationFormatId();
178 $representationId = (int) $request->getUserVar(
'representationId');
179 $templateMgr->assign(array(
180 'dateFormat' =>
'20',
182 'currencyCode' =>
'CAD',
187 $publicationFormat = $publicationFormatDao->getById($representationId, $this->
getPublication()->getId());
189 if ($publicationFormat) {
190 $templateMgr->assign(
'representationId', $representationId);
192 fatalError(
'Format not in authorized submission');
195 return parent::fetch($request, $template, $display);
228 parent::execute(...$functionArgs);
234 $publicationFormat = $publicationFormatDao->getById($this->
getData(
'representationId'), $this->
getPublication()->getId());
238 $market = $marketDao->newDataObject();
239 $existingFormat =
false;
240 if ($publicationFormat !=
null) {
241 $market->setPublicationFormatId($publicationFormat->getId());
243 fatalError(
'This assigned format not in authorized submission context!');
246 $existingFormat =
true;
247 if ($publicationFormat->getId() !== $market->getPublicationFormatId())
fatalError(
'Invalid format!');
250 $market->setCountriesIncluded($this->
getData(
'countriesIncluded') ? $this->
getData(
'countriesIncluded') : array());
251 $market->setCountriesExcluded($this->
getData(
'countriesExcluded') ? $this->
getData(
'countriesExcluded') : array());
252 $market->setRegionsIncluded($this->
getData(
'regionsIncluded') ? $this->
getData(
'regionsIncluded') : array());
253 $market->setRegionsExcluded($this->
getData(
'regionsExcluded') ? $this->
getData(
'regionsExcluded') : array());
254 $market->setDate($this->
getData(
'date'));
255 $market->setDateFormat($this->
getData(
'dateFormat'));
256 $market->setDiscount($this->
getData(
'discount'));
257 $market->setDateRole($this->
getData(
'dateRole'));
258 $market->setPrice($this->
getData(
'price'));
259 $market->setPriceTypeCode($this->
getData(
'priceTypeCode'));
260 $market->setCurrencyCode($this->
getData(
'currencyCode'));
261 $market->setTaxRateCode($this->
getData(
'taxRateCode'));
262 $market->setTaxTypeCode($this->
getData(
'taxTypeCode'));
263 $market->setAgentId($this->
getData(
'agentId'));
264 $market->setSupplierId($this->
getData(
'supplierId'));
266 if ($existingFormat) {
267 $marketDao->updateObject($market);
268 $marketId = $market->getId();
270 $marketId = $marketDao->insertObject($market);