Skip to content

Commit e8bcd03

Browse files
committed
trigger editor placement and emailing like regular submission
1 parent c8f36f9 commit e8bcd03

File tree

2 files changed

+227
-8
lines changed

2 files changed

+227
-8
lines changed

FidusWriterGatewayPlugin.inc.php

+226-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
/**
44
* Copyright 2016-17, Afshin Sadeghi ([email protected]) of the OSCOSS
55
* Project.
6-
* License: MIT. See LICENSE.md for details.
6+
* License: GNU GPL v2. See LICENSE.md for details.
77
*/
88

9+
class MockObject extends stdClass {
10+
// Used to create request mock object, to emulate real request. See below.
11+
public function __call($closure, $args) {
12+
return call_user_func_array($this->{$closure}->bindTo($this),$args);
13+
}
14+
15+
public function __toString() {
16+
return call_user_func($this->{"__toString"}->bindTo($this));
17+
}
18+
}
19+
920
import('lib.pkp.classes.plugins.GatewayPlugin');
1021

1122
class FidusWriterGatewayPlugin extends GatewayPlugin {
@@ -351,7 +362,9 @@ function authorSubmit() {
351362
// Together with the 'fidusId', OJS will be able to create
352363
// a link to send the user to FW to edit the file.
353364
$fidusUrl = $this->getPOSTPayloadVariable("fidus_url");
354-
$submissionId = $this->createNewSubmission($title, $journalId, $fidusUrl, $fidusId);
365+
$submission = $this->createNewSubmission($title, $journalId, $fidusUrl, $fidusId);
366+
367+
$submissionId = $submission->getId();
355368

356369
// We also create a user for the author
357370
$emailAddress = $this->getPOSTPayloadVariable("email");
@@ -368,13 +381,217 @@ function authorSubmit() {
368381
$biography = $this->getPOSTPayloadVariable("biography");
369382
$authorId = $this->saveAuthor($submissionId, $journalId, $emailAddress, $firstName, $lastName, $affiliation, $country, $authorUrl, $biography);
370383

371-
// Assign the user author to the stage
372-
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
373-
$authorUserGroupId = $this->getAuthorUserGroupId($journalId);
384+
// Create a fake request object as the real request does not contain the required data.
385+
// $request is required in the following code which comes from different parts of OJS.
386+
387+
$request = new MockObject();
388+
$request->journalId = $journalId;
389+
$request->user = $user;
390+
$application = PKPApplication::getApplication();
391+
$request->origRequest = $application->getRequest();
392+
393+
$request->getContext = function() {
394+
$contextDao = Application::getContextDAO();
395+
return $contextDao->getById($this->journalId);
396+
};
397+
398+
$request->getUser = function() {
399+
return $this->user;
400+
};
401+
402+
$request->getRouter = function() {
403+
return $this->origRequest->getRouter();
404+
};
405+
406+
$request->isPathInfoEnabled = function() {
407+
return $this->origRequest->isPathInfoEnabled();
408+
};
409+
410+
$request->isRestfulUrlsEnabled = function() {
411+
return $this->origRequest->isRestfulUrlsEnabled();
412+
};
413+
414+
$request->getBaseUrl = function() {
415+
return $this->origRequest->getBaseUrl();
416+
};
417+
418+
$request->getRemoteAddr = function() {
419+
return $this->origRequest->getRemoteAddr();
420+
};
421+
422+
423+
// The following has been adapted from PKPSubmissionSubmitStep4Form
424+
425+
// Manager and assistant roles -- for each assigned to this
426+
// stage in setup, iff there is only one user for the group,
427+
// automatically assign the user to the stage.
428+
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
429+
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');
430+
$submissionStageGroups = $userGroupDao->getUserGroupsByStage($journalId, WORKFLOW_STAGE_ID_SUBMISSION);
431+
$managerFound = false;
432+
while ($userGroup = $submissionStageGroups->next()) {
433+
// Only handle manager and assistant roles
434+
if (!in_array($userGroup->getRoleId(), array(ROLE_ID_MANAGER, ROLE_ID_ASSISTANT))) continue;
435+
436+
$users = $userGroupDao->getUsersById($userGroup->getId(), $journalId);
437+
if($users->getCount() == 1) {
438+
$user = $users->next();
439+
$stageAssignmentDao->build($submissionId, $userGroup->getId(), $user->getId(), $userGroup->getRecommendOnly());
440+
if ($userGroup->getRoleId() == ROLE_ID_MANAGER) $managerFound = true;
441+
}
442+
}
443+
444+
// Assign the user author to the stage
445+
$authorUserGroupId = $this->getAuthorUserGroupId($journalId);
374446
if ($authorUserGroupId) {
375447
$stageAssignmentDao->build($submissionId, $authorUserGroupId, $userId);
376448
}
377449

450+
451+
452+
// Assign sub editors for that section
453+
$submissionSubEditorFound = false;
454+
$subEditorsDao = DAORegistry::getDAO('SubEditorsDAO');
455+
$subEditors = $subEditorsDao->getBySectionId($submission->getSectionId(), $journalId);
456+
foreach ($subEditors as $subEditor) {
457+
$userGroups = $userGroupDao->getByUserId($subEditor->getId(), $journalId);
458+
while ($userGroup = $userGroups->next()) {
459+
if ($userGroup->getRoleId() != ROLE_ID_SUB_EDITOR) continue;
460+
$stageAssignmentDao->build($submissionId, $userGroup->getId(), $subEditor->getId(), $userGroup->getRecommendOnly());
461+
// If we assign a stage assignment in the Submission stage to a sub editor, make note.
462+
if ($userGroupDao->userGroupAssignedToStage($userGroup->getId(), WORKFLOW_STAGE_ID_SUBMISSION)) {
463+
$submissionSubEditorFound = true;
464+
}
465+
}
466+
}
467+
468+
// Update assignment notifications
469+
import('classes.workflow.EditorDecisionActionsManager');
470+
$notificationManager = new NotificationManager();
471+
$notificationManager->updateNotification(
472+
$request,
473+
EditorDecisionActionsManager::getStageNotifications(),
474+
null,
475+
ASSOC_TYPE_SUBMISSION,
476+
$journalId
477+
);
478+
479+
// Send a notification to associated users if an editor needs assigning
480+
if (!$managerFound && !$submissionSubEditorFound) {
481+
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */
482+
483+
// Get the managers.
484+
$managers = $roleDao->getUsersByRoleId(ROLE_ID_MANAGER, $journalId);
485+
486+
$managersArray = $managers->toAssociativeArray();
487+
488+
$allUserIds = array_keys($managersArray);
489+
foreach ($allUserIds as $userId) {
490+
$notificationManager->createNotification(
491+
$request, $userId, NOTIFICATION_TYPE_SUBMISSION_SUBMITTED,
492+
$journalId, ASSOC_TYPE_SUBMISSION, $submissionId
493+
);
494+
495+
// Add TASK notification indicating that a submission is unassigned
496+
$notificationManager->createNotification(
497+
$request,
498+
$userId,
499+
NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_REQUIRED,
500+
$journalId,
501+
ASSOC_TYPE_SUBMISSION,
502+
$submissionId,
503+
NOTIFICATION_LEVEL_TASK
504+
);
505+
}
506+
}
507+
508+
$notificationManager->updateNotification(
509+
$request,
510+
array(NOTIFICATION_TYPE_APPROVE_SUBMISSION),
511+
null,
512+
ASSOC_TYPE_SUBMISSION,
513+
$submissionId
514+
);
515+
516+
// End adaption from PKPSubmissionSubmitStep4Form
517+
518+
// The following has been adapted from SubmissionSubmitStep4Form
519+
520+
// Send author notification email
521+
import('classes.mail.ArticleMailTemplate');
522+
$context = $request->getContext();
523+
$router = $request->getRouter();
524+
$mail = new ArticleMailTemplate($submission, 'SUBMISSION_ACK', null, null, false);
525+
$mail->setContext($context);
526+
$authorMail = new ArticleMailTemplate($submission, 'SUBMISSION_ACK_NOT_USER', null, null, false);
527+
$authorMail->setContext($context);
528+
529+
if ($mail->isEnabled()) {
530+
// submission ack emails should be from the contact.
531+
$mail->setFrom($context->getSetting('contactEmail'), $context->getSetting('contactName'));
532+
$authorMail->setFrom($context->getSetting('contactEmail'), $context->getSetting('contactName'));
533+
534+
$user = $request->getUser();
535+
$primaryAuthor = $submission->getPrimaryAuthor();
536+
if (!isset($primaryAuthor)) {
537+
$authors = $submission->getAuthors();
538+
$primaryAuthor = $authors[0];
539+
}
540+
$mail->addRecipient($user->getEmail(), $user->getFullName());
541+
// Add primary contact and e-mail address as specified in the journal submission settings
542+
if ($context->getSetting('copySubmissionAckPrimaryContact')) {
543+
$mail->addBcc(
544+
$context->getSetting('contactEmail'),
545+
$context->getSetting('contactName')
546+
);
547+
}
548+
if ($copyAddress = $context->getSetting('copySubmissionAckAddress')) {
549+
$mail->addBcc($copyAddress);
550+
}
551+
552+
if ($user->getEmail() != $primaryAuthor->getEmail()) {
553+
$authorMail->addRecipient($primaryAuthor->getEmail(), $primaryAuthor->getFullName());
554+
}
555+
556+
$assignedAuthors = $submission->getAuthors();
557+
558+
foreach ($assignedAuthors as $author) {
559+
$authorEmail = $author->getEmail();
560+
// only add the author email if they have not already been added as the primary author
561+
// or user creating the submission.
562+
if ($authorEmail != $primaryAuthor->getEmail() && $authorEmail != $user->getEmail()) {
563+
$authorMail->addRecipient($author->getEmail(), $author->getFullName());
564+
}
565+
}
566+
$mail->bccAssignedSubEditors($submission->getId(), WORKFLOW_STAGE_ID_SUBMISSION);
567+
568+
$mail->assignParams(array(
569+
'authorName' => $user->getFullName(),
570+
'authorUsername' => $user->getUsername(),
571+
'editorialContactSignature' => $context->getSetting('contactName'),
572+
'submissionUrl' => $router->url($request, null, 'authorDashboard', 'submission', $submission->getId()),
573+
));
574+
575+
$authorMail->assignParams(array(
576+
'submitterName' => $user->getFullName(),
577+
'editorialContactSignature' => $context->getSetting('contactName'),
578+
));
579+
580+
$mail->send($request);
581+
582+
$recipients = $authorMail->getRecipients();
583+
if (!empty($recipients)) {
584+
$authorMail->send($request);
585+
}
586+
}
587+
588+
// Log submission.
589+
import('classes.log.SubmissionEventLogEntry'); // Constants
590+
import('lib.pkp.classes.log.SubmissionLog');
591+
SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_SUBMISSION_SUBMIT, 'submission.event.submissionSubmitted');
592+
593+
// End adaption from SubmissionSubmitStep4Form
594+
378595
}
379596

380597
$resultArray = array(
@@ -394,6 +611,7 @@ function createNewSubmission($title, $journalId, $fidusUrl, $fidusId) {
394611
$submissionDao = Application::getSubmissionDAO();
395612
$submission = $submissionDao->newDataObject();
396613
$submission->setStatus(STATUS_QUEUED);
614+
$submission->stampStatusModified();
397615
$submission->setSubmissionProgress(0);
398616
// $journalId in OJS is same as $contextId in PKP lib.
399617
$submission->setContextId($journalId);
@@ -417,13 +635,14 @@ function createNewSubmission($title, $journalId, $fidusUrl, $fidusId) {
417635
$submission->setData("sectionId", $sectionId);
418636
$submission->setTitle($title, $locale);
419637
$submission->setCleanTitle($title, $locale);
638+
420639
// Set fidus writer related fields.
421640
$submission->setData("fidusUrl", $fidusUrl);
422641
$submission->setData("fidusId", $fidusId);
423642
// Insert the submission
424-
$submissionId = $submissionDao->insertObject($submission);
643+
$submissionDao->insertObject($submission);
425644

426-
return $submissionId;
645+
return $submission;
427646
}
428647

429648
/**

FidusWriterPlugin.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Copyright 2016-17, Afshin Sadeghi ([email protected]) of the OSCOSS
55
* Project.
6-
* License: MIT. See LICENSE.md for details.
6+
* License: GNU GPL v2. See LICENSE.md for details.
77
*/
88

99
import('lib.pkp.classes.plugins.GenericPlugin');

0 commit comments

Comments
 (0)