first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
@@ -0,0 +1,167 @@
<?php
/**
* @file controllers/api/file/linkAction/AddFileLinkAction.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 AddFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to add a submission file.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\submissionFile\SubmissionFile;
class AddFileLinkAction extends BaseAddFileLinkAction
{
/**
* Constructor
*
* @param Request $request
* @param int $submissionId The submission the file should be
* uploaded to.
* @param int $stageId The workflow stage in which the file
* uploader is being instantiated (one of the WORKFLOW_STAGE_ID_*
* constants).
* @param array $uploaderRoles The ids of all roles allowed to upload
* in the context of this action.
* @param int $fileStage The file stage the file should be
* uploaded to (one of the SubmissionFile::SUBMISSION_FILE_* constants).
* @param int $assocType The type of the element the file should
* be associated with (one fo the Application::ASSOC_TYPE_* constants).
* @param int $assocId The id of the element the file should be
* associated with.
* @param int $reviewRoundId The current review round ID (if any)
* @param int $revisedFileId Revised file ID, if any
* @param bool $dependentFilesOnly whether to only include dependent
* files in the Genres dropdown.
* @param int $queryId The query id. Use when the assoc details point
* to a note
*/
public function __construct(
$request,
$submissionId,
$stageId,
$uploaderRoles,
$fileStage,
$assocType = null,
$assocId = null,
$reviewRoundId = null,
$revisedFileId = null,
$dependentFilesOnly = false,
$queryId = null
) {
// Create the action arguments array.
$actionArgs = ['fileStage' => $fileStage, 'reviewRoundId' => $reviewRoundId];
if (is_numeric($assocType) && is_numeric($assocId)) {
$actionArgs['assocType'] = (int)$assocType;
$actionArgs['assocId'] = (int)$assocId;
}
if ($revisedFileId) {
$actionArgs['revisedFileId'] = $revisedFileId;
$actionArgs['revisionOnly'] = true;
}
if ($dependentFilesOnly) {
$actionArgs['dependentFilesOnly'] = true;
}
if ($queryId) {
$actionArgs['queryId'] = $queryId;
}
// Identify text labels based on the file stage.
$textLabels = AddFileLinkAction::_getTextLabels($fileStage);
// Call the parent class constructor.
parent::__construct(
$request,
$submissionId,
$stageId,
$uploaderRoles,
$actionArgs,
__($textLabels['wizardTitle']),
__($textLabels['buttonLabel'])
);
}
//
// Private methods
//
/**
* Static method to return text labels
* for upload to different file stages.
*
* @param int $fileStage One of the
* SubmissionFile::SUBMISSION_FILE_* constants.
*
* @return array
*/
public static function _getTextLabels($fileStage)
{
static $textLabels = [
SubmissionFile::SUBMISSION_FILE_SUBMISSION => [
'wizardTitle' => 'submission.submit.uploadSubmissionFile',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_REVIEW_FILE => [
'wizardTitle' => 'editor.submissionReview.uploadFile',
'buttonLabel' => 'editor.submissionReview.uploadFile'
],
SubmissionFile::SUBMISSION_FILE_INTERNAL_REVIEW_FILE => [
'wizardTitle' => 'editor.submissionReview.uploadFile',
'buttonLabel' => 'editor.submissionReview.uploadFile'
],
SubmissionFile::SUBMISSION_FILE_REVIEW_ATTACHMENT => [
'wizardTitle' => 'editor.submissionReview.uploadAttachment',
'buttonLabel' => 'editor.submissionReview.uploadAttachment'
],
SubmissionFile::SUBMISSION_FILE_ATTACHMENT => [
'wizardTitle' => 'editor.submissionReview.uploadFile',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_REVIEW_REVISION => [
'wizardTitle' => 'editor.submissionReview.uploadFile',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_INTERNAL_REVIEW_REVISION => [
'wizardTitle' => 'editor.submissionReview.uploadFile',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_FINAL => [
'wizardTitle' => 'submission.upload.finalDraft',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_COPYEDIT => [
'wizardTitle' => 'submission.upload.copyeditedVersion',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_PRODUCTION_READY => [
'wizardTitle' => 'submission.upload.productionReady',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_PROOF => [
'wizardTitle' => 'submission.upload.proof',
'buttonLabel' => 'submission.changeFile'
],
SubmissionFile::SUBMISSION_FILE_DEPENDENT => [
'wizardTitle' => 'submission.upload.dependent',
'buttonLabel' => 'submission.addFile'
],
SubmissionFile::SUBMISSION_FILE_QUERY => [
'wizardTitle' => 'submission.upload.query',
'buttonLabel' => 'submission.addFile'
],
];
assert(isset($textLabels[$fileStage]));
return $textLabels[$fileStage];
}
}
@@ -0,0 +1,54 @@
<?php
/**
* @file controllers/api/file/linkAction/AddRevisionLinkAction.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 AddRevisionLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to upload a revision of file currently under review.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submissionFile\SubmissionFile;
class AddRevisionLinkAction extends BaseAddFileLinkAction
{
/**
* Constructor
*
* @param Request $request
* @param ReviewRound $reviewRound The review round to upload to.
* @param array $uploaderRoles The ids of all roles allowed to upload
* in the context of this action.
*/
public function __construct($request, $reviewRound, $uploaderRoles)
{
// Create the action arguments array.
$actionArgs = [
'fileStage' => SubmissionFile::SUBMISSION_FILE_REVIEW_REVISION,
'stageId' => $reviewRound->getStageId(),
'reviewRoundId' => $reviewRound->getId(),
'revisionOnly' => '1'
];
// Call the parent class constructor.
parent::__construct(
$request,
$reviewRound->getSubmissionId(),
$reviewRound->getStageId(),
$uploaderRoles,
$actionArgs,
__('submission.review.uploadRevisionToRound', ['round' => $reviewRound->getRound()]),
__('submission.addFile')
);
}
}
@@ -0,0 +1,80 @@
<?php
/**
* @defgroup controllers_api_file_linkAction Link action API controller
*/
/**
* @file controllers/api/file/linkAction/BaseAddFileLinkAction.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 BaseAddFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief Abstract base class for file upload actions.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\core\PKPApplication;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\WizardModal;
class BaseAddFileLinkAction extends LinkAction
{
/**
* Constructor
*
* @param Request $request
* @param int $submissionId The submission the file should be
* uploaded to.
* @param int $stageId The workflow stage in which the file
* uploader is being instantiated (one of the WORKFLOW_STAGE_ID_*
* constants).
* @param array $uploaderRoles The ids of all roles allowed to upload
* in the context of this action.
* @param array $actionArgs The arguments to be passed into the file
* upload wizard.
* @param string $wizardTitle The title to be displayed in the file
* upload wizard.
* @param string $buttonLabel The link action's button label.
*/
public function __construct(
$request,
$submissionId,
$stageId,
$uploaderRoles,
$actionArgs,
$wizardTitle,
$buttonLabel
) {
// Augment the action arguments array.
$actionArgs['submissionId'] = $submissionId;
$actionArgs['stageId'] = $stageId;
assert(is_array($uploaderRoles) && count($uploaderRoles) >= 1);
$actionArgs['uploaderRoles'] = implode('-', (array) $uploaderRoles);
// Instantiate the file upload modal.
$dispatcher = $request->getDispatcher();
$modal = new WizardModal(
$dispatcher->url(
$request,
PKPApplication::ROUTE_COMPONENT,
null,
'wizard.fileUpload.FileUploadWizardHandler',
'startWizard',
null,
$actionArgs
),
$wizardTitle,
'modal_add_file'
);
// Configure the link action.
parent::__construct('addFile', $modal, $buttonLabel, 'add');
}
}
@@ -0,0 +1,56 @@
<?php
/**
* @file controllers/api/file/linkAction/DeleteFileLinkAction.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 DeleteFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to delete a file.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\linkAction\request\RemoteActionConfirmationModal;
use PKP\submissionFile\SubmissionFile;
class DeleteFileLinkAction extends FileLinkAction
{
/**
* Constructor
*
* @param Request $request
* @param SubmissionFile $submissionFile the submission file to be deleted
* @param int $stageId (optional)
* @param string $localeKey (optional) Locale key to use for delete link
* be deleted.
*/
public function __construct($request, $submissionFile, $stageId, $localeKey = 'grid.action.delete')
{
$router = $request->getRouter();
parent::__construct(
'deleteFile',
new RemoteActionConfirmationModal(
$request->getSession(),
__('common.confirmDelete'),
__('common.delete'),
$router->url(
$request,
null,
'api.file.ManageFileApiHandler',
'deleteFile',
null,
$this->getActionArgs($submissionFile, $stageId)
),
'modal_delete'
),
__($localeKey),
'delete'
);
}
}
@@ -0,0 +1,91 @@
<?php
/**
* @file controllers/api/file/linkAction/DownloadFileLinkAction.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 DownloadFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to download a file.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\linkAction\request\PostAndRedirectAction;
use PKP\submissionFile\SubmissionFile;
class DownloadFileLinkAction extends FileLinkAction
{
/** @var string Optional label to use instead of file name */
public $label;
/**
* Constructor
*
* @param Request $request
* @param SubmissionFile $submissionFile the submission file to
* link to.
* @param int $stageId (optional)
* @param string $label (optional) Label to use instead of filename
* @param int $fileId (optional) Download a specific revision of a file
* @param string $filename (optional) The filename to use for the file
*/
public function __construct($request, $submissionFile, $stageId = null, $label = null, $fileId = null, $filename = null)
{
// Instantiate the redirect action request.
$router = $request->getRouter();
$this->label = $label;
$actionArgs = $this->getActionArgs($submissionFile, $stageId);
if ($fileId) {
$actionArgs['fileId'] = $fileId;
}
if ($filename) {
$actionArgs['filename'] = $filename;
}
$redirectRequest = new PostAndRedirectAction(
$router->url(
$request,
null,
'api.file.FileApiHandler',
'recordDownload',
null,
$actionArgs
),
$router->url(
$request,
null,
'api.file.FileApiHandler',
'downloadFile',
null,
$actionArgs
)
);
// Configure the file link action.
parent::__construct(
'downloadFile',
$redirectRequest,
htmlspecialchars($this->getLabel($submissionFile))
);
}
/**
* Get the label for the file download action.
*
* @param SubmissionFile $submissionFile
*
* @return string
*/
public function getLabel($submissionFile)
{
if ($this->label !== null) {
return $this->label;
}
return $submissionFile->getLocalizedData('name');
}
}
@@ -0,0 +1,84 @@
<?php
/**
* @file controllers/api/file/linkAction/DownloadLibraryFileLinkAction.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 DownloadLibraryFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to download a library file.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\context\LibraryFile;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\PostAndRedirectAction;
class DownloadLibraryFileLinkAction extends LinkAction
{
/**
* Constructor
*
* @param Request $request
* @param LibraryFile $libraryFile the library file to
* link to.
*/
public function __construct($request, $libraryFile)
{
// Instantiate the redirect action request.
$router = $request->getRouter();
$redirectRequest = new PostAndRedirectAction(
$router->url(
$request,
null,
'api.file.FileApiHandler',
'enableLinkAction',
null,
$this->getActionArgs($libraryFile)
),
$router->url(
$request,
null,
'api.file.FileApiHandler',
'downloadLibraryFile',
null,
$this->getActionArgs($libraryFile)
)
);
// Configure the file link action.
parent::__construct(
'downloadFile',
$redirectRequest,
htmlspecialchars($libraryFile->getLocalizedName()),
$libraryFile->getDocumentType()
);
}
/**
* Return the action arguments to address a file.
*
* @param LibraryFile $libraryFile
*
* @return array
*/
public function getActionArgs(&$libraryFile)
{
assert($libraryFile instanceof LibraryFile);
// Create the action arguments array.
$args = ['libraryFileId' => $libraryFile->getId()];
if ($libraryFile->getSubmissionId()) {
$args['submissionId'] = $libraryFile->getSubmissionId();
}
return $args;
}
}
@@ -0,0 +1,59 @@
<?php
/**
* @file controllers/api/file/linkAction/EditFileLinkAction.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 EditFileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An action to edit a file's metadata.
*/
namespace PKP\controllers\api\file\linkAction;
use APP\core\Request;
use PKP\core\PKPApplication;
use PKP\linkAction\request\AjaxModal;
use PKP\submissionFile\SubmissionFile;
class EditFileLinkAction extends FileLinkAction
{
/**
* Constructor
*
* @param Request $request
* @param SubmissionFile $submissionFile the submission file to edit.
* @param int $stageId Stage ID
*/
public function __construct($request, $submissionFile, $stageId)
{
// Instantiate the AJAX modal request.
$router = $request->getRouter();
$dispatcher = $router->getDispatcher();
$modal = new AjaxModal(
$dispatcher->url(
$request,
PKPApplication::ROUTE_COMPONENT,
null,
'api.file.ManageFileApiHandler',
'editMetadata',
null,
$this->getActionArgs($submissionFile, $stageId)
),
__('grid.action.editFile'),
'modal_information'
);
// Configure the file link action.
parent::__construct(
'editFile',
$modal,
__('common.edit'),
'edit'
);
}
}
@@ -0,0 +1,49 @@
<?php
/**
* @file controllers/api/file/linkAction/FileLinkAction.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 FileLinkAction
*
* @ingroup controllers_api_file_linkAction
*
* @brief An abstract file action.
*/
namespace PKP\controllers\api\file\linkAction;
use PKP\linkAction\LinkAction;
use PKP\submissionFile\SubmissionFile;
class FileLinkAction extends LinkAction
{
//
// Protected helper function
//
/**
* Return the action arguments to address a file.
*
* @param SubmissionFile $submissionFile
* @param int $stageId (optional)
*
* @return array
*/
public function getActionArgs($submissionFile, $stageId = null)
{
assert($submissionFile instanceof SubmissionFile);
// Create the action arguments array.
$args = [
'submissionFileId' => $submissionFile->getId(),
'submissionId' => $submissionFile->getData('submissionId')
];
if ($stageId) {
$args['stageId'] = $stageId;
}
return $args;
}
}