-
Notifications
You must be signed in to change notification settings - Fork 452
/
Copy pathPKPSubmissionService.inc.php
898 lines (783 loc) · 30.1 KB
/
PKPSubmissionService.inc.php
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
<?php
/**
* @file classes/services/PKPSubmissionService.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 SubmissionService
* @ingroup services
*
* @brief Helper class that encapsulates submission business logic
*/
namespace PKP\Services;
use function PHP81_BC\strftime;
use \Core;
use \DBResultRange;
use \Application;
use \DAOResultFactory;
use \DAORegistry;
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Services;
use \PKP\Services\interfaces\EntityPropertyInterface;
use \PKP\Services\interfaces\EntityReadInterface;
use \PKP\Services\interfaces\EntityWriteInterface;
use \APP\Services\QueryBuilders\SubmissionQueryBuilder;
define('STAGE_STATUS_SUBMISSION_UNASSIGNED', 1);
abstract class PKPSubmissionService implements EntityPropertyInterface, EntityReadInterface, EntityWriteInterface {
/**
* @copydoc \PKP\Services\interfaces\EntityReadInterface::get()
*/
public function get($submissionId) {
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
return $submissionDao->getById($submissionId);
}
/**
* Get a submission by the urlPath of its publications
*
* @param string $urlPath
* @param int $contextId
* @return Submission|null
*/
public function getByUrlPath($urlPath, $contextId) {
$qb = new \PKP\Services\QueryBuilders\PKPPublicationQueryBuilder();
$firstResult = $qb->getQueryByUrlPath($urlPath, $contextId)->first();
if (!$firstResult) {
return null;
}
return $this->get($firstResult->submission_id);
}
/**
* @copydoc \PKP\Services\interfaces\EntityReadInterface::getCount()
*/
public function getCount($args = []) {
return $this->getQueryBuilder($args)->getCount();
}
/**
* @copydoc \PKP\Services\interfaces\EntityReadInterface::getIds()
*/
public function getIds($args = []) {
return $this->getQueryBuilder($args)->getIds();
}
/**
* Get a collection of Submission objects limited, filtered
* and sorted by $args
*
* @param array $args
* @option int contextId If not supplied, CONTEXT_ID_NONE will be used and
* no submissions will be returned. To retrieve submissions from all
* contexts, use CONTEXT_ID_ALL.
* @option string orderBy
* @option string orderDirection
* @option int assignedTo
* @option int|array status
* @option string searchPhrase
* @option int count
* @option int offset
* @return \Iterator
*/
public function getMany($args = []) {
$range = null;
if (isset($args['count'])) {
import('lib.pkp.classes.db.DBResultRange');
$range = new \DBResultRange($args['count'], null, isset($args['offset']) ? $args['offset'] : 0);
}
// Pagination is handled by the DAO, so don't pass count and offset
// arguments to the QueryBuilder.
if (isset($args['count'])) unset($args['count']);
if (isset($args['offset'])) unset($args['offset']);
$submissionListQO = $this->getQueryBuilder($args)->getQuery();
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
$result = $submissionDao->retrieveRange($submissionListQO->toSql(), $submissionListQO->getBindings(), $range);
$queryResults = new DAOResultFactory($result, $submissionDao, '_fromRow', [], $submissionListQO, [], $range);
return $queryResults->toIterator();
}
/**
* @copydoc \PKP\Services\interfaces\EntityReadInterface::getMax()
*/
public function getMax($args = []) {
// Don't accept args to limit the results
if (isset($args['count'])) unset($args['count']);
if (isset($args['offset'])) unset($args['offset']);
return $this->getQueryBuilder($args)->getCount();
}
/**
* @copydoc \PKP\Services\interfaces\EntityReadInterface::getQueryBuilder()
* @return SubmissionQueryBuilder
*/
public function getQueryBuilder($args = []) {
$defaultArgs = array(
'contextId' => CONTEXT_ID_NONE,
'orderBy' => 'dateSubmitted',
'orderDirection' => 'DESC',
'assignedTo' => [],
'status' => null,
'stageIds' => null,
'searchPhrase' => null,
'isIncomplete' => false,
'isOverdue' => false,
'daysInactive' => null,
);
$args = array_merge($defaultArgs, $args);
$submissionListQB = new SubmissionQueryBuilder();
$submissionListQB
->filterByContext($args['contextId'])
->orderBy($args['orderBy'], $args['orderDirection'])
->assignedTo($args['assignedTo'])
->filterByStatus($args['status'])
->filterByStageIds($args['stageIds'])
->filterByIncomplete($args['isIncomplete'])
->filterByOverdue($args['isOverdue'])
->filterByDaysInactive($args['daysInactive'])
->filterByCategories(isset($args['categoryIds'])?$args['categoryIds']:null)
->searchPhrase($args['searchPhrase']);
if (isset($args['count'])) {
$submissionListQB->limitTo($args['count']);
}
if (isset($args['offset'])) {
$submissionListQB->offsetBy($args['count']);
}
\HookRegistry::call('Submission::getMany::queryBuilder', array(&$submissionListQB, $args));
return $submissionListQB;
}
/**
* @copydoc \PKP\Services\interfaces\EntityPropertyInterface::getProperties()
*/
public function getProperties($submission, $props, $args = null) {
\AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
$values = array();
$request = $args['request'];
$dispatcher = $request->getDispatcher();
// Retrieve the submission's context for properties that require it
if (array_intersect(['_href', 'urlAuthorWorkflow', 'urlEditorialWorkflow'], $props)) {
$submissionContext = $request->getContext();
if (!$submissionContext || $submissionContext->getId() != $submission->getData('contextId')) {
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
}
}
foreach ($props as $prop) {
switch ($prop) {
case '_href':
$values[$prop] = $dispatcher->url(
$request,
ROUTE_API,
$submissionContext->getData('urlPath'),
'submissions/' . $submission->getId()
);
break;
case 'publications':
$values[$prop] = array_map(
function($publication) use ($args, $submission, $submissionContext) {
return Services::get('publication')->getSummaryProperties(
$publication,
$args + [
'submission' => $submission,
'context' => $submissionContext,
'currentUserReviewAssignment' => DAORegistry::getDAO('ReviewAssignmentDAO')
->getLastReviewRoundReviewAssignmentByReviewer(
$submission->getId(),
$args['request']->getUser()->getId()
),
]);
},
$submission->getData('publications')
);
break;
case 'reviewAssignments':
$values[$prop] = $this->getPropertyReviewAssignments($submission);
break;
case 'reviewRounds':
$values[$prop] = $this->getPropertyReviewRounds($submission);
break;
case 'stages':
$values[$prop] = $this->getPropertyStages($submission);
break;
case 'statusLabel':
$values[$prop] = __($submission->getStatusKey());
break;
case 'urlAuthorWorkflow':
$values[$prop] = $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getData('urlPath'),
'authorDashboard',
'submission',
$submission->getId()
);
break;
case 'urlEditorialWorkflow':
$values[$prop] = $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getData('urlPath'),
'workflow',
'access',
$submission->getId()
);
break;
case 'urlWorkflow':
$values[$prop] = $this->getWorkflowUrlByUserRoles($submission);
break;
default:
$values[$prop] = $submission->getData($prop);
break;
}
}
$values = Services::get('schema')->addMissingMultilingualValues(SCHEMA_SUBMISSION, $values, $request->getContext()->getSupportedSubmissionLocales());
\HookRegistry::call('Submission::getProperties::values', array(&$values, $submission, $props, $args));
ksort($values);
return $values;
}
/**
* @copydoc \PKP\Services\interfaces\EntityPropertyInterface::getSummaryProperties()
*/
public function getSummaryProperties($submission, $args = null) {
$props = Services::get('schema')->getSummaryProps(SCHEMA_SUBMISSION);
return $this->getProperties($submission, $props, $args);
}
/**
* @copydoc \PKP\Services\interfaces\EntityPropertyInterface::getFullProperties()
*/
public function getFullProperties($submission, $args = null) {
$props = Services::get('schema')->getFullProps(SCHEMA_SUBMISSION);
return $this->getProperties($submission, $props, $args);
}
/**
* Returns properties for custom API endpoints used in the backend
* @param Submission $submission
* @param array extra arguments
* $args['request'] PKPRequest Required
* $args['slimRequest'] SlimRequest
*/
public function getBackendListProperties($submission, $args = null) {
\PluginRegistry::loadCategory('pubIds', true);
$props = array (
'_href', 'contextId', 'currentPublicationId','dateLastActivity','dateSubmitted','id',
'lastModified','publications','reviewAssignments','reviewRounds','stageId','stages','status',
'statusLabel','submissionProgress','urlAuthorWorkflow','urlEditorialWorkflow','urlWorkflow','urlPublished',
);
\HookRegistry::call('Submission::getBackendListProperties::properties', array(&$props, $submission, $args));
return $this->getProperties($submission, $props, $args);
}
/**
* Get details about the review assignments for a submission
*
* @todo account for extra review stage in omp
* @param $submission Submission
*/
public function getPropertyReviewAssignments($submission) {
$reviewAssignments = $this->getReviewAssignments($submission);
$reviews = array();
foreach($reviewAssignments as $reviewAssignment) {
if ($reviewAssignment->getDeclined() || $reviewAssignment->getCancelled()) {
continue;
}
$request = \Application::get()->getRequest();
$currentUser = $request->getUser();
$context = $request->getContext();
$dateFormatShort = $context->getLocalizedDateFormatShort();
$due = is_null($reviewAssignment->getDateDue()) ? null : strftime($dateFormatShort, strtotime($reviewAssignment->getDateDue()));
$responseDue = is_null($reviewAssignment->getDateResponseDue()) ? null : strftime($dateFormatShort, strtotime($reviewAssignment->getDateResponseDue()));
$reviews[] = array(
'id' => (int) $reviewAssignment->getId(),
'isCurrentUserAssigned' => $currentUser->getId() == (int) $reviewAssignment->getReviewerId(),
'statusId' => (int) $reviewAssignment->getStatus(),
'status' => __($reviewAssignment->getStatusKey()),
'due' => $due,
'responseDue' => $responseDue,
'round' => (int) $reviewAssignment->getRound(),
'roundId' => (int) $reviewAssignment->getReviewRoundId(),
);
}
return $reviews;
}
/**
* Get details about the review rounds for a submission
*
* @todo account for extra review stage in omp
* @param $submission Submission
* @return array
*/
public function getPropertyReviewRounds($submission) {
$reviewRounds = $this->getReviewRounds($submission);
$rounds = array();
foreach ($reviewRounds as $reviewRound) {
$rounds[] = array(
'id' => $reviewRound->getId(),
'round' => $reviewRound->getRound(),
'stageId' => $reviewRound->getStageId(),
'statusId' => $reviewRound->determineStatus(),
'status' => __($reviewRound->getStatusKey()),
);
}
return $rounds;
}
/**
* Get details about a submission's stage(s)
*
* @param $submission Submission
* @param $stageIds array|int|null One or more stages to retrieve.
* Default: null. Will return data on all app stages.
* @return array {
* `id` int stage id
* `label` string translated stage name
* `queries` array [{
* `id` int query id
* `assocType` int
* `assocId` int
* `stageId` int
* `seq` int
* `closed` bool
* }]
* `statusId` int stage status. note: on review stage, this refers to the
* status of the latest round.
* `status` string translated stage status name
* `files` array {
* `count` int number of files attached to stage. note: this only counts
* revision files.
* }
*/
public function getPropertyStages($submission, $stageIds = null) {
if (is_null($stageIds)) {
$stageIds = Application::get()->getApplicationStages();
} elseif (is_int($stageIds)) {
$stageIds = array($stageIds);
}
$currentUser = \Application::get()->getRequest()->getUser();
$context = \Application::get()->getRequest()->getContext();
$contextId = $context ? $context->getId() : CONTEXT_ID_NONE;
$stages = array();
foreach ($stageIds as $stageId) {
import('lib.pkp.classes.workflow.WorkflowStageDAO');
$workflowStageDao = DAORegistry::getDAO('WorkflowStageDAO'); /* @var $workflowStageDao WorkflowStageDAO */
$stage = array(
'id' => (int) $stageId,
'label' => __($workflowStageDao->getTranslationKeyFromId($stageId)),
'isActiveStage' => $submission->getStageId() == $stageId,
);
// Discussions in this stage
$stage['queries'] = array();
$request = Application::get()->getRequest();
import('lib.pkp.classes.query.QueryDAO');
$queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
$queries = $queryDao->getByAssoc(
ASSOC_TYPE_SUBMISSION,
$submission->getId(),
$stageId,
$request->getUser()->getId() // Current user restriction should prevent unauthorized access
);
while ($query = $queries->next()) {
$stage['queries'][] = array(
'id' => (int) $query->getId(),
'assocType' => (int) $query->getAssocType(),
'assocId' => (int) $query->getAssocId(),
'stageId' => $stageId,
'seq' => (int) $query->getSequence(),
'closed' => (bool) $query->getIsClosed(),
);
}
$currentUserAssignedRoles = array();
if ($currentUser) {
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$stageAssignmentsResult = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId($submission->getId(), $currentUser->getId(), $stageId);
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
while ($stageAssignment = $stageAssignmentsResult->next()) {
$userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId(), $contextId);
$currentUserAssignedRoles[] = (int) $userGroup->getRoleId();
}
}
$stage['currentUserAssignedRoles'] = array_values(array_unique($currentUserAssignedRoles));
// Stage-specific statuses
switch ($stageId) {
case WORKFLOW_STAGE_ID_SUBMISSION:
import('lib.pkp.classes.stageAssignment.StageAssignmentDAO');
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$assignedEditors = $stageAssignmentDao->editorAssignedToStage($submission->getId(), $stageId);
if (!$assignedEditors) {
$stage['statusId'] = STAGE_STATUS_SUBMISSION_UNASSIGNED;
$stage['status'] = __('submissions.queuedUnassigned');
}
// Submission stage never has revisions
$stage['files'] = array(
'count' => 0,
);
break;
case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
import('lib.pkp.classes.submission.reviewRound.ReviewRoundDAO');
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
$reviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);
if ($reviewRound) {
$stage['statusId'] = $reviewRound->determineStatus();
$stage['status'] = __($reviewRound->getStatusKey());
// Revision files in this round.
$stage['files'] = [
'count' => Services::get('submissionFile')->getCount([
'submissionIds' => [$submission->getId()],
'fileStages' => [SUBMISSION_FILE_REVIEW_REVISION],
'reviewRounds' => [$reviewRound->getId()],
]),
];
// See if the curent user can only recommend:
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$user = $request->getUser();
$editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $stageId);
// if the user is assigned several times in the editorial role, and
// one of the assignments have recommendOnly option set, consider it here
$stage['currentUserCanRecommendOnly'] = false;
foreach ($editorsStageAssignments as $editorsStageAssignment) {
if ($editorsStageAssignment->getUserId() == $user->getId() && $editorsStageAssignment->getRecommendOnly()) {
$stage['currentUserCanRecommendOnly'] = true;
break;
}
}
} else {
// workaround for pkp/pkp-lib#4231, pending formal data model
$stage['files'] = [
'count' => 0
];
}
break;
// Get revision files for editing and production stages.
// Review rounds are handled separately in the review stage below.
case WORKFLOW_STAGE_ID_EDITING:
case WORKFLOW_STAGE_ID_PRODUCTION:
import('lib.pkp.classes.submission.SubmissionFile'); // Import constants
$stage['files'] = [
'count' => Services::get('submissionFile')->getCount([
'submissionIds' => [$submission->getId()],
'fileStages' => [WORKFLOW_STAGE_ID_EDITING ? SUBMISSION_FILE_COPYEDIT : SUBMISSION_FILE_PROOF],
]),
];
break;
}
$stages[] = $stage;
}
return $stages;
}
/**
* Get the correct access URL for a submission's workflow based on a user's
* role.
*
* The returned URL will point to the correct workflow page based on whether
* the user should be treated as an author, reviewer or editor/assistant for
* this submission.
*
* @param $submission Submission
* @param $userId an optional user id
* @return string|false URL; false if the user does not exist or an
* appropriate access URL could not be determined
*/
public function getWorkflowUrlByUserRoles($submission, $userId = null) {
$request = Application::get()->getRequest();
if (is_null($userId)) {
$user = $request->getUser();
} else {
$userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
$user = $userDao->getById($userId);
}
if (is_null($user)) {
return false;
}
$submissionContext = $request->getContext();
if (!$submissionContext || $submissionContext->getId() != $submission->getData('contextId')) {
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
}
$dispatcher = $request->getDispatcher();
// Check if the user is an author of this submission
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$authorUserGroupIds = $userGroupDao->getUserGroupIdsByRoleId(ROLE_ID_AUTHOR);
$stageAssignmentsFactory = $stageAssignmentDao->getBySubmissionAndStageId($submission->getId(), null, null, $user->getId());
$authorDashboard = false;
while ($stageAssignment = $stageAssignmentsFactory->next()) {
if (in_array($stageAssignment->getUserGroupId(), $authorUserGroupIds)) {
$authorDashboard = true;
}
}
// Send authors, journal managers and site admins to the submission
// wizard for incomplete submissions
if ($submission->getSubmissionProgress() > 0 &&
($authorDashboard ||
$user->hasRole(array(ROLE_ID_MANAGER), $submissionContext->getId()) ||
$user->hasRole(array(ROLE_ID_SITE_ADMIN), CONTEXT_SITE))) {
return $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getPath(),
'submission',
'wizard',
$submission->getSubmissionProgress(),
array('submissionId' => $submission->getId())
);
}
// Send authors to author dashboard
if ($authorDashboard) {
return $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getPath(),
'authorDashboard',
'submission',
$submission->getId()
);
}
// Send reviewers to review wizard
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
$reviewAssignment = $reviewAssignmentDao->getLastReviewRoundReviewAssignmentByReviewer($submission->getId(), $user->getId());
if ($reviewAssignment && !$reviewAssignment->getCancelled() && !$reviewAssignment->getDeclined()) {
return $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getPath(),
'reviewer',
'submission',
$submission->getId()
);
}
// Give any other users the editorial workflow URL. If they can't access
// it, they'll be blocked there.
return $dispatcher->url(
$request,
ROUTE_PAGE,
$submissionContext->getPath(),
'workflow',
'access',
$submission->getId()
);
}
/**
* Check if a user can delete a submission
*
* @param $submission Submission|int Submission object or submission ID
* @return bool
*/
public function canCurrentUserDelete($submission) {
if (!is_a($submission, 'Submission')) {
$submission = $this->get((int) $submission);
if (!$submission) {
return false;
}
}
$request = Application::get()->getRequest();
$contextId = $submission->getContextId();
$currentUser = $request->getUser();
if (!$currentUser) {
return false;
}
$canDelete = false;
// Only allow admins and journal managers to delete submissions, except
// for authors who can delete their own incomplete submissions
if ($currentUser->hasRole(array(ROLE_ID_MANAGER), $contextId) || $currentUser->hasRole(array(ROLE_ID_SITE_ADMIN), CONTEXT_SITE)) {
$canDelete = true;
} else {
if ($submission->getSubmissionProgress() != 0 ) {
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$assignments = $stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), ROLE_ID_AUTHOR, WORKFLOW_STAGE_ID_SUBMISSION, $currentUser->getId());
$assignment = $assignments->next();
if ($assignment) {
$canDelete = true;
}
}
}
return $canDelete;
}
/**
* Get review rounds for a submission
*
* @param $submission Submission
* @return \Iterator
*/
public function getReviewRounds($submission) {
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
return $reviewRoundDao->getBySubmissionId($submission->getId())->toIterator();
}
/**
* Get review assignments for a submission
*
* @param $submission Submission
* @return array
*/
public function getReviewAssignments($submission) {
import('lib.pkp.classes.submission.reviewAssignment.ReviewAssignmentDAO');
$reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
return $reviewAssignmentDao->getBySubmissionId($submission->getId());
}
/**
* @copydoc \PKP\Services\EntityProperties\EntityWriteInterface::validate()
*/
public function validate($action, $props, $allowedLocales, $primaryLocale) {
$schemaService = Services::get('schema');
import('lib.pkp.classes.validation.ValidatorFactory');
$validator = \ValidatorFactory::make(
$props,
$schemaService->getValidationRules(SCHEMA_SUBMISSION, $allowedLocales)
);
// Check required fields
\ValidatorFactory::required(
$validator,
$action,
$schemaService->getRequiredProps(SCHEMA_SUBMISSION),
$schemaService->getMultilingualProps(SCHEMA_SUBMISSION),
$primaryLocale,
$allowedLocales
);
// Check for input from disallowed locales
\ValidatorFactory::allowedLocales($validator, $schemaService->getMultilingualProps(SCHEMA_SUBMISSION), $allowedLocales);
// The contextId must match an existing context
$validator->after(function($validator) use ($props) {
if (isset($props['contextId']) && !$validator->errors()->get('contextId')) {
$submissionContext = Services::get('context')->get($props['contextId']);
if (!$submissionContext) {
$validator->errors()->add('contextId', __('submission.submit.noContext'));
}
}
});
if ($validator->fails()) {
$errors = $schemaService->formatValidationErrors($validator->errors(), $schemaService->get(SCHEMA_SUBMISSION), $allowedLocales);
}
\HookRegistry::call('Submission::validate', [&$errors, $action, $props, $allowedLocales, $primaryLocale]);
return $errors;
}
/**
* @copydoc \PKP\Services\EntityProperties\EntityWriteInterface::add()
*/
public function add($submission, $request) {
$submission->stampLastActivity();
$submission->stampModified();
if (!$submission->getData('dateSubmitted') && !$submission->getData('submissionProgress')) {
$submission->setData('dateSubmitted', Core::getCurrentDate());
}
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
$submissionId = $submissionDao->insertObject($submission);
$submission = $this->get($submissionId);
\HookRegistry::call('Submission::add', [&$submission, $request]);
return $submission;
}
/**
* @copydoc \PKP\Services\EntityProperties\EntityWriteInterface::edit()
*/
public function edit($submission, $params, $request) {
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
$newSubmission = $submissionDao->newDataObject();
$newSubmission->_data = array_merge($submission->_data, $params);
$submission->stampLastActivity();
$submission->stampModified();
\HookRegistry::call('Submission::edit', [&$newSubmission, $submission, $params, $request]);
$submissionDao->updateObject($newSubmission);
$newSubmission = $this->get($newSubmission->getId());
return $newSubmission;
}
/**
* @copydoc \PKP\Services\EntityProperties\EntityWriteInterface::delete()
*/
public function delete($submission) {
\HookRegistry::call('Submission::delete::before', [&$submission]);
$submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
$submissionDao->deleteObject($submission);
\HookRegistry::call('Submission::delete', [&$submission]);
}
/**
* Check if a user can edit a publications metadata
*
* @param Submission $submission
* @param int $userId
* @return boolean
*/
public function canEditPublication($submission, $userId) {
$contextId = Application::get()->getRequest()->getContext()->getId();
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
$stageAssignments = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId($submission->getId(), $userId, null)->toArray();
$userIsAuthor = !empty($stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), ROLE_ID_AUTHOR, null, $userId)->toArray());
// If the user is an author of a declined submission and user can't edit anyway ie. is not manager
if ($submission->getStatus() == STATUS_DECLINED && $userIsAuthor && !$this->_canUserAccessUnassignedSubmissions($contextId, $userId)) {
return false;
}
// Check for permission from stage assignments
foreach ($stageAssignments as $stageAssignment) {
if ($stageAssignment->getCanChangeMetadata()) {
return true;
}
}
// If user has no stage assigments, check if user can edit anyway ie. is manager
if (count($stageAssignments) == 0 && $this->_canUserAccessUnassignedSubmissions($contextId, $userId)) {
return true;
}
// Else deny access
return false;
}
/**
* Check whether the user is by default allowed to edit publications metadata
* @param $contextId int
* @param $userId int
* @return boolean true if the user is allowed to edit metadata by default
*/
private static function _canUserAccessUnassignedSubmissions($contextId, $userId) {
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */
$roles = $roleDao->getByUserId($userId, $contextId);
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$allowedRoles = $userGroupDao->getNotChangeMetadataEditPermissionRoles();
foreach ($roles as $role) {
if (in_array($role->getRoleId(), $allowedRoles))
return true;
}
return false;
}
/**
* Update a submission's status and current publication id if necessary
*
* Checks the status of the submission's publications and sets
* the appropriate status and current publication id.
*
* @param Submission $submission
* @return Submission
*/
public function updateStatus($submission) {
$status = $newStatus = $submission->getData('status');
$currentPublicationId = $submission->getData('currentPublicationId');
$publications = $submission->getData('publications');
// There should always be at least one publication for a submission. If
// not, an error has occurred in the code and will cause problems.
if (empty($publications)) {
throw new \Exception('Tried to update the status of submission ' . $submission->getId() . ' and no publications were found.');
}
// Get the new current publication after status changes or deletions
// Use the latest published publication or, failing that, the latest publication
$newCurrentPublicationId = array_reduce($publications, function($a, $b) {
return $b->getData('status') === STATUS_PUBLISHED && $b->getId() > $a ? $b->getId() : $a;
}, 0);
if (!$newCurrentPublicationId) {
$newCurrentPublicationId = array_reduce($publications, function($a, $b) {
return $a > $b->getId() ? $a : $b->getId();
}, 0);
}
// Declined submissions should remain declined even if their
// publications change
if ($status !== STATUS_DECLINED) {
$newStatus = STATUS_QUEUED;
foreach ($publications as $publication) {
if ($publication->getData('status') === STATUS_PUBLISHED) {
$newStatus = STATUS_PUBLISHED;
break;
}
if ($publication->getData('status') === STATUS_SCHEDULED) {
$newStatus = STATUS_SCHEDULED;
continue;
}
}
}
\HookRegistry::call('Submission::updateStatus', [&$status, $submission]);
$updateParams = [];
if ($status !== $newStatus) {
$updateParams['status'] = $newStatus;
}
if ($currentPublicationId !== $newCurrentPublicationId) {
$updateParams['currentPublicationId'] = $newCurrentPublicationId;
}
if (!empty($updateParams)) {
$submission = $this->edit($submission, $updateParams, Application::get()->getRequest());
}
return $submission;
}
}