19 use \DAOResultFactory;
22 use \PKP\Services\interfaces\EntityPropertyInterface;
23 use \PKP\Services\interfaces\EntityReadInterface;
24 use \PKP\Services\interfaces\EntityWriteInterface;
25 use \APP\Services\QueryBuilders\GalleyQueryBuilder;
27 class GalleyService implements EntityReadInterface, EntityWriteInterface, EntityPropertyInterface {
32 public function get($galleyId) {
34 return $articleGalleyDao->getById($galleyId);
63 $result = $galleyDao->retrieveRange($galleyQO->toSql(), $galleyQO->getBindings());
66 return $queryResults->toIterator();
84 if (!empty($args[
'publicationIds'])) {
85 $galleyQB->filterByPublicationIds($args[
'publicationIds']);
97 $request = $args[
'request'];
98 $context = $request->getContext();
99 $dispatcher = $request->getDispatcher();
101 if (is_a($galley,
'ArticleGalley')) {
102 $publication = !empty($args[
'publication'])
103 ? $args[
'publication']
104 : $args[
'publication'] =
Services::get(
'publication')->get($galley->getData(
'publicationId'));
106 $submission = !empty($args[
'submission'])
107 ? $args[
'submission']
108 : $args[
'submission'] =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
114 foreach ($props as $prop) {
117 if (is_a($galley,
'IssueGalley')) {
118 $values[$prop] = $dispatcher->url(
125 $galley->getIssueId(),
130 $values[$prop] = $dispatcher->url(
137 $submission->getBestId(),
139 $publication->getId(),
140 $galley->getBestGalleyId(),
146 $values[$prop] =
null;
147 $file = $galley->getFile();
151 $values[$prop] = array(
152 'fileName' => $file->getOriginalFileName(),
154 if (is_a($file,
'SubmissionFile')) {
155 $values[$prop][
'id'] = $file->getFileId();
156 $values[$prop][
'revision'] = $file->getRevision();
157 $values[$prop][
'fileStage'] = $file->getFileStage();
158 $values[$prop][
'genreId'] = $file->getGenreId();
159 $values[$prop][
'fileName'] = $file->getClientFileName();
160 } elseif (is_a($file,
'IssueFile')) {
161 $values[$prop][
'id'] = $file->getId();
163 if (is_a($file,
'SupplementaryFile')) {
164 $values[$prop][
'metadata'] = array(
165 'description' => $file->getDescription(
null),
166 'creator' => $file->getCreator(
null),
167 'publisher' => $file->getPublisher(
null),
168 'source' => $file->getSource(
null),
169 'subject' => $file->getSubject(
null),
170 'sponsor' => $file->getSponsor(
null),
171 'dateCreated' => $file->getDateCreated(),
172 'language' => $file->getLanguage(),
174 } elseif (is_a($file,
'SubmissionArtworkFile')) {
175 $values[$prop][
'metadata'] = array(
176 'caption' => $file->getCaption(),
177 'credit' => $file->getCredit(),
178 'copyrightOwner' => $file->getCopyrightOwner(),
179 'terms' => $file->getPermissionTerms(),
180 'width' => $file->getWidth(),
181 'height' => $file->getHeight(),
182 'physicalWidth' => $file->getPhysicalWidth(300),
183 'physicalHeight' => $file->getPhysicalHeight(300),
188 if (is_a($file,
'SubmissionFile')) {
189 $values[
'dependentFiles'] = [];
191 $dependentFiles = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $file->getFileId(), $submission->getId(), SUBMISSION_FILE_DEPENDENT);
192 if ($dependentFiles) {
193 foreach ($dependentFiles as $dependentFile) {
194 $dependentFileProps = array(
195 'id' => $dependentFile->getFileId(),
196 'fileName' => $dependentFile->getOriginalFileName(),
198 if (is_a($dependentFile,
'SubmissionFile')) {
199 $dependentFileProps[
'revision'] = $dependentFile->getRevision();
200 $dependentFileProps[
'fileStage'] = $dependentFile->getFileStage();
201 $dependentFileProps[
'genreId'] = $dependentFile->getGenreId();
202 $dependentFileProps[
'fileName'] = $dependentFile->getClientFileName();
204 if (is_a($dependentFile,
'SupplementaryFile')) {
205 $dependentFileProps[
'description'] = $dependentFile->getDescription(
null);
206 $dependentFileProps[
'creator'] = $dependentFile->getCreator(
null);
207 $dependentFileProps[
'publisher'] = $dependentFile->getPublisher(
null);
208 $dependentFileProps[
'source'] = $dependentFile->getSource(
null);
209 $dependentFileProps[
'subject'] = $dependentFile->getSubject(
null);
210 $dependentFileProps[
'sponsor'] = $dependentFile->getSponsor(
null);
211 $dependentFileProps[
'dateCreated'] = $dependentFile->getDateCreated();
212 $dependentFileProps[
'language'] = $dependentFile->getLanguage();
213 } elseif (is_a($dependentFile,
'SubmissionArtworkFile')) {
214 $dependentFileProps[
'caption'] = $dependentFile->getCaption();
215 $dependentFileProps[
'credit'] = $dependentFile->getCredit();
216 $dependentFileProps[
'copyrightOwner'] = $dependentFile->getCopyrightOwner();
217 $dependentFileProps[
'terms'] = $dependentFile->getPermissionTerms();
218 $dependentFileProps[
'width'] = $dependentFile->getWidth();
219 $dependentFileProps[
'height'] = $dependentFile->getHeight();
220 $dependentFileProps[
'physicalWidth'] = $dependentFile->getPhysicalWidth(300);
221 $dependentFileProps[
'physicalHeight'] = $dependentFile->getPhysicalHeight(300);
223 $values[
'dependentFiles'][] = $dependentFileProps;
229 $values[$prop] = $galley->getData($prop);
234 $values =
Services::get(
'schema')->addMissingMultilingualValues(SCHEMA_GALLEY, $values, $context->getSupportedSubmissionLocales());
236 \HookRegistry::call(
'Galley::getProperties::values', array(&$values, $galley, $props, $args));
247 $props =
Services::get(
'schema')->getSummaryProps(SCHEMA_GALLEY);
256 $props =
Services::get(
'schema')->getFullProps(SCHEMA_GALLEY);
264 public function validate($action, $props, $allowedLocales, $primaryLocale) {
267 import(
'lib.pkp.classes.validation.ValidatorFactory');
270 $schemaService->getValidationRules(SCHEMA_GALLEY, $allowedLocales),
272 'locale.regex' => __(
'validator.localeKey'),
273 'urlPath.regex' => __(
'validator.alpha_dash'),
281 $schemaService->getRequiredProps(SCHEMA_GALLEY),
282 $schemaService->getMultilingualProps(SCHEMA_GALLEY),
291 $validator->after(
function($validator) use ($props) {
292 if (isset($props[
'publicationId']) && !$validator->errors()->get(
'publicationId')) {
293 $publication = Services::get(
'publication')->get($props[
'publicationId']);
295 $validator->errors()->add(
'publicationId', __(
'galley.publicationNotFound'));
296 }
else if (
Services::get(
'publication')->isPublished($publication)) {
297 $validator->errors()->
add(
'publicationId', __(
'galley.editPublishedDisabled'));
302 if ($validator->fails()) {
303 $errors = $schemaService->formatValidationErrors($validator->errors(), $schemaService->get(SCHEMA_GALLEY), $allowedLocales);
306 \HookRegistry::call(
'Galley::validate', array(&$errors, $action, $props, $allowedLocales, $primaryLocale));
314 public function add($galley, $request) {
316 $galleyId = $articleGalleyDao->insertObject($galley);
317 $galley = $this->
get($galleyId);
327 public function edit($galley, $params, $request) {
330 $newGalley = $galleyDao->newDataObject();
331 $newGalley->_data = array_merge($galley->_data, $params);
335 $galleyDao->updateObject($newGalley);
336 $newGalley = $this->
get($newGalley->getId());
344 public function delete($galley) {
348 $articleGalleyDao->deleteObject($galley);
351 $publication =
Services::get(
'publication')->get($galley->getData(
'publicationId'));
354 import(
'lib.pkp.classes.submission.SubmissionFile');
355 $galleyFiles = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_GALLEY, $galley->getId(), $publication->getData(
'submissionId'), SUBMISSION_FILE_PROOF);
356 foreach ($galleyFiles as $file) {
358 $submissionFileDao->deleteAllRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $file->getFileId(), SUBMISSION_FILE_DEPENDENT);
361 $submissionFileDao->deleteAllRevisionsByAssocId(ASSOC_TYPE_GALLEY, $galley->getId(), SUBMISSION_FILE_PROOF);