16 import(
'lib.pkp.classes.form.Form');
31 public function __construct($submission, $publication, $publicationDate) {
32 parent::__construct(
'controllers/grid/catalogEntry/form/pubDateForm.tpl');
40 $this->
addCheck(
new FormValidator($this,
'dateFormat',
'required',
'grid.catalogEntry.dateFormatRequired'));
43 $this,
'date',
'required',
'grid.catalogEntry.dateRequired',
44 function($date) use ($form) {
46 $dateFormat = $form->getData(
'dateFormat');
47 if (!$dateFormat)
return false;
48 $dateFormats = $onixCodelistItemDao->getCodes(
'List55');
49 $format = $dateFormats[$dateFormat];
50 if (stristr($format,
'string') && $date !=
'')
return true;
51 $format = trim(preg_replace(
'/\s*\(.*?\)/i',
'', $format));
52 if (count(str_split($date)) == count(str_split($format)))
return true;
57 $this->
addCheck(
new FormValidator($this,
'representationId',
'required',
'grid.catalogEntry.publicationFormatRequired'));
78 $this->_publicationDate = $publicationDate;
94 $this->_submission = $submission;
110 $this->_publication = $publication;
124 $this->_data = array(
125 'publicationDateId' => $date->getId(),
126 'role' => $date->getRole(),
127 'dateFormat' => $date->getDateFormat(),
128 'date' => $date->getDate(),
136 public function fetch($request, $template =
null, $display =
false) {
139 $templateMgr->assign(
'submissionId', $submission->getId());
140 $templateMgr->assign(
'publicationId', $this->
getPublication()->getId());
143 if ($publicationDate) {
144 $templateMgr->assign(
'publicationDateId', $publicationDate->getId());
145 $templateMgr->assign(
'role', $publicationDate->getRole());
146 $templateMgr->assign(
'dateFormat', $publicationDate->getDateFormat());
147 $templateMgr->assign(
'date', $publicationDate->getDate());
148 $representationId = $publicationDate->getPublicationFormatId();
150 $representationId = (int) $request->getUserVar(
'representationId');
151 $templateMgr->assign(
'dateFormat',
'20');
155 $publicationFormat = $publicationFormatDao->getById($representationId, $this->
getPublication()->getId());
157 if ($publicationFormat) {
158 $templateMgr->assign(
'representationId', $representationId);
159 $publicationDates = $publicationFormat->getPublicationDates();
160 $assignedRoles = array_keys($publicationDates->toAssociativeArray(
'role'));
161 if ($publicationDate) $assignedRoles = array_diff($assignedRoles, array($publicationDate->getRole()));
163 $roles = $onixCodelistItemDao->getCodes(
'List163', $assignedRoles);
164 $templateMgr->assign(
'publicationDateRoles', $roles);
167 $dateFormats = $onixCodelistItemDao->getCodes(
'List55');
168 $templateMgr->assign(
'publicationDateFormats', $dateFormats);
170 fatalError(
'Format not in authorized submission');
173 return parent::fetch($request, $template, $display);
194 parent::execute(...$functionArgs);
200 $publicationFormat = $publicationFormatDao->getById($this->
getData(
'representationId'), $this->
getPublication()->getId());
202 if (!$publicationDate) {
204 $publicationDate = $publicationDateDao->newDataObject();
205 $existingFormat =
false;
206 if ($publicationFormat !=
null) {
207 $publicationDate->setPublicationFormatId($publicationFormat->getId());
209 fatalError(
'This assigned format not in authorized submission context!');
212 $existingFormat =
true;
213 if ($publicationFormat->getId() !== $publicationDate->getPublicationFormatId())
fatalError(
'Invalid format!');
216 $publicationDate->setRole($this->
getData(
'role'));
217 $publicationDate->setDateFormat($this->
getData(
'dateFormat'));
218 $publicationDate->setDate($this->
getData(
'date'));
220 if ($existingFormat) {
221 $publicationDateDao->updateObject($publicationDate);
222 $publicationDateId = $publicationDate->getId();
224 $publicationDateId = $publicationDateDao->insertObject($publicationDate);
227 return $publicationDateId;