17 import(
'lib.pkp.classes.form.Form');
36 parent::__construct(
'controllers/grid/users/chapter/form/chapterForm.tpl');
46 $this->
addCheck(
new FormValidatorLocale($this,
'title',
'required',
'metadata.property.validationMessage.title', $publication->getData(
'locale')));
68 $this->_monograph = $monograph;
84 $this->_publication = $publication;
100 $this->_chapter = $chapter;
115 $this->
setData(
'enableChapterPublicationDates', (
bool) $this->
getMonograph()->getEnableChapterPublicationDates());
119 $this->
setData(
'chapterId', $chapter->getId());
120 $this->
setData(
'title', $chapter->getTitle());
121 $this->
setData(
'subtitle', $chapter->getSubtitle());
122 $this->
setData(
'abstract', $chapter->getAbstract());
123 $this->
setData(
'datePublished', $chapter->getDatePublished());
124 $this->
setData(
'pages', $chapter->getPages());
127 $this->
setData(
'subtitle',
null);
128 $this->
setData(
'abstract',
null);
129 $this->
setData(
'datePublished',
null);
137 function fetch($request, $template =
null, $display =
false) {
139 $chapterAuthorOptions = [];
140 $selectedChapterAuthors = [];
143 foreach ($selectedChapterAuthors as $selectedChapterAuthor) {
144 $chapterAuthorOptions[$selectedChapterAuthor->getId()] = $selectedChapterAuthor->getFullName();
148 foreach ($authorsIterator as $author) {
150 foreach ($chapterAuthorOptions as $chapterAuthorOptionId => $chapterAuthorOption) {
151 if ($chapterAuthorOptionId === $author->getId()) {
156 $chapterAuthorOptions[$author->getId()] = $author->getFullName();
161 $templateMgr->assign([
162 'chapterAuthorOptions' => $chapterAuthorOptions,
163 'selectedChapterAuthors' => array_map(
function($author) {
return $author->getId(); }, $selectedChapterAuthors),
168 $chapterFileOptions = [];
169 foreach ($submissionFiles as $submissionFile) {
170 if (!$submissionFile->getData(
'chapterId') || $submissionFile->getData(
'chapterId') == $this->getChapter()->getId()) {
171 $chapterFileOptions[$submissionFile->getFileId()] = $submissionFile->getLocalizedName();
174 $selectedChapterFiles = [];
175 foreach ($submissionFiles as $submissionFile) {
176 if ($submissionFile->getData(
'chapterId') == $this->getChapter()->getId()) {
177 $selectedChapterFiles[] = $submissionFile->getFileId();
181 $templateMgr->assign([
182 'chapterFileOptions' => $chapterFileOptions,
183 'selectedChapterFiles' => $selectedChapterFiles,
187 return parent::fetch($request, $template, $display);
195 $this->
readUserVars(array(
'title',
'subtitle',
'authors',
'files',
'abstract',
'datePublished',
'pages'));
203 parent::execute(...$functionParams);
208 $isEdit = !!$chapter;
211 $chapter->setTitle($this->
getData(
'title'),
null);
212 $chapter->setSubtitle($this->
getData(
'subtitle'),
null);
213 $chapter->setAbstract($this->
getData(
'abstract'),
null);
214 $chapter->setDatePublished($this->
getData(
'datePublished'));
215 $chapter->setPages($this->
getData(
'pages'));
216 $chapterDao->updateObject($chapter);
218 $chapter = $chapterDao->newDataObject();
219 $chapter->setData(
'publicationId', $this->
getPublication()->getId());
220 $chapter->setTitle($this->
getData(
'title'),
null);
221 $chapter->setSubtitle($this->
getData(
'subtitle'),
null);
222 $chapter->setAbstract($this->
getData(
'abstract'),
null);
223 $chapter->setDatePublished($this->
getData(
'datePublished'));
224 $chapter->setPages($this->
getData(
'pages'));
225 $chapter->setSequence(REALLY_BIG_NUMBER);
226 $chapterDao->insertChapter($chapter);
227 $chapterDao->resequenceChapters($this->
getPublication()->getId());
234 foreach ((array) $this->
getData(
'authors') as $seq => $authorId) {
240 $selectedFiles = (array) $this->
getData(
'files');
242 foreach ($allFiles as $file) {
243 $revisions =
DAORegistry::getDAO(
'SubmissionFileDAO')->getAllRevisions($file->getId(),
null, $this->getMonograph()->getId());
244 foreach ($revisions as $revision) {
245 if (in_array($revision->getFileId(), $selectedFiles)) {
246 $revision->setData(
'chapterId', $this->
getChapter()->getId());
247 } elseif ($revision->getData(
'chapterId') == $chapter->getId()) {
248 $revision->setData(
'chapterId',
null);