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,104 @@
<?php
/**
* @file controllers/grid/issues/form/IssueAccessForm.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 IssueAccessForm
*
* @ingroup controllers_grid_issues_form
*
* @see Issue
*
* @brief Form to edit an issue's access settings
*/
namespace APP\controllers\grid\issues\form;
use APP\facades\Repo;
use APP\issue\Issue;
use APP\template\TemplateManager;
use PKP\form\Form;
use PKP\plugins\Hook;
class IssueAccessForm extends Form
{
/** @var Issue current issue */
public $_issue;
/**
* Constructor.
*
* @param Issue $issue
*/
public function __construct($issue)
{
parent::__construct('controllers/grid/issues/form/issueAccessForm.tpl');
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
$this->_issue = $issue;
}
/**
* @copydoc Form::fetch()
*
* @param null|mixed $template
*/
public function fetch($request, $template = null, $display = false)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'accessOptions' => [
Issue::ISSUE_ACCESS_OPEN => 'editor.issues.openAccess',
Issue::ISSUE_ACCESS_SUBSCRIPTION => 'editor.issues.subscription',
],
'issueId' => $this->_issue->getId(),
]);
return parent::fetch($request, $template, $display);
}
/**
* Initialize form data from current issue.
*/
public function initData()
{
$this->_data = [
'accessStatus' => $this->_issue->getAccessStatus(),
'openAccessDate' => $this->_issue->getOpenAccessDate(),
];
parent::initData();
}
/**
* Assign form data to user-submitted data.
*/
public function readInputData()
{
$this->readUserVars([
'accessStatus',
'openAccessDate',
]);
}
/**
* @copydoc Form::execute()
*
* @return int Issue ID for created/updated issue
*/
public function execute(...$functionArgs)
{
$this->_issue->setAccessStatus($this->getData('accessStatus') ? $this->getData('accessStatus') : Issue::ISSUE_ACCESS_OPEN);
if ($openAccessDate = $this->getData('openAccessDate')) {
$this->_issue->setOpenAccessDate($openAccessDate);
} else {
$this->_issue->setOpenAccessDate(null);
}
Hook::call('IssueAccessForm::execute', [$this, $this->_issue]);
Repo::issue()->edit($this->_issue, []);
parent::execute(...$functionArgs);
}
}
+281
View File
@@ -0,0 +1,281 @@
<?php
/**
* @file controllers/grid/issues/form/IssueForm.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 IssueForm
*
* @ingroup controllers_grid_issues_form
*
* @see Issue
*
* @brief Form to create or edit an issue
*/
namespace APP\controllers\grid\issues\form;
use APP\core\Application;
use APP\facades\Repo;
use APP\file\PublicFileManager;
use APP\issue\Issue;
use APP\template\TemplateManager;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\file\TemporaryFileDAO;
use PKP\form\Form;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\RemoteActionConfirmationModal;
class IssueForm extends Form
{
/** @var Issue current issue */
public $issue;
/**
* Constructor.
*
* @param Issue $issue (optional)
*/
public function __construct($issue = null)
{
parent::__construct('controllers/grid/issues/form/issueForm.tpl');
$form = $this;
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'volume', 'optional', 'editor.issues.volumeRequired', '/^[0-9]+$/i'));
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'showVolume', 'optional', 'editor.issues.volumeRequired', function ($showVolume) use ($form) {
return !$showVolume || $form->getData('volume') ? true : false;
}));
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'showNumber', 'optional', 'editor.issues.numberRequired', function ($showNumber) use ($form) {
return !$showNumber || $form->getData('number') ? true : false;
}));
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'showYear', 'optional', 'editor.issues.yearRequired', function ($showYear) use ($form) {
return !$showYear || $form->getData('year') ? true : false;
}));
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'showTitle', 'optional', 'editor.issues.titleRequired', function ($showTitle) use ($form) {
return !$showTitle || implode('', $form->getData('title')) != '' ? true : false;
}));
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
$this->issue = $issue;
}
/**
* @copydoc Form::fetch()
*
* @param null|mixed $template
*/
public function fetch($request, $template = null, $display = false)
{
if ($this->issue) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'issue' => $this->issue,
'issueId' => $this->issue->getId(),
]);
// Cover image delete link action
if ($coverImage = $this->issue->getCoverImage(Locale::getLocale())) {
$templateMgr->assign(
'deleteCoverImageLinkAction',
new LinkAction(
'deleteCoverImage',
new RemoteActionConfirmationModal(
$request->getSession(),
__('common.confirmDelete'),
null,
$request->getRouter()->url(
$request,
null,
null,
'deleteCoverImage',
null,
[
'coverImage' => $coverImage,
'issueId' => $this->issue->getId(),
]
),
'modal_delete'
),
__('common.delete'),
null
)
);
}
}
return parent::fetch($request, $template, $display);
}
/**
* @copydoc Form::validate()
*/
public function validate($callHooks = true)
{
if ($temporaryFileId = $this->getData('temporaryFileId')) {
$request = Application::get()->getRequest();
$user = $request->getUser();
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); /** @var TemporaryFileDAO $temporaryFileDao */
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
$publicFileManager = new PublicFileManager();
if (!$publicFileManager->getImageExtension($temporaryFile->getFileType())) {
$this->addError('coverImage', __('editor.issues.invalidCoverImageFormat'));
}
}
// Check if urlPath is already being used
if (strlen((string) $this->getData('urlPath'))) {
if (ctype_digit((string) $this->getData('urlPath'))) {
$this->addError('urlPath', __('publication.urlPath.numberInvalid'));
$this->addErrorField('urlPath');
} else {
$issue = Repo::issue()->getByBestId($this->getData('urlPath'), Application::get()->getRequest()->getContext()->getId());
if ($issue && $this->issue?->getId() !== $issue->getId()) {
$this->addError('urlPath', __('publication.urlPath.duplicate'));
$this->addErrorField('urlPath');
}
}
}
return parent::validate($callHooks);
}
/**
* @copydoc Form::initData()
*/
public function initData()
{
if (isset($this->issue)) {
$locale = Locale::getLocale();
$this->_data = [
'title' => $this->issue->getTitle(null), // Localized
'volume' => $this->issue->getVolume(),
'number' => $this->issue->getNumber(),
'year' => $this->issue->getYear(),
'datePublished' => $this->issue->getDatePublished(),
'description' => $this->issue->getDescription(null), // Localized
'showVolume' => $this->issue->getShowVolume(),
'showNumber' => $this->issue->getShowNumber(),
'showYear' => $this->issue->getShowYear(),
'showTitle' => $this->issue->getShowTitle(),
'coverImage' => $this->issue->getCoverImage($locale),
'coverImageAltText' => $this->issue->getCoverImageAltText($locale),
'urlPath' => $this->issue->getData('urlPath'),
];
parent::initData();
} else {
$this->_data = [
'showVolume' => 1,
'showNumber' => 1,
'showYear' => 1,
'showTitle' => 1,
];
}
}
/**
* Assign form data to user-submitted data.
*/
public function readInputData()
{
$this->readUserVars([
'title',
'volume',
'number',
'year',
'description',
'showVolume',
'showNumber',
'showYear',
'showTitle',
'temporaryFileId',
'coverImageAltText',
'datePublished',
'urlPath',
]);
$form = $this;
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'issueForm', 'required', 'editor.issues.issueIdentificationRequired', function () use ($form) {
return $form->getData('showVolume') || $form->getData('showNumber') || $form->getData('showYear') || $form->getData('showTitle');
}));
}
/**
* Save issue settings.
*/
public function execute(...$functionArgs)
{
$request = Application::get()->getRequest();
$journal = $request->getJournal();
if ($this->issue) {
$isNewIssue = false;
$issue = $this->issue;
} else {
$issue = Repo::issue()->newDataObject();
$this->issue = $issue;
switch ($journal->getData('publishingMode')) {
case \APP\journal\Journal::PUBLISHING_MODE_SUBSCRIPTION:
case \APP\journal\Journal::PUBLISHING_MODE_NONE:
$issue->setAccessStatus(Issue::ISSUE_ACCESS_SUBSCRIPTION);
break;
case \APP\journal\Journal::PUBLISHING_MODE_OPEN:
default:
$issue->setAccessStatus(Issue::ISSUE_ACCESS_OPEN);
break;
}
$isNewIssue = true;
}
$volume = $this->getData('volume');
$number = $this->getData('number');
$year = $this->getData('year');
$issue->setJournalId($journal->getId());
$issue->setTitle($this->getData('title'), null); // Localized
$issue->setVolume(empty($volume) ? null : $volume);
$issue->setNumber(empty($number) ? null : $number);
$issue->setYear(empty($year) ? null : $year);
if (!$isNewIssue) {
$issue->setDatePublished($this->getData('datePublished'));
}
$issue->setDescription($this->getData('description'), null); // Localized
$issue->setShowVolume((int) $this->getData('showVolume'));
$issue->setShowNumber((int) $this->getData('showNumber'));
$issue->setShowYear((int) $this->getData('showYear'));
$issue->setShowTitle((int) $this->getData('showTitle'));
$issue->setData('urlPath', strlen($urlPath = (string) $this->getData('urlPath')) ? $urlPath : null);
// If it is a new issue, first insert it, then update the cover
// because the cover name needs an issue id.
if ($isNewIssue) {
$issue->setPublished(0);
Repo::issue()->add($issue);
}
$locale = Locale::getLocale();
// Copy an uploaded cover file for the issue, if there is one.
if ($temporaryFileId = $this->getData('temporaryFileId')) {
$user = $request->getUser();
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); /** @var TemporaryFileDAO $temporaryFileDao */
$temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId());
$publicFileManager = new PublicFileManager();
$newFileName = 'cover_issue_' . $issue->getId() . '_' . $locale . $publicFileManager->getImageExtension($temporaryFile->getFileType());
$journal = $request->getJournal();
$publicFileManager->copyContextFile($journal->getId(), $temporaryFile->getFilePath(), $newFileName);
$issue->setCoverImage($newFileName, $locale);
Repo::issue()->edit($issue, []);
}
$issue->setCoverImageAltText($this->getData('coverImageAltText'), $locale);
parent::execute(...$functionArgs);
Repo::issue()->edit($issue, []);
}
}
@@ -0,0 +1,237 @@
<?php
/**
* @file controllers/grid/issues/form/IssueGalleyForm.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 IssueGalleyForm
*
* @ingroup issue_galley
*
* @see IssueGalley
*
* @brief Issue galley editing form.
*/
namespace APP\controllers\grid\issues\form;
use APP\core\Application;
use APP\core\Request;
use APP\file\IssueFileManager;
use APP\issue\Issue;
use APP\issue\IssueGalley;
use APP\issue\IssueGalleyDAO;
use APP\journal\JournalDAO;
use APP\template\TemplateManager;
use PKP\db\DAORegistry;
use PKP\file\TemporaryFileDAO;
use PKP\form\Form;
class IssueGalleyForm extends Form
{
/** @var Issue the issue the galley belongs to */
public $_issue = null;
/** @var IssueGalley current galley */
public $_issueGalley = null;
/**
* Constructor.
*
* @param Request $request
* @param Issue $issue
* @param IssueGalley $issueGalley (optional)
*/
public function __construct($request, $issue, $issueGalley = null)
{
parent::__construct('controllers/grid/issueGalleys/form/issueGalleyForm.tpl');
$this->_issue = $issue;
$this->_issueGalley = $issueGalley;
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'label', 'required', 'editor.issues.galleyLabelRequired'));
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
// Ensure a locale is provided and valid
$journal = $request->getJournal();
$this->addCheck(new \PKP\form\validation\FormValidatorCustom(
$this,
'galleyLocale',
'required',
'editor.issues.galleyLocaleRequired',
function ($galleyLocale) use ($journal) {
return in_array($galleyLocale, $journal->getSupportedFormLocales());
}
));
if (!$issueGalley) {
// A file must be uploaded with a newly-created issue galley.
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'temporaryFileId', 'required', 'form.fileRequired'));
}
}
/**
* @copydoc Form::fetch()
*
* @param Request $request
* @param null|mixed $template
*/
public function fetch($request, $template = null, $display = false)
{
$journal = $request->getJournal();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'issueId' => $this->_issue->getId(),
'supportedLocales' => $journal->getSupportedLocaleNames(),
'enablePublisherId' => in_array('issueGalley', (array) $request->getContext()->getData('enablePublisherId')),
]);
if ($this->_issueGalley) {
$templateMgr->assign([
'issueGalleyId' => $this->_issueGalley->getId(),
'issueGalley' => $this->_issueGalley,
]);
}
return parent::fetch($request, $template, $display);
}
/**
* @copydoc Form::validate
*/
public function validate($callHooks = true)
{
// Check if public galley ID is already being used
$request = Application::get()->getRequest();
$journal = $request->getJournal();
$journalDao = DAORegistry::getDAO('JournalDAO'); /** @var JournalDAO $journalDao */
$publicGalleyId = $this->getData('publicGalleyId');
if ($publicGalleyId) {
if (ctype_digit((string) $publicGalleyId)) {
$this->addError('publicGalleyId', __('editor.publicIdentificationNumericNotAllowed', ['publicIdentifier' => $publicGalleyId]));
$this->addErrorField('publicGalleyId');
} elseif ($journalDao->anyPubIdExists($journal->getId(), 'publisher-id', $publicGalleyId, Application::ASSOC_TYPE_ISSUE_GALLEY, $this->_issueGalley ? $this->_issueGalley->getId() : null, true)) {
$this->addError('publicGalleyId', __('editor.publicIdentificationExistsForTheSameType', ['publicIdentifier' => $publicGalleyId]));
$this->addErrorField('publicGalleyId');
}
}
if (strlen((string) $this->getData('urlPath'))) {
if (ctype_digit((string) $this->getData('urlPath'))) {
$this->addError('urlPath', __('publication.urlPath.numberInvalid'));
$this->addErrorField('urlPath');
} else {
$issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO'); /** @var IssueGalleyDAO $issueGalleyDao */
$issueGalley = $issueGalleyDao->getByBestId($this->getData('urlPath'), $this->_issue->getId());
if ($issueGalley && $this->_issueGalley?->getId() !== $issueGalley->getId()) {
$this->addError('urlPath', __('publication.urlPath.duplicate'));
$this->addErrorField('urlPath');
}
}
}
return parent::validate($callHooks);
}
/**
* Initialize form data from current galley (if applicable).
*/
public function initData()
{
if ($this->_issueGalley) {
$this->_data = [
'label' => $this->_issueGalley->getLabel(),
'publicGalleyId' => $this->_issueGalley->getStoredPubId('publisher-id'),
'galleyLocale' => $this->_issueGalley->getLocale(),
'urlPath' => $this->_issueGalley->getData('urlPath'),
];
} else {
$this->_data = [];
}
}
/**
* Assign form data to user-submitted data.
*/
public function readInputData()
{
$this->readUserVars(
[
'label',
'publicGalleyId',
'galleyLocale',
'temporaryFileId',
'urlPath',
]
);
}
/**
* @copydoc Form::execute()
*/
public function execute(...$functionArgs)
{
$issueFileManager = new IssueFileManager($this->_issue->getId());
$request = Application::get()->getRequest();
$user = $request->getUser();
$issueGalley = $this->_issueGalley;
$issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO'); /** @var IssueGalleyDAO $issueGalleyDao */
// If a temporary file ID was specified (i.e. an upload occurred), get the file for later.
$temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); /** @var TemporaryFileDAO $temporaryFileDao */
$temporaryFile = $temporaryFileDao->getTemporaryFile($this->getData('temporaryFileId'), $user->getId());
parent::execute(...$functionArgs);
if ($issueGalley) {
// Update an existing galley
$oldFileId = null;
if ($temporaryFile) {
$oldFileId = $issueGalley->getFileId();
// Upload new file
$issueFile = $issueFileManager->fromTemporaryFile($temporaryFile);
$issueGalley->setFileId($issueFile->getId());
}
$issueGalley->setLabel($this->getData('label'));
$issueGalley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
$issueGalley->setLocale($this->getData('galleyLocale'));
$issueGalley->setData('urlPath', strlen($urlPath = (string) $this->getData('urlPath')) ? $urlPath : null);
// Update galley in the db
$issueGalleyDao->updateObject($issueGalley);
if ($oldFileId) {
// If the galley previously had a file, delete it
$issueFileManager->deleteById($oldFileId);
}
} else {
// Create a new galley
$issueGalleyFile = $issueFileManager->fromTemporaryFile($temporaryFile);
$issueGalley = $issueGalleyDao->newDataObject();
$issueGalley->setIssueId($this->_issue->getId());
$issueGalley->setFileId($issueGalleyFile->getId());
$issueGalley->setData('urlPath', $this->getData('urlPath'));
$issueGalley->setLabel($this->getData('label'));
$issueGalley->setLocale($this->getData('galleyLocale'));
$issueGalley->setStoredPubId('publisher-id', $this->getData('publicGalleyId'));
// Insert new galley into the db
$issueGalleyDao->insertObject($issueGalley);
$this->_issueGalley = $issueGalley;
}
return $this->_issueGalley->getId();
}
}