addRoleAssignment( [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_SUB_EDITOR], ['fetchGrid', 'fetchRow', 'viewEmail'] ); } // // Getters/Setters // /** * Get the submission associated with this grid. * * @return Submission */ public function getSubmission() { return $this->_submission; } /** * Set the Submission * * @param Submission $submission */ public function setSubmission($submission) { $this->_submission = $submission; } // // Overridden methods from PKPHandler // /** * @see PKPHandler::authorize() * * @param PKPRequest $request * @param array $args * @param array $roleAssignments */ public function authorize($request, &$args, $roleAssignments) { $this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments)); $this->addPolicy(new UserAccessibleWorkflowStageRequiredPolicy($request, PKPApplication::WORKFLOW_TYPE_EDITORIAL)); $success = parent::authorize($request, $args, $roleAssignments); // Prevent authors from accessing review details, even if they are also // assigned as an editor, sub-editor or assistant. $userAssignedRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES); $this->_isCurrentUserAssignedAuthor = false; foreach ($userAssignedRoles as $stageId => $roles) { if (in_array(Role::ROLE_ID_AUTHOR, $roles)) { $this->_isCurrentUserAssignedAuthor = true; break; } } return $success; } /** * @copydoc GridHandler::initialize() * * @param null|mixed $args */ public function initialize($request, $args = null) { parent::initialize($request, $args); // Retrieve the authorized monograph. $submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION); $this->setSubmission($submission); $this->_stageId = (int) ($args['stageId'] ?? null); // Columns $cellProvider = new EventLogGridCellProvider($this->_isCurrentUserAssignedAuthor); $this->addColumn( new GridColumn( 'date', 'common.date', null, null, new DateGridCellProvider( $cellProvider, Application::get()->getRequest()->getContext()->getLocalizedDateFormatShort() ) ) ); $this->addColumn( new GridColumn( 'user', 'common.user', null, null, $cellProvider ) ); $this->addColumn( new GridColumn( 'event', 'common.event', null, null, $cellProvider, ['width' => 60] ) ); } // // Overridden methods from GridHandler // /** * @see GridHandler::getRowInstance() * * @return EventLogGridRow */ protected function getRowInstance() { return new EventLogGridRow($this->getSubmission(), $this->_isCurrentUserAssignedAuthor); } /** * Get the arguments that will identify the data in the grid * In this case, the monograph. * * @return array */ public function getRequestArgs() { $submission = $this->getSubmission(); return [ 'submissionId' => $submission->getId(), 'stageId' => $this->_stageId, ]; } /** * @copydoc GridHandler::loadData * * @param null|mixed $filter */ protected function loadData($request, $filter = null) { $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ $submission = $this->getSubmission(); $eventLogEntries = Repo::eventLog()->getCollector() ->filterByAssoc(PKPApplication::ASSOC_TYPE_SUBMISSION, [$submission->getId()]) ->getMany(); $emailLogEntries = $submissionEmailLogDao->getBySubmissionId($submission->getId()); $entries = array_merge($eventLogEntries->toArray(), $emailLogEntries->toArray()); // Sort the merged data by date, most recent first usort($entries, function ($a, $b) { $aDate = $a instanceof EventLogEntry ? $a->getDateLogged() : $a->getDateSent(); $bDate = $b instanceof EventLogEntry ? $b->getDateLogged() : $b->getDateSent(); if ($aDate == $bDate) { return 0; } return $aDate < $bDate ? 1 : -1; }); return $entries; } /** * Get the contents of the email * * @param array $args * @param PKPRequest $request * * @return JSONMessage JSON object */ public function viewEmail($args, $request) { $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ $emailLogEntry = $submissionEmailLogDao->getById((int) $args['emailLogEntryId']); return new JSONMessage(true, $this->_formatEmail($emailLogEntry)); } /** * Format the contents of the email * * * @return string Formatted email */ public function _formatEmail(EmailLogEntry $emailLogEntry) { $text = []; $text[] = __('email.from') . ': ' . htmlspecialchars($emailLogEntry->getFrom()); $text[] = __('email.to') . ': ' . htmlspecialchars($emailLogEntry->getRecipients()); if ($emailLogEntry->getCcs()) { $text[] = __('email.cc') . ': ' . htmlspecialchars($emailLogEntry->getCcs()); } if ($emailLogEntry->getBccs()) { $text[] = __('email.bcc') . ': ' . htmlspecialchars($emailLogEntry->getBccs()); } $text[] = __('email.subject') . ': ' . htmlspecialchars($emailLogEntry->getSubject()); return '