/** * Log the upload event. * Must be overridden in subclasses. * @param PKPRequest $request * @param PKPUser $user * @param SubmissionFile $submissionFile * @param int $assocType * @param int $revisedFileId * @param int $fileStage */ function _logEvent($request, $user, $submissionFile, $assocType, $revisedFileId, $fileStage) { // log the upload event. import('lib.pkp.classes.log.SubmissionFileLog'); import('lib.pkp.classes.log.SubmissionFileEventLogEntry'); // constants $localeKey = $revisedFileId ? 'submission.event.revisionUploaded' : 'submission.event.fileUploaded'; $assocType = $revisedFileId ? SUBMISSION_LOG_FILE_REVISION_UPLOAD : SUBMISSION_LOG_FILE_UPLOAD; SubmissionFileLog::logEvent($request, $submissionFile, $assocType, $localeKey, array('fileStage' => $fileStage, 'revisedFileId' => $revisedFileId, 'fileId' => $submissionFile->getFileId(), 'fileRevision' => $submissionFile->getRevision(), 'originalFileName' => $submissionFile->getOriginalFileName(), 'submissionId' => $this->getData('submissionId'), 'username' => $user->getUsername())); }
function User() { parent::PKPUser(); }
/** * Setup the fixture for all tests that covers the * PKPNotificationManager::createNotification() method in * a send email scenario. * @return array Fixture objects. */ private function getFixtureCreateNotificationSendEmail($expectedNotification) { // Add the notification type to the emailed notifications set. $emailedNotifications = array($expectedNotification->getType()); $notificationMgrStub = $this->getMgrStubForCreateNotificationTests(array(), $emailedNotifications, array('getMailTemplate')); // Stub a PKPRequest object. $requestStub = $this->getMock('PKPRequest', array('getSite', 'getContext')); // Some site, user and notification data are required for composing the email. // Retrieve/define them so we can check later. $siteTitle = 'Site title'; $siteContactName = 'Site contact name'; $siteEmail = '*****@*****.**'; $userFirstName = 'FirstName'; $userLastName = 'UserLastName'; $userEmail = '*****@*****.**'; $notificationContents = $notificationMgrStub->getNotificationContents($requestStub, $expectedNotification); $contextTitle = 'Context title'; // Build a test user object. import('lib.pkp.classes.user.PKPUser'); $testUser = new PKPUser(); $testUser->setId($expectedNotification->getUserId()); $testUser->setFirstName($userFirstName); $testUser->setLastName($userLastName); $testUser->setEmail($userEmail); // Get the user full name to check. $userFullName = $testUser->getFullName(); // Mock MailTemplate class so we can verify // notification manager interaction with it. Avoid // calling the mail template original constructor. $mailTemplateMock = $this->getMock('MailTemplate', array('setReplyTo', 'addRecipient', 'assignParams', 'send'), array(), '', false); $mailTemplateMock->expects($this->any())->method('setReplyTo')->with($this->equalTo($siteEmail), $this->equalTo($siteContactName)); $mailTemplateMock->expects($this->any())->method('addRecipient')->with($this->equalTo($userEmail), $this->equalTo($userFullName)); $mailTemplateMock->expects($this->any())->method('assignParams')->with($this->logicalAnd($this->contains($notificationContents), $this->contains($contextTitle))); $mailTemplateMock->expects($this->once())->method('send'); // Inject our MailTemplate mock in notification manager. $notificationMgrStub->expects($this->any())->method('getMailTemplate')->will($this->returnValue($mailTemplateMock)); // Stub site. $siteStub = $this->getMock('Site', array('getLocalizedContactName', 'getLocalizedTitle', 'getLocalizedContactEmail')); $siteStub->expects($this->any())->method('getLocalizedContactName')->will($this->returnValue($siteContactName)); $siteStub->expects($this->any())->method('getLocalizedTitle')->will($this->returnValue($siteTitle)); $siteStub->expects($this->any())->method('getLocalizedContactEmail')->will($this->returnValue($siteEmail)); // Inject site stub into our request stub. $requestStub->expects($this->any())->method('getSite')->will($this->returnValue($siteStub)); // Stub context. $contextStub = $this->getMock('Context', array('getLocalizedName')); $contextStub->expects($this->any())->method('getLocalizedName')->will($this->returnValue($contextTitle)); // Inject context stub into our request stub. $requestStub->expects($this->any())->method('getContext')->will($this->returnValue($contextStub)); // Register a UserDao stub to return the test user. $userDaoStub = $this->getMock('UserDAO', array('getById')); $userDaoStub->expects($this->any())->method('getById')->will($this->returnValue($testUser)); DAORegistry::registerDAO('UserDAO', $userDaoStub); return array($notificationMgrStub, $requestStub); }
function __construct() { parent::__construct(); }
/** * Internal method to create the necessary notifications, with user validation. * @param PKPRquest $request * @param Submission $submission * @param PKPUser $user * @param string $template */ function _createNotifications($request, $submission, $user, $template) { $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); $stageAssignments = $stageAssignmentDao->getBySubmissionAndStageId($submission->getId(), $this->getStageId(), null, $user->getId()); $notificationMgr = new NotificationManager(); switch ($template) { case 'COPYEDIT_REQUEST': while ($stageAssignment = $stageAssignments->next()) { $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId()); if (in_array($userGroup->getRoleId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) { import('lib.pkp.classes.submission.SubmissionFile'); $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); $submissionFileSignoffDao = DAORegistry::getDAO('SubmissionFileSignoffDAO'); $submissionFiles = $submissionFileDao->getLatestRevisions($submission->getId(), SUBMISSION_FILE_COPYEDIT); foreach ($submissionFiles as $submissionFile) { $signoffFactory = $submissionFileSignoffDao->getAllBySymbolic('SIGNOFF_COPYEDITING', $submissionFile->getFileId()); while ($signoff = $signoffFactory->next()) { $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_COPYEDIT_ASSIGNMENT), array($user->getId()), ASSOC_TYPE_SIGNOFF, $signoff->getId()); } } return; } } // User not in valid role for this task/notification. break; case 'LAYOUT_REQUEST': while ($stageAssignment = $stageAssignments->next()) { $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId()); if (in_array($userGroup->getRoleId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) { $this->_addUploadTaskNotification($request, NOTIFICATION_TYPE_LAYOUT_ASSIGNMENT, $user->getId(), $submission->getId()); return; } } // User not in valid role for this task/notification. break; case 'INDEX_REQUEST': while ($stageAssignment = $stageAssignments->next()) { $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId()); if (in_array($userGroup->getRoleId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) { $this->_addUploadTaskNotification($request, NOTIFICATION_TYPE_INDEX_ASSIGNMENT, $user->getId(), $submission->getId()); return; } } // User not in valid role for this task/notification. break; } }
/** * Determine if a particular stage has a notification pending. If so, return true. * This is used to set the CSS class of the submission progress bar. * @param PKPUser $user * @param int $stageId */ function _notificationOptionsByStage(&$user, $stageId, $contextId) { $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION); $notificationDao = DAORegistry::getDAO('NotificationDAO'); $signOffNotificationType = $this->_getSignoffNotificationTypeByStageId($stageId); $editorAssignmentNotificationType = $this->_getEditorAssignmentNotificationTypeByStageId($stageId); $editorAssignments = $notificationDao->getByAssoc(ASSOC_TYPE_SUBMISSION, $submission->getId(), null, $editorAssignmentNotificationType, $contextId); if (isset($signOffNotificationType)) { $signoffAssignments = $notificationDao->getByAssoc(ASSOC_TYPE_SUBMISSION, $submission->getId(), $user->getId(), $signOffNotificationType, $contextId); } // if the User has assigned TASKs in this stage check, return true if (!$editorAssignments->wasEmpty() || isset($signoffAssignments) && !$signoffAssignments->wasEmpty()) { return true; } // check for more specific notifications on those stages that have them. if ($stageId == WORKFLOW_STAGE_ID_PRODUCTION) { $submissionApprovalNotification = $notificationDao->getByAssoc(ASSOC_TYPE_SUBMISSION, $submission->getId(), null, NOTIFICATION_TYPE_APPROVE_SUBMISSION, $contextId); if (!$submissionApprovalNotification->wasEmpty()) { return true; } } if ($stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) { $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); $reviewRounds = $reviewRoundDao->getBySubmissionId($submission->getId(), $stageId); $notificationTypes = array(NOTIFICATION_TYPE_REVIEW_ROUND_STATUS, NOTIFICATION_TYPE_ALL_REVIEWS_IN); while ($reviewRound = $reviewRounds->next()) { foreach ($notificationTypes as $type) { $notifications = $notificationDao->getByAssoc(ASSOC_TYPE_REVIEW_ROUND, $reviewRound->getId(), null, $type, $contextId); if (!$notifications->wasEmpty()) { return true; } } } } return false; }