-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathCatalogEntryForm.php
More file actions
176 lines (159 loc) · 7.37 KB
/
Copy pathCatalogEntryForm.php
File metadata and controls
176 lines (159 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* @file classes/components/form/publication/CatalogEntryForm.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class CatalogEntryForm
*
* @ingroup classes_controllers_form
*
* @brief A preset form for entering a publication's catalog entry details,
* such as series, category and cover image.
*/
namespace APP\components\forms\publication;
use APP\facades\Repo;
use APP\publication\Publication;
use APP\submission\Submission;
use PKP\components\forms\FieldAutosuggestPreset;
use PKP\components\forms\FieldRichTextarea;
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FieldText;
use PKP\components\forms\FieldUploadImage;
use PKP\components\forms\FormComponent;
use PKP\publication\enums\UpdateType;
class CatalogEntryForm extends FormComponent
{
public const FORM_CATALOG_ENTRY = 'catalogEntry';
public const GROUP_PLACEMENT = 'placement';
public const GROUP_PUBLICATION_TIMING = 'publicationTiming';
public const GROUP_VERSION_AND_UPDATES = 'versionAndUpdates';
public const GROUP_DISPLAY = 'display';
public const GROUP_ACCESS = 'access';
public $id = self::FORM_CATALOG_ENTRY;
public $method = 'PUT';
/** @var string */
public $successMessage;
/**
* Constructor
*
* @param string $action URL to submit the form to
* @param array $locales Supported locales
* @param Publication $publication The publication to change settings for
* @param Submission $submission The submission of this publication
* @param string $baseUrl Site's base URL. Used for image previews.
* @param string $temporaryFileApiUrl The url to upload the cover image
*/
public function __construct($action, $locales, $publication, $submission, $baseUrl, $temporaryFileApiUrl)
{
$this->action = $action;
$this->successMessage = __('publication.catalogEntry.success');
$this->locales = $locales;
$this
->addGroup(['id' => self::GROUP_PLACEMENT, 'label' => __('publication.placement')])
->addGroup(['id' => self::GROUP_PUBLICATION_TIMING, 'label' => __('publication.publicationTiming')])
->addGroup(['id' => self::GROUP_VERSION_AND_UPDATES, 'label' => __('publication.versionAndUpdates')])
->addGroup(['id' => self::GROUP_DISPLAY, 'label' => __('publication.display')])
->addGroup(['id' => self::GROUP_ACCESS, 'label' => __('publication.access')]);
// Series options
$seriesOptions = [['value' => '', 'label' => '']];
$result = Repo::section()
->getCollector()
->filterByContextIds([$submission->getData('contextId')])
->getMany();
foreach ($result as $series) {
$seriesOptions[] = [
'value' => (int) $series->getId(),
'label' => (($series->getIsInactive()) ? __('publication.inactiveSeries', ['series' => $series->getLocalizedTitle()]) : $series->getLocalizedTitle()),
];
}
$this
->addField(new FieldSelect('seriesId', [
'groupId' => self::GROUP_PLACEMENT,
'label' => __('series.series'),
'description' => __('publication.series.description'),
'value' => $publication->getData('seriesId'),
'options' => $seriesOptions,
]))
->addField(new FieldText('seriesPosition', [
'groupId' => self::GROUP_PLACEMENT,
'label' => __('submission.submit.seriesPosition'),
'description' => __('submission.submit.seriesPosition.description'),
'value' => $publication->getData('seriesPosition'),
]));
// Categories
$categoryOptions = [];
$categories = Repo::category()->getCollector()
->filterByContextIds([$submission->getData('contextId')])
->getMany();
$categoriesBreadcrumb = Repo::category()->getBreadcrumbs($categories);
foreach ($categoriesBreadcrumb as $categoryId => $breadcrumb) {
$categoryOptions[] = [
'value' => $categoryId,
'label' => $breadcrumb,
];
}
$hasAllBreadcrumbs = count($categories) === $categoriesBreadcrumb->count();
if (!empty($categoryOptions)) {
$vocabulary = Repo::category()->getCategoryVocabularyStructure($categories);
$this->addField(new FieldAutosuggestPreset('categoryIds', [
'groupId' => self::GROUP_PLACEMENT,
'label' => __('submission.submit.placement.categories'),
'value' => (array) $publication->getData('categoryIds'),
'description' => __('publication.categories.description') . ($hasAllBreadcrumbs ? '' : ' ' . __('submission.categories.circularReferenceWarning')),
'options' => $categoryOptions,
'vocabularies' => [
[
'addButtonLabel' => __('manager.selectCategories'),
'modalTitleLabel' => __('manager.selectCategories'),
'items' => $vocabulary
]
]
]));
}
$this
->addField(new FieldText('datePublished', [
'groupId' => self::GROUP_PUBLICATION_TIMING,
'label' => __('publication.datePublished'),
'description' => __('publication.datePublished.description'),
'value' => $publication->getData('datePublished'),
]))
->addField(new FieldSelect('updateType', [
'groupId' => self::GROUP_VERSION_AND_UPDATES,
'label' => __('publication.updateType.label'),
'description' => __('publication.updateType.description'),
'options' => array_map(
fn (UpdateType $case) => ['value' => $case->value, 'label' => $case->label()],
UpdateType::cases()
),
'value' => $publication->getData('updateType') ?? UpdateType::NEW_VERSION->value,
'size' => 'large',
]))
->addField(new FieldRichTextarea('summaryOfChanges', [
'groupId' => self::GROUP_VERSION_AND_UPDATES,
'label' => __('submission.form.summaryOfChanges'),
'description' => __('publication.summaryOfChanges.description'),
'isMultilingual' => true,
'value' => $publication->getData('summaryOfChanges'),
]))
->addField(new FieldUploadImage('coverImage', [
'groupId' => self::GROUP_DISPLAY,
'label' => __('monograph.coverImage'),
'description' => __('publication.coverImage.description'),
'value' => $publication->getData('coverImage'),
'isMultilingual' => true,
'baseUrl' => $baseUrl,
'options' => [
'url' => $temporaryFileApiUrl,
],
]))
->addField(new FieldText('urlPath', [
'groupId' => self::GROUP_ACCESS,
'label' => __('publication.urlPath'),
'description' => __('publication.urlPath.description'),
'value' => $publication->getData('urlPath'),
]));
}
}