first commit
This commit is contained in:
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/FileInformationCenterHandler.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class FileInformationCenterHandler
|
||||
*
|
||||
* @ingroup controllers_informationCenter
|
||||
*
|
||||
* @brief Handle requests to view the information center for a file.
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\facades\Repo;
|
||||
use APP\notification\NotificationManager;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\controllers\informationCenter\form\NewFileNoteForm;
|
||||
use PKP\core\JSONMessage;
|
||||
use PKP\core\PKPApplication;
|
||||
use PKP\core\PKPRequest;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\log\event\EventLogEntry;
|
||||
use PKP\notification\PKPNotification;
|
||||
use PKP\security\authorization\WorkflowStageAccessPolicy;
|
||||
use PKP\security\Role;
|
||||
|
||||
class FileInformationCenterHandler extends InformationCenterHandler
|
||||
{
|
||||
/** @var object */
|
||||
public $submissionFile;
|
||||
|
||||
/** @var int */
|
||||
public $_stageId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->addRoleAssignment(
|
||||
[Role::ROLE_ID_ASSISTANT],
|
||||
[
|
||||
'viewInformationCenter',
|
||||
'viewHistory',
|
||||
'viewNotes', 'listNotes', 'saveNote', 'deleteNote',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPHandler::authorize()
|
||||
*/
|
||||
public function authorize($request, &$args, $roleAssignments)
|
||||
{
|
||||
// Require stage access
|
||||
$this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', (int) $request->getUserVar('stageId')));
|
||||
|
||||
return parent::authorize($request, $args, $roleAssignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc InformationCenterHandler::initialize
|
||||
*/
|
||||
public function initialize($request)
|
||||
{
|
||||
parent::initialize($request);
|
||||
|
||||
$this->_stageId = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_WORKFLOW_STAGE);
|
||||
$this->submissionFile = Repo::submissionFile()->get($request->getUserVar('submissionFileId'));
|
||||
|
||||
// Ensure data integrity.
|
||||
if (!$this->_submission || !$this->submissionFile || $this->_submission->getId() != $this->submissionFile->getData('submissionId')) {
|
||||
throw new \Exception('Unknown or invalid submission or submission file!');
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the main information center modal.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*/
|
||||
public function viewInformationCenter($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
// Assign variables to the template manager and display
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$templateMgr->assign('removeHistoryTab', (int) $request->getUserVar('removeHistoryTab'));
|
||||
|
||||
return parent::viewInformationCenter($args, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the notes tab.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function viewNotes($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$notesForm = new NewFileNoteForm($this->submissionFile->getId());
|
||||
$notesForm->initData();
|
||||
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$templateMgr->assign('notesList', $this->_listNotes($args, $request));
|
||||
$templateMgr->assign('pastNotesList', $this->_listPastNotes($args, $request));
|
||||
|
||||
return new JSONMessage(true, $notesForm->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the list of existing notes from prior files.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function _listPastNotes($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */
|
||||
|
||||
$notes = collect();
|
||||
$sourceSubmissionFileId = $this->submissionFile->getData('sourceSubmissionFileId');
|
||||
|
||||
if (!is_null($sourceSubmissionFileId)) {
|
||||
$notes = $noteDao->getByAssoc($this->_getAssocType(), $sourceSubmissionFileId);
|
||||
}
|
||||
|
||||
$templateMgr->assign('notes', $notes);
|
||||
|
||||
$user = $request->getUser();
|
||||
$templateMgr->assign([
|
||||
'currentUserId' => $user->getId(),
|
||||
'notesDeletable' => false,
|
||||
]);
|
||||
|
||||
return $templateMgr->fetch('controllers/informationCenter/notesList.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a note.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function saveNote($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$notesForm = new NewFileNoteForm($this->submissionFile->getId());
|
||||
$notesForm->readInputData();
|
||||
|
||||
if ($notesForm->validate()) {
|
||||
$notesForm->execute();
|
||||
|
||||
// Save to event log
|
||||
$this->_logEvent($request, $this->submissionFile, EventLogEntry::SUBMISSION_LOG_NOTE_POSTED, PKPApplication::ASSOC_TYPE_SUBMISSION_FILE);
|
||||
|
||||
$user = $request->getUser();
|
||||
$notificationManager = new NotificationManager();
|
||||
$notificationManager->createTrivialNotification($user->getId(), PKPNotification::NOTIFICATION_TYPE_SUCCESS, ['contents' => __('notification.addedNote')]);
|
||||
|
||||
$jsonViewNotesResponse = $this->viewNotes($args, $request);
|
||||
$json = new JSONMessage(true);
|
||||
$json->setEvent('dataChanged');
|
||||
$json->setEvent('noteAdded', $jsonViewNotesResponse->_content);
|
||||
|
||||
return $json;
|
||||
} else {
|
||||
// Return a JSON string indicating failure
|
||||
return new JSONMessage(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the contents of the event log.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function viewHistory($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$dispatcher = $request->getDispatcher();
|
||||
return $templateMgr->fetchAjax(
|
||||
'eventLogGrid',
|
||||
$dispatcher->url($request, PKPApplication::ROUTE_COMPONENT, null, 'grid.eventLog.SubmissionFileEventLogGridHandler', 'fetchGrid', null, $this->_getLinkParams())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing link parameters that subclasses
|
||||
* need to have passed to their various handlers (i.e. submission ID
|
||||
* to the delete note handler).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getLinkParams()
|
||||
{
|
||||
return array_merge(
|
||||
parent::_getLinkParams(),
|
||||
[
|
||||
'submissionFileId' => $this->submissionFile->getId(),
|
||||
'stageId' => $this->_stageId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association ID for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function _getAssocId()
|
||||
{
|
||||
return $this->submissionFile->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association type for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function _getAssocType()
|
||||
{
|
||||
return Application::ASSOC_TYPE_SUBMISSION_FILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the template
|
||||
*
|
||||
* @param PKPRequest $request
|
||||
*/
|
||||
public function setupTemplate($request)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
|
||||
$lastEvent = Repo::eventLog()->getCollector()
|
||||
->filterByAssoc(PKPApplication::ASSOC_TYPE_SUBMISSION_FILE, [$this->submissionFile->getId()])
|
||||
->getMany()
|
||||
->first();
|
||||
|
||||
if (!is_null($lastEvent)) {
|
||||
$templateMgr->assign('lastEvent', $lastEvent);
|
||||
|
||||
// Get the user who created the last event.
|
||||
$user = Repo::user()->get($lastEvent->getUserId(), true);
|
||||
$templateMgr->assign('lastEventUser', $user);
|
||||
}
|
||||
|
||||
return parent::setupTemplate($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/InformationCenterHandler.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class InformationCenterHandler
|
||||
*
|
||||
* @ingroup controllers_informationCenter
|
||||
*
|
||||
* @brief Parent class for file/submission information center handlers.
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\facades\Repo;
|
||||
use APP\handler\Handler;
|
||||
use APP\notification\NotificationManager;
|
||||
use APP\submission\Submission;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\core\Core;
|
||||
use PKP\core\JSONMessage;
|
||||
use PKP\core\PKPRequest;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\log\event\EventLogEntry;
|
||||
use PKP\note\NoteDAO;
|
||||
use PKP\notification\PKPNotification;
|
||||
use PKP\security\authorization\SubmissionAccessPolicy;
|
||||
use PKP\security\Role;
|
||||
use PKP\security\Validation;
|
||||
use PKP\submissionFile\SubmissionFile;
|
||||
|
||||
abstract class InformationCenterHandler extends Handler
|
||||
{
|
||||
/** @var Submission */
|
||||
public $_submission;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->addRoleAssignment(
|
||||
[Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN],
|
||||
[
|
||||
'viewInformationCenter',
|
||||
'viewHistory',
|
||||
'viewNotes', 'listNotes', 'saveNote', 'deleteNote',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Implement template methods from PKPHandler.
|
||||
//
|
||||
/**
|
||||
* @copydoc PKPHandler::authorize()
|
||||
*/
|
||||
public function authorize($request, &$args, $roleAssignments)
|
||||
{
|
||||
// Require a submission
|
||||
$this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments, 'submissionId'));
|
||||
return parent::authorize($request, $args, $roleAssignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and store away objects
|
||||
*
|
||||
* @param PKPRequest $request
|
||||
*/
|
||||
public function initialize($request)
|
||||
{
|
||||
parent::initialize($request);
|
||||
|
||||
// Fetch the submission and file to display information about
|
||||
$this->_submission = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Public operations
|
||||
//
|
||||
/**
|
||||
* Display the main information center modal.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function viewInformationCenter($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
return $templateMgr->fetchJson('controllers/informationCenter/informationCenter.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* View a list of notes posted on the item.
|
||||
* Subclasses must implement.
|
||||
*/
|
||||
abstract public function viewNotes($args, $request);
|
||||
|
||||
/**
|
||||
* Save a note.
|
||||
* Subclasses must implement.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*/
|
||||
abstract public function saveNote($args, $request);
|
||||
|
||||
/**
|
||||
* Delete a note.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function deleteNote($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$noteId = (int) $request->getUserVar('noteId');
|
||||
$noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */
|
||||
$note = $noteDao->getById($noteId);
|
||||
|
||||
if (!$request->checkCSRF() || !$note || $note->getAssocType() != $this->_getAssocType() || $note->getAssocId() != $this->_getAssocId()) {
|
||||
fatalError('Invalid note!');
|
||||
}
|
||||
$noteDao->deleteById($noteId);
|
||||
|
||||
$user = $request->getUser();
|
||||
$notificationManager = new NotificationManager();
|
||||
$notificationManager->createTrivialNotification($user->getId(), PKPNotification::NOTIFICATION_TYPE_SUCCESS, ['contents' => __('notification.removedNote')]);
|
||||
|
||||
$json = new JSONMessage(true);
|
||||
$jsonViewNotesResponse = $this->viewNotes($args, $request);
|
||||
$json->setEvent('dataChanged');
|
||||
$json->setEvent('noteDeleted', $jsonViewNotesResponse->_content);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the list of existing notes.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _listNotes($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */
|
||||
$notes = $noteDao->getByAssoc($this->_getAssocType(), $this->_getAssocId());
|
||||
$templateMgr->assign('notes', $notes);
|
||||
|
||||
$user = $request->getUser();
|
||||
$templateMgr->assign('currentUserId', $user->getId());
|
||||
$templateMgr->assign('notesDeletable', true);
|
||||
|
||||
$templateMgr->assign('notesListId', 'notesList');
|
||||
|
||||
return $templateMgr->fetch('controllers/informationCenter/notesList.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing link parameters that subclasses
|
||||
* need to have passed to their various handlers (i.e. submission ID
|
||||
* to the delete note handler).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getLinkParams()
|
||||
{
|
||||
return [
|
||||
'submissionId' => $this->_submission->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event for this file or submission
|
||||
*/
|
||||
public function _logEvent(
|
||||
PKPRequest $request,
|
||||
Submission|SubmissionFile $object,
|
||||
int $eventType, //SUBMISSION_LOG_... const
|
||||
int $assocType // PKPApplication::ASSOC_TYPE_SUBMISSION_FILE || PKPApplication::ASSOC_TYPE_SUBMISSION
|
||||
)
|
||||
{
|
||||
// Get the log event message
|
||||
switch ($eventType) {
|
||||
case EventLogEntry::SUBMISSION_LOG_NOTE_POSTED:
|
||||
$logMessage = 'informationCenter.history.notePosted';
|
||||
break;
|
||||
case EventLogEntry::SUBMISSION_LOG_MESSAGE_SENT:
|
||||
$logMessage = 'informationCenter.history.messageSent';
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
$eventLog = Repo::eventLog()->newDataObject([
|
||||
'assocType' => $assocType,
|
||||
'assocId' => $object->getId(),
|
||||
'eventType' => $eventType,
|
||||
'userId' => Validation::loggedInAs() ?? $request->getUser()->getId(),
|
||||
'message' => $logMessage,
|
||||
'isTranslated' => false,
|
||||
'dateLogged' => Core::getCurrentDate()
|
||||
]);
|
||||
Repo::eventLog()->add($eventLog);
|
||||
}
|
||||
|
||||
public function setupTemplate($request)
|
||||
{
|
||||
$linkParams = $this->_getLinkParams();
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
|
||||
// Preselect tab from keywords 'notes', 'notify', 'history'
|
||||
switch ($request->getUserVar('tab')) {
|
||||
case 'history':
|
||||
$templateMgr->assign('selectedTabIndex', 2);
|
||||
break;
|
||||
case 'notify':
|
||||
$userId = (int) $request->getUserVar('userId');
|
||||
if ($userId) {
|
||||
$linkParams['userId'] = $userId; // user validated in Listbuilder.
|
||||
}
|
||||
$templateMgr->assign('selectedTabIndex', 1);
|
||||
break;
|
||||
// notes is default
|
||||
default:
|
||||
$templateMgr->assign('selectedTabIndex', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
$templateMgr->assign('linkParams', $linkParams);
|
||||
parent::setupTemplate($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association ID for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function _getAssocId();
|
||||
|
||||
/**
|
||||
* Get the association type for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function _getAssocType();
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/SubmissionInformationCenterHandler.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class SubmissionInformationCenterHandler
|
||||
*
|
||||
* @ingroup controllers_informationCenter
|
||||
*
|
||||
* @brief Handle requests to view the information center for a submission.
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\notification\NotificationManager;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\controllers\informationCenter\form\NewSubmissionNoteForm;
|
||||
use PKP\core\JSONMessage;
|
||||
use PKP\core\PKPApplication;
|
||||
use PKP\log\event\EventLogEntry;
|
||||
use PKP\notification\PKPNotification;
|
||||
use PKP\security\Role;
|
||||
|
||||
class SubmissionInformationCenterHandler extends InformationCenterHandler
|
||||
{
|
||||
/** @var bool Is the current user assigned to an editorial role for this submission */
|
||||
public $_isCurrentUserAssignedEditor;
|
||||
|
||||
/**
|
||||
* @copydoc PKPHandler::authorize()
|
||||
*/
|
||||
public function authorize($request, &$args, $roleAssignments)
|
||||
{
|
||||
$success = parent::authorize($request, $args, $roleAssignments);
|
||||
|
||||
// Prevent users from accessing history unless they are assigned to an
|
||||
// appropriate role in this submission
|
||||
$this->_isCurrentUserAssignedEditor = false;
|
||||
$userAssignedRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES);
|
||||
if (!empty($userAssignedRoles)) {
|
||||
foreach ($userAssignedRoles as $stageId => $roles) {
|
||||
if (array_intersect([Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR], $roles)) {
|
||||
$this->_isCurrentUserAssignedEditor = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$userGlobalRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES);
|
||||
if (array_intersect([Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER], $userGlobalRoles)) {
|
||||
$this->_isCurrentUserAssignedEditor = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->_isCurrentUserAssignedEditor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc InformationCenterHandler::viewInformationCenter()
|
||||
*/
|
||||
public function viewInformationCenter($args, $request)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$user = $request->getUser();
|
||||
// Do not display the History tab if the user is not a manager or a sub-editor
|
||||
$userHasRole = $user->hasRole([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR], $this->_submission->getContextId());
|
||||
$templateMgr->assign('removeHistoryTab', !$userHasRole || !$this->_isCurrentUserAssignedEditor);
|
||||
return parent::viewInformationCenter($args, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the notes tab.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function viewNotes($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$notesForm = new NewSubmissionNoteForm($this->_submission->getId());
|
||||
$notesForm->initData();
|
||||
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$templateMgr->assign('notesList', $this->_listNotes($args, $request));
|
||||
|
||||
return new JSONMessage(true, $notesForm->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a note.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*/
|
||||
public function saveNote($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
|
||||
$notesForm = new NewSubmissionNoteForm($this->_submission->getId());
|
||||
$notesForm->readInputData();
|
||||
|
||||
if ($notesForm->validate()) {
|
||||
$notesForm->execute();
|
||||
|
||||
// Save to event log
|
||||
$this->_logEvent($request, $this->_submission, EventLogEntry::SUBMISSION_LOG_NOTE_POSTED, PKPApplication::ASSOC_TYPE_SUBMISSION);
|
||||
|
||||
$user = $request->getUser();
|
||||
$notificationManager = new NotificationManager();
|
||||
$notificationManager->createTrivialNotification($user->getId(), PKPNotification::NOTIFICATION_TYPE_SUCCESS, ['contents' => __('notification.addedNote')]);
|
||||
|
||||
$jsonViewNotesResponse = $this->viewNotes($args, $request);
|
||||
$json = new JSONMessage(true);
|
||||
$json->setEvent('dataChanged');
|
||||
$json->setEvent('noteAdded', $jsonViewNotesResponse->_content);
|
||||
|
||||
return $json;
|
||||
} else {
|
||||
// Return a JSON string indicating failure
|
||||
return new JSONMessage(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the contents of the event log.
|
||||
*
|
||||
* @param array $args
|
||||
* @param PKPRequest $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function viewHistory($args, $request)
|
||||
{
|
||||
$this->setupTemplate($request);
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$dispatcher = $request->getDispatcher();
|
||||
$templateMgr->assign('gridParameters', $this->_getLinkParams());
|
||||
return $templateMgr->fetchJson('controllers/informationCenter/submissionHistory.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association ID for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function _getAssocId()
|
||||
{
|
||||
return $this->_submission->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association type for this information center view
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function _getAssocType()
|
||||
{
|
||||
return Application::ASSOC_TYPE_SUBMISSION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/form/NewFileNoteForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class NewFileNoteForm
|
||||
*
|
||||
* @ingroup informationCenter_form
|
||||
*
|
||||
* @brief Form to display and post notes on a file
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter\form;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\template\TemplateManager;
|
||||
|
||||
class NewFileNoteForm extends NewNoteForm
|
||||
{
|
||||
/** @var int The ID of the submission file to attach the note to */
|
||||
public $fileId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct($fileId)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->fileId = $fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc type for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocType()
|
||||
{
|
||||
return Application::ASSOC_TYPE_SUBMISSION_FILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the submit note button locale key.
|
||||
* Can be overriden by subclasses.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitNoteLocaleKey()
|
||||
{
|
||||
return 'informationCenter.addNote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc ID for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocId()
|
||||
{
|
||||
return $this->fileId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc NewFileNoteForm::fetch()
|
||||
*
|
||||
* @param null|mixed $template
|
||||
*/
|
||||
public function fetch($request, $template = null, $display = false)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$templateMgr->assign('showEarlierEntries', true);
|
||||
return parent::fetch($request, $template, $display);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/form/NewNoteForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class NewNoteForm
|
||||
*
|
||||
* @ingroup informationCenter_form
|
||||
*
|
||||
* @brief Form to display and post notes on a file
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter\form;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\form\Form;
|
||||
use PKP\note\NoteDAO;
|
||||
|
||||
class NewNoteForm extends Form
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('controllers/informationCenter/notes.tpl');
|
||||
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc type for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocType()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc ID for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocId()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the submit note button locale key.
|
||||
* Should be overriden by subclasses.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitNoteLocaleKey()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the new note form template. Subclasses can
|
||||
* override this method to define other template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNewNoteFormTemplate()
|
||||
{
|
||||
return 'controllers/informationCenter/newNoteForm.tpl';
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::fetch()
|
||||
*
|
||||
* @param null|mixed $template
|
||||
*/
|
||||
public function fetch($request, $template = null, $display = false)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */
|
||||
$templateMgr->assign([
|
||||
'notes' => $noteDao->getByAssoc($this->getAssocType(), $this->getAssocId()),
|
||||
'submitNoteText' => $this->getSubmitNoteLocaleKey(),
|
||||
'newNoteFormTemplate' => $this->getNewNoteFormTemplate(),
|
||||
]);
|
||||
return parent::fetch($request, $template, $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::readInputData()
|
||||
*/
|
||||
public function readInputData()
|
||||
{
|
||||
$this->readUserVars([
|
||||
'newNote'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::execute()
|
||||
*/
|
||||
public function execute(...$functionArgs)
|
||||
{
|
||||
$request = Application::get()->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$noteDao = DAORegistry::getDAO('NoteDAO'); /** @var NoteDAO $noteDao */
|
||||
$note = $noteDao->newDataObject();
|
||||
|
||||
$note->setUserId($user->getId());
|
||||
$note->setContents($this->getData('newNote'));
|
||||
$note->setAssocType($this->getAssocType());
|
||||
$note->setAssocId($this->getAssocId());
|
||||
|
||||
parent::execute(...$functionArgs);
|
||||
return $noteDao->insertObject($note);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/informationCenter/form/NewSubmissionNoteForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class NewSubmissionNoteForm
|
||||
*
|
||||
* @ingroup informationCenter_form
|
||||
*
|
||||
* @brief Form to display and post notes on a file
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter\form;
|
||||
|
||||
use APP\core\Application;
|
||||
|
||||
class NewSubmissionNoteForm extends NewNoteForm
|
||||
{
|
||||
/** @var int The ID of the submission to attach the note to */
|
||||
public $submissionId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct($submissionId)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->submissionId = $submissionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc type for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocType()
|
||||
{
|
||||
return Application::ASSOC_TYPE_SUBMISSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the submit note button locale key.
|
||||
* Can be overriden by subclasses.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitNoteLocaleKey()
|
||||
{
|
||||
return 'informationCenter.addNote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the assoc ID for this note.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocId()
|
||||
{
|
||||
return $this->submissionId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @file controllers/informationCenter/linkAction/FileInfoCenterLinkAction.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class FileInfoCenterLinkAction
|
||||
*
|
||||
* @ingroup controllers_informationCenter
|
||||
*
|
||||
* @brief A base action to open up the information center for a file.
|
||||
*/
|
||||
|
||||
namespace PKP\controllers\informationCenter\linkAction;
|
||||
|
||||
use APP\core\Request;
|
||||
use PKP\controllers\api\file\linkAction\FileLinkAction;
|
||||
use PKP\core\PKPRequest;
|
||||
use PKP\linkAction\request\AjaxModal;
|
||||
use PKP\submissionFile\SubmissionFile;
|
||||
|
||||
class FileInfoCenterLinkAction extends FileLinkAction
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Request $request
|
||||
* @param SubmissionFile $submissionFile the submission file
|
||||
* to show information about.
|
||||
* @param int $stageId (optional) The stage id that user is looking at.
|
||||
*/
|
||||
public function __construct($request, $submissionFile, $stageId = null)
|
||||
{
|
||||
// Instantiate the information center modal.
|
||||
$ajaxModal = $this->getModal($request, $submissionFile, $stageId);
|
||||
|
||||
// Configure the file link action.
|
||||
parent::__construct(
|
||||
'moreInformation',
|
||||
$ajaxModal,
|
||||
__('grid.action.moreInformation'),
|
||||
'more_info'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the modal for this link action.
|
||||
*
|
||||
* @param PKPRequest $request
|
||||
* @param SubmissionFile $submissionFile
|
||||
* @param int $stageId
|
||||
*
|
||||
* @return AjaxModal
|
||||
*/
|
||||
public function getModal($request, $submissionFile, $stageId)
|
||||
{
|
||||
$router = $request->getRouter();
|
||||
|
||||
$title = (isset($submissionFile)) ? implode(': ', [__('informationCenter.informationCenter'), htmlspecialchars($submissionFile->getLocalizedData('name'))]) : __('informationCenter.informationCenter');
|
||||
|
||||
$ajaxModal = new AjaxModal(
|
||||
$router->url(
|
||||
$request,
|
||||
null,
|
||||
'informationCenter.FileInformationCenterHandler',
|
||||
'viewInformationCenter',
|
||||
null,
|
||||
$this->getActionArgs($submissionFile, $stageId)
|
||||
),
|
||||
$title,
|
||||
'modal_information'
|
||||
);
|
||||
|
||||
return $ajaxModal;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user