16 import(
'lib.pkp.classes.form.Form');
28 public function __construct($submission, $publication, $salesRights) {
29 parent::__construct(
'controllers/grid/catalogEntry/form/salesRightsForm.tpl');
37 $this->
addCheck(
new FormValidator($this,
'representationId',
'required',
'grid.catalogEntry.publicationFormatRequired'));
39 $this,
'ROWSetting',
'optional',
'grid.catalogEntry.oneROWPerFormat',
40 function($ROWSetting) use ($form, $salesRights) {
42 $pubFormatId = $form->getData(
'representationId');
43 return $ROWSetting ==
'' || $salesRightsDao->getROWByPublicationFormatId($pubFormatId) ==
null ||
44 ($salesRights !=
null && $salesRightsDao->getROWByPublicationFormatId($pubFormatId)->getId() == $salesRights->getId());
68 $this->_salesRights = $salesRights;
84 $this->_submission = $submission;
92 return $this->_publication;
100 $this->_publication = $publication;
114 $this->_data = array(
115 'salesRightsId' => $salesRights->getId(),
116 'type' => $salesRights->getType(),
117 'ROWSetting' => $salesRights->getROWSetting(),
118 'countriesIncluded' => $salesRights->getCountriesIncluded(),
119 'countriesExcluded' => $salesRights->getCountriesExcluded(),
120 'regionsIncluded' => $salesRights->getRegionsIncluded(),
121 'regionsExcluded' => $salesRights->getRegionsExcluded(),
129 public function fetch($request, $template =
null, $display =
false) {
132 $templateMgr->assign(
'submissionId', $submission->getId());
133 $templateMgr->assign(
'publicationId', $this->
getPublication()->getId());
136 $templateMgr->assign(
'countryCodes', $onixCodelistItemDao->getCodes(
'List91'));
137 $templateMgr->assign(
'regionCodes', $onixCodelistItemDao->getCodes(
'List49'));
140 $templateMgr->assign(
'salesRightsId', $salesRights->getId());
141 $templateMgr->assign(
'type', $salesRights->getType());
142 $templateMgr->assign(
'ROWSetting', $salesRights->getROWSetting());
143 $templateMgr->assign(
'countriesIncluded', $salesRights->getCountriesIncluded());
144 $templateMgr->assign(
'countriesExcluded', $salesRights->getCountriesExcluded());
145 $templateMgr->assign(
'regionsIncluded', $salesRights->getRegionsIncluded());
146 $templateMgr->assign(
'regionsExcluded', $salesRights->getRegionsExcluded());
148 $representationId = $salesRights->getPublicationFormatId();
150 $representationId = (int) $request->getUserVar(
'representationId');
154 $publicationFormat = $publicationFormatDao->getById($representationId, $this->
getPublication()->getId());
156 if ($publicationFormat) {
157 $templateMgr->assign(
'representationId', $representationId);
159 $assignedSalesRights = $publicationFormat->getSalesRights();
160 $assignedTypes = array_keys($assignedSalesRights->toAssociativeArray(
'type'));
162 if ($salesRights) $assignedTypes = array_diff($assignedTypes, array($salesRights->getType()));
164 $types = $onixCodelistItemDao->getCodes(
'List46', $assignedTypes);
165 $templateMgr->assign(
'salesRights', $types);
167 fatalError(
'Format not in authorized submission');
170 return parent::fetch($request, $template, $display);
194 parent::execute(...$functionArgs);
200 $publicationFormat = $publicationFormatDao->getById($this->
getData(
'representationId'), $this->
getPublication()->getId());
204 $salesRights = $salesRightsDao->newDataObject();
205 $existingFormat =
false;
206 if ($publicationFormat !=
null) {
207 $salesRights->setPublicationFormatId($publicationFormat->getId());
209 fatalError(
'This assigned format not in authorized submission context!');
212 $existingFormat =
true;
213 if ($publicationFormat->getId() !== $salesRights->getPublicationFormatId())
fatalError(
'Invalid format!');
216 $salesRights->setType($this->
getData(
'type'));
217 $salesRights->setROWSetting($this->
getData(
'ROWSetting')?
true:
false);
218 $salesRights->setCountriesIncluded($this->
getData(
'countriesIncluded') ? $this->
getData(
'countriesIncluded') : array());
219 $salesRights->setCountriesExcluded($this->
getData(
'countriesExcluded') ? $this->
getData(
'countriesExcluded') : array());
220 $salesRights->setRegionsIncluded($this->
getData(
'regionsIncluded') ? $this->
getData(
'regionsIncluded') : array());
221 $salesRights->setRegionsExcluded($this->
getData(
'regionsExcluded') ? $this->
getData(
'regionsExcluded') : array());
223 if ($existingFormat) {
224 $salesRightsDao->updateObject($salesRights);
225 $salesRightsId = $salesRights->getId();
227 $salesRightsId = $salesRightsDao->insertObject($salesRights);
230 return $salesRightsId;