first commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/components/fileAttachers/Base.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class Base
|
||||
*
|
||||
* @ingroup classes_controllers_form
|
||||
*
|
||||
* @brief A base class for FileAttacher components.
|
||||
*/
|
||||
|
||||
namespace PKP\components\fileAttachers;
|
||||
|
||||
abstract class BaseAttacher
|
||||
{
|
||||
public string $component;
|
||||
public string $label;
|
||||
public string $description;
|
||||
public string $button;
|
||||
|
||||
/**
|
||||
* Initialize the file attacher
|
||||
*
|
||||
* @param string $label The label to display for this file attacher
|
||||
* @param string $description A description of this file attacher
|
||||
* @param string $button The label for the button to activate this file attacher
|
||||
*/
|
||||
public function __construct(string $label, string $description, string $button)
|
||||
{
|
||||
$this->label = $label;
|
||||
$this->description = $description;
|
||||
$this->button = $button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the initial state for this file attacher
|
||||
*/
|
||||
public function getState(): array
|
||||
{
|
||||
return [
|
||||
'component' => $this->component,
|
||||
'label' => $this->label,
|
||||
'description' => $this->description,
|
||||
'button' => $this->button,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/components/fileAttachers/FileStage.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class FileStage
|
||||
*
|
||||
* @ingroup classes_controllers_form
|
||||
*
|
||||
* @brief A class to compile initial state for a FileAttacherFileStage component.
|
||||
*/
|
||||
|
||||
namespace PKP\components\fileAttachers;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\submission\Submission;
|
||||
use PKP\context\Context;
|
||||
use PKP\submission\reviewRound\ReviewRound;
|
||||
|
||||
class FileStage extends BaseAttacher
|
||||
{
|
||||
public string $component = 'FileAttacherFileStage';
|
||||
public Context $context;
|
||||
public Submission $submission;
|
||||
public array $fileStages = [];
|
||||
|
||||
/**
|
||||
* Initialize a file stage attacher
|
||||
*
|
||||
* @param string $label The label to display for this file attacher
|
||||
* @param string $description A description of this file attacher
|
||||
* @param string $button The label for the button to activate this file attacher
|
||||
*/
|
||||
public function __construct(Context $context, Submission $submission, string $label, string $description, string $button)
|
||||
{
|
||||
parent::__construct($label, $description, $button);
|
||||
$this->context = $context;
|
||||
$this->submission = $submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a submission file stage that can be used for attachments
|
||||
*/
|
||||
public function withFileStage(int $fileStage, string $label, ?ReviewRound $reviewRound = null): self
|
||||
{
|
||||
$queryParams = ['fileStages' => [$fileStage]];
|
||||
if ($reviewRound) {
|
||||
$queryParams['reviewRoundIds'] = [$reviewRound->getId()];
|
||||
}
|
||||
$this->fileStages[] = [
|
||||
'label' => $label,
|
||||
'queryParams' => $queryParams,
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the props for this file attacher
|
||||
*/
|
||||
public function getState(): array
|
||||
{
|
||||
$props = parent::getState();
|
||||
|
||||
$request = Application::get()->getRequest();
|
||||
$props['submissionFilesApiUrl'] = $request->getDispatcher()->url(
|
||||
$request,
|
||||
Application::ROUTE_API,
|
||||
$this->context->getData('urlPath'),
|
||||
'submissions/' . $this->submission->getId() . '/files'
|
||||
);
|
||||
|
||||
$props['fileStages'] = $this->fileStages;
|
||||
$props['attachSelectedLabel'] = __('common.attachSelected');
|
||||
$props['downloadLabel'] = __('common.download');
|
||||
$props['backLabel'] = __('common.back');
|
||||
|
||||
return $props;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/components/fileAttachers/Library.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class Library
|
||||
*
|
||||
* @ingroup classes_controllers_form
|
||||
*
|
||||
* @brief A class to compile initial state for a FileAttacherLibrary component.
|
||||
*/
|
||||
|
||||
namespace PKP\components\fileAttachers;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\submission\Submission;
|
||||
use PKP\context\Context;
|
||||
|
||||
class Library extends BaseAttacher
|
||||
{
|
||||
public string $component = 'FileAttacherLibrary';
|
||||
public Context $context;
|
||||
public Submission $submission;
|
||||
|
||||
/**
|
||||
* Initialize this file attacher
|
||||
*
|
||||
*/
|
||||
public function __construct(Context $context, ?Submission $submission = null)
|
||||
{
|
||||
parent::__construct(
|
||||
__('email.addAttachment.libraryFiles'),
|
||||
__('email.addAttachment.libraryFiles.description'),
|
||||
__('email.addAttachment.libraryFiles.attach')
|
||||
);
|
||||
$this->context = $context;
|
||||
$this->submission = $submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the props for this file attacher
|
||||
*/
|
||||
public function getState(): array
|
||||
{
|
||||
$props = parent::getState();
|
||||
|
||||
$request = Application::get()->getRequest();
|
||||
$props['libraryApiUrl'] = $request->getDispatcher()->url(
|
||||
$request,
|
||||
Application::ROUTE_API,
|
||||
$this->context->getData('urlPath'),
|
||||
'_library'
|
||||
);
|
||||
if ($this->submission) {
|
||||
$props['includeSubmissionId'] = $this->submission->getId();
|
||||
}
|
||||
$props['attachSelectedLabel'] = __('common.attachSelected');
|
||||
$props['backLabel'] = __('common.back');
|
||||
$props['downloadLabel'] = __('common.download');
|
||||
|
||||
return $props;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/components/fileAttachers/ReviewFiles.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ReviewFiles
|
||||
*
|
||||
* @ingroup classes_controllers_form
|
||||
*
|
||||
* @brief A class to compile initial state for a FileAttacherReviewFiles component.
|
||||
*/
|
||||
|
||||
namespace PKP\components\fileAttachers;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\core\Services;
|
||||
use APP\facades\Repo;
|
||||
use Exception;
|
||||
use PKP\context\Context;
|
||||
use PKP\submission\reviewAssignment\ReviewAssignment;
|
||||
use PKP\submissionFile\SubmissionFile;
|
||||
|
||||
class ReviewFiles extends BaseAttacher
|
||||
{
|
||||
public string $component = 'FileAttacherReviewFiles';
|
||||
public Context $context;
|
||||
|
||||
/** @var iterable<SubmissionFile> $files */
|
||||
public iterable $files;
|
||||
|
||||
/** @var array<ReviewAssignment> $reviewAssignments */
|
||||
public array $reviewAssignments;
|
||||
|
||||
/**
|
||||
* Initialize this file attacher
|
||||
*
|
||||
* @param string $label The label to display for this file attacher
|
||||
* @param string $description A description of this file attacher
|
||||
* @param string $button The label for the button to activate this file attacher
|
||||
*/
|
||||
public function __construct(string $label, string $description, string $button, iterable $files, array $reviewAssignments, Context $context)
|
||||
{
|
||||
parent::__construct($label, $description, $button);
|
||||
$this->files = $files;
|
||||
$this->reviewAssignments = $reviewAssignments;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the props for this file attacher
|
||||
*/
|
||||
public function getState(): array
|
||||
{
|
||||
$props = parent::getState();
|
||||
$props['attachSelectedLabel'] = __('common.attachSelected');
|
||||
$props['backLabel'] = __('common.back');
|
||||
$props['downloadLabel'] = __('common.download');
|
||||
$props['files'] = $this->getFilesState();
|
||||
|
||||
return $props;
|
||||
}
|
||||
|
||||
protected function getFilesState(): array
|
||||
{
|
||||
$request = Application::get()->getRequest();
|
||||
|
||||
$files = [];
|
||||
/** @var SubmissionFile $file */
|
||||
foreach ($this->files as $file) {
|
||||
if (!isset($this->reviewAssignments[$file->getData('assocId')])) {
|
||||
throw new Exception('Tried to add review file attachment from unknown review assignment.');
|
||||
}
|
||||
$files[] = [
|
||||
'id' => $file->getId(),
|
||||
'name' => $file->getData('name'),
|
||||
'documentType' => Services::get('file')->getDocumentType($file->getData('documentType')),
|
||||
'reviewerName' => $this->reviewAssignments[$file->getData('assocId')]->getReviewerFullName(),
|
||||
'url' => $request->getDispatcher()->url(
|
||||
$request,
|
||||
Application::ROUTE_COMPONENT,
|
||||
$this->context->getData('urlPath'),
|
||||
'api.file.FileApiHandler',
|
||||
'downloadFile',
|
||||
null,
|
||||
[
|
||||
'submissionFileId' => $file->getId(),
|
||||
'submissionId' => $file->getData('submissionId'),
|
||||
'stageId' => Repo::submissionFile()->getWorkflowStageId($file),
|
||||
]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @file classes/components/fileAttachers/Upload.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class Upload
|
||||
*
|
||||
* @ingroup classes_controllers_form
|
||||
*
|
||||
* @brief A class to compile initial state for a FileAttacherUpload component.
|
||||
*/
|
||||
|
||||
namespace PKP\components\fileAttachers;
|
||||
|
||||
use APP\core\Application;
|
||||
use PKP\context\Context;
|
||||
|
||||
class Upload extends BaseAttacher
|
||||
{
|
||||
public string $component = 'FileAttacherUpload';
|
||||
public Context $context;
|
||||
|
||||
/**
|
||||
* Initialize this file attacher
|
||||
*
|
||||
* @param string $label The label to display for this file attacher
|
||||
* @param string $description A description of this file attacher
|
||||
* @param string $button The label for the button to activate this file attacher
|
||||
*/
|
||||
public function __construct(Context $context, string $label, string $description, string $button)
|
||||
{
|
||||
parent::__construct($label, $description, $button);
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the props for this file attacher
|
||||
*/
|
||||
public function getState(): array
|
||||
{
|
||||
$props = parent::getState();
|
||||
|
||||
$request = Application::get()->getRequest();
|
||||
$props['temporaryFilesApiUrl'] = $request->getDispatcher()->url(
|
||||
$request,
|
||||
Application::ROUTE_API,
|
||||
$this->context->getData('urlPath'),
|
||||
'temporaryFiles'
|
||||
);
|
||||
$props['dropzoneOptions'] = [
|
||||
'maxFilesize' => Application::getIntMaxFileMBs(),
|
||||
'timeout' => ini_get('max_execution_time') ? ini_get('max_execution_time') * 1000 : 0,
|
||||
'dropzoneDictDefaultMessage' => __('form.dropzone.dictDefaultMessage'),
|
||||
'dropzoneDictFallbackMessage' => __('form.dropzone.dictFallbackMessage'),
|
||||
'dropzoneDictFallbackText' => __('form.dropzone.dictFallbackText'),
|
||||
'dropzoneDictFileTooBig' => __('form.dropzone.dictFileTooBig'),
|
||||
'dropzoneDictInvalidFileType' => __('form.dropzone.dictInvalidFileType'),
|
||||
'dropzoneDictResponseError' => __('form.dropzone.dictResponseError'),
|
||||
'dropzoneDictCancelUpload' => __('form.dropzone.dictCancelUpload'),
|
||||
'dropzoneDictUploadCanceled' => __('form.dropzone.dictUploadCanceled'),
|
||||
'dropzoneDictCancelUploadConfirmation' => __('form.dropzone.dictCancelUploadConfirmation'),
|
||||
'dropzoneDictRemoveFile' => __('form.dropzone.dictRemoveFile'),
|
||||
'dropzoneDictMaxFilesExceeded' => __('form.dropzone.dictMaxFilesExceeded'),
|
||||
];
|
||||
$props['addFilesLabel'] = __('common.addFiles');
|
||||
$props['attachFilesLabel'] = __('common.attachFiles');
|
||||
$props['dragAndDropMessage'] = __('common.dragAndDropHere');
|
||||
$props['dragAndDropOrUploadMessage'] = __('common.orUploadFile');
|
||||
$props['backLabel'] = __('common.back');
|
||||
$props['removeItemLabel'] = __('common.removeItem');
|
||||
|
||||
return $props;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user