16 import(
'lib.pkp.classes.form.Form');
31 public function __construct($submission, $publication, $identificationCode) {
32 parent::__construct(
'controllers/grid/catalogEntry/form/codeForm.tpl');
40 $this->
addCheck(
new FormValidator($this,
'representationId',
'required',
'grid.catalogEntry.publicationFormatRequired'));
61 $this->_identificationCode = $identificationCode;
77 $this->_submission = $submission;
93 $this->_publication = $publication;
107 $this->_data = array(
108 'identificationCodeId' => $code->getId(),
109 'code' => $code->getCode(),
110 'value' => $code->getValue(),
118 public function fetch($request, $template =
null, $display =
false) {
121 $templateMgr->assign(
'submissionId', $submission->getId());
122 $templateMgr->assign(
'publicationId', $this->
getPublication()->getId());
125 if ($identificationCode) {
126 $templateMgr->assign(
'identificationCodeId', $identificationCode->getId());
127 $templateMgr->assign(
'code', $identificationCode->getCode());
128 $templateMgr->assign(
'value', $identificationCode->getValue());
129 $representationId = $identificationCode->getPublicationFormatId();
131 $representationId = (int) $request->getUserVar(
'representationId');
135 $publicationFormat = $publicationFormatDao->getById($representationId, $this->
getPublication()->getId());
137 if ($publicationFormat) {
138 $templateMgr->assign(
'representationId', $representationId);
139 $identificationCodes = $publicationFormat->getIdentificationCodes();
140 $assignedCodes = array_keys($identificationCodes->toAssociativeArray(
'code'));
141 if ($identificationCode) $assignedCodes = array_diff($assignedCodes, array($identificationCode->getCode()));
146 foreach ($pubIdPlugins as $plugin) {
147 if ($plugin->getEnabled() && $plugin->getPubIdType() ==
'doi') {
148 $assignedCodes[] =
'06';
151 $codes = $onixCodelistItemDao->getCodes(
'List5', $assignedCodes);
152 $templateMgr->assign(
'identificationCodes', $codes);
154 fatalError(
'Format not in authorized submission');
157 return parent::fetch($request, $template, $display);
166 'identificationCodeId',
177 parent::execute(...$functionArgs);
183 $publicationFormat = $publicationFormatDao->getById($this->
getData(
'representationId', $this->
getPublication()->getId()));
185 if (!$identificationCode) {
187 $identificationCode = $identificationCodeDao->newDataObject();
188 $existingFormat =
false;
189 if ($publicationFormat !=
null) {
190 $identificationCode->setPublicationFormatId($publicationFormat->getId());
192 fatalError(
'This format not in authorized submission context!');
195 $existingFormat =
true;
196 if ($publicationFormat->getId() !== $identificationCode->getPublicationFormatId())
fatalError(
'Invalid format!');
199 $identificationCode->setCode($this->
getData(
'code'));
200 $identificationCode->setValue($this->
getData(
'value'));
202 if ($existingFormat) {
203 $identificationCodeDao->updateObject($identificationCode);
204 $identificationCodeId = $identificationCode->getId();
206 $identificationCodeId = $identificationCodeDao->insertObject($identificationCode);
209 return $identificationCodeId;