17 import(
'lib.pkp.classes.form.Form');
31 function __construct($request, $issue, $issueGalley =
null) {
32 parent::__construct(
'controllers/grid/issueGalleys/form/issueGalleyForm.tpl');
33 $this->_issue = $issue;
34 $this->_issueGalley = $issueGalley;
44 $journal = $request->getJournal();
46 $this,
'galleyLocale',
'required',
'editor.issues.galleyLocaleRequired',
47 function($galleyLocale) use ($journal) {
48 return in_array($galleyLocale, $journal->getSupportedFormLocales());
61 function fetch($request, $template =
null, $display =
false) {
62 $journal = $request->getJournal();
65 $templateMgr->assign(array(
66 'issueId' => $this->_issue->getId(),
67 'supportedLocales' => $journal->getSupportedLocaleNames(),
68 'enablePublisherId' => in_array(
'issueGalley', (array) $request->getContext()->getData(
'enablePublisherId')),
70 if ($this->_issueGalley) $templateMgr->assign(array(
71 'issueGalleyId' => $this->_issueGalley->getId(),
72 'issueGalley' => $this->_issueGalley,
75 return parent::fetch($request, $template, $display);
81 function validate($callHooks =
true) {
84 $journal = $request->getJournal();
87 $publicGalleyId = $this->
getData(
'publicGalleyId');
88 if ($publicGalleyId) {
89 if (ctype_digit((
string) $publicGalleyId)) {
90 $this->
addError(
'publicGalleyId', __(
'editor.publicIdentificationNumericNotAllowed', array(
'publicIdentifier' => $publicGalleyId)));
92 } elseif ($journalDao->anyPubIdExists($journal->getId(),
'publisher-id', $publicGalleyId, ASSOC_TYPE_ISSUE_GALLEY, $this->_issueGalley?$this->_issueGalley->getId():
null,
true)) {
93 $this->
addError(
'publicGalleyId', __(
'editor.publicIdentificationExistsForTheSameType', array(
'publicIdentifier' => $publicGalleyId)));
98 if ($this->
getData(
'urlPath')) {
99 if (ctype_digit((
string) $this->
getData(
'urlPath'))) {
100 $this->
addError(
'urlPath', __(
'publication.urlPath.numberInvalid'));
104 $issueGalley = $issueGalleyDao->getByBestId($this->
getData(
'urlPath'), $this->_issue->getId());
106 (!$this->_issueGalley || $this->_issueGalley->getId() !== $issueGalley->getId())
108 $this->
addError(
'urlPath', __(
'publication.urlPath.duplicate'));
114 return parent::validate($callHooks);
121 if ($this->_issueGalley) {
122 $this->_data = array(
123 'label' => $this->_issueGalley->getLabel(),
124 'publicGalleyId' => $this->_issueGalley->getStoredPubId(
'publisher-id'),
125 'galleyLocale' => $this->_issueGalley->getLocale(),
126 'urlPath' => $this->_issueGalley->getData(
'urlPath'),
129 $this->_data = array();
151 function execute(...$functionArgs) {
152 import(
'classes.file.IssueFileManager');
156 $journal = $request->getJournal();
157 $user = $request->getUser();
164 $temporaryFile = $temporaryFileDao->getTemporaryFile($this->
getData(
'temporaryFileId'), $user->getId());
166 parent::execute(...$functionArgs);
170 if ($temporaryFile) {
172 if ($issueGalley->getFileId()) {
173 $issueFileManager->deleteById($issueGalley->getFileId());
176 $issueFile = $issueFileManager->fromTemporaryFile($temporaryFile);
177 $issueGalley->setFileId($issueFile->getId());
180 $issueGalley->setLabel($this->
getData(
'label'));
181 $issueGalley->setStoredPubId(
'publisher-id', $this->
getData(
'publicGalleyId'));
182 $issueGalley->setLocale($this->
getData(
'galleyLocale'));
183 $issueGalley->setData(
'urlPath', $this->
getData(
'urlPath'));
186 $issueGalleyDao->updateObject($issueGalley);
189 $issueGalleyFile = $issueFileManager->fromTemporaryFile($temporaryFile);
191 $issueGalley = $issueGalleyDao->newDataObject();
192 $issueGalley->setIssueId($this->_issue->getId());
193 $issueGalley->setFileId($issueGalleyFile->getId());
194 $issueGalley->setData(
'urlPath', $this->
getData(
'urlPath'));
196 if ($this->
getData(
'label') ==
null) {
198 if (isset($fileType)) {
199 if(strstr($fileType,
'pdf')) {
200 $issueGalley->setLabel(
'PDF');
201 }
else if (strstr($fileType,
'postscript')) {
202 $issueGalley->setLabel(
'PostScript');
203 }
else if (strstr($fileType,
'xml')) {
204 $issueGalley->setLabel(
'XML');
208 if ($issueGalley->getLabel() ==
null) {
209 $issueGalley->setLabel(__(
'common.untitled'));
213 $issueGalley->setLabel($this->
getData(
'label'));
215 $issueGalley->setLocale($this->
getData(
'galleyLocale'));
217 $issueGalley->setStoredPubId(
'publisher-id', $this->
getData(
'publicGalleyId'));
220 $issueGalleyDao->insertObject($issueGalley);
221 $this->_issueGalley = $issueGalley;
224 return $this->_issueGalley->getId();