first commit
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/grid/articleGalleys/ArticleGalleyGridCellProvider.php
|
||||
*
|
||||
* Copyright (c) 2016-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ArticleGalleyGridCellProvider
|
||||
*
|
||||
* @ingroup controllers_grid_articleGalleys
|
||||
*
|
||||
* @brief Base class for a cell provider for article galleys.
|
||||
*/
|
||||
|
||||
namespace APP\controllers\grid\articleGalleys;
|
||||
|
||||
use APP\facades\Repo;
|
||||
use APP\publication\Publication;
|
||||
use APP\submission\Submission;
|
||||
use PKP\controllers\api\file\linkAction\DownloadFileLinkAction;
|
||||
use PKP\controllers\grid\DataObjectGridCellProvider;
|
||||
use PKP\controllers\grid\GridHandler;
|
||||
use PKP\galley\Galley;
|
||||
|
||||
class ArticleGalleyGridCellProvider extends DataObjectGridCellProvider
|
||||
{
|
||||
/** @var Submission */
|
||||
public $_submission;
|
||||
|
||||
/** @var Publication */
|
||||
public $_publication;
|
||||
|
||||
public $_isEditable;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Submission $submission
|
||||
*/
|
||||
public function __construct($submission, $publication, $isEditable)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_submission = $submission;
|
||||
$this->_publication = $publication;
|
||||
$this->_isEditable = $isEditable;
|
||||
}
|
||||
|
||||
//
|
||||
// Template methods from GridCellProvider
|
||||
//
|
||||
/**
|
||||
* @copydoc GridCellProvider::getTemplateVarsFromRowColumn()
|
||||
*/
|
||||
public function getTemplateVarsFromRowColumn($row, $column)
|
||||
{
|
||||
$element = $row->getData();
|
||||
$columnId = $column->getId();
|
||||
assert($element instanceof \PKP\core\DataObject && !empty($columnId));
|
||||
/** @var Galley $element */
|
||||
switch ($columnId) {
|
||||
case 'label':
|
||||
return [
|
||||
'label' => !$element->getRemoteUrl() && $element->getData('submissionFileId') ? '' : $element->getLabel()
|
||||
];
|
||||
default: assert(false);
|
||||
}
|
||||
return parent::getTemplateVarsFromRowColumn($row, $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request arguments.
|
||||
*
|
||||
* @param \PKP\controllers\grid\GridRow $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestArgs($row)
|
||||
{
|
||||
return [
|
||||
'submissionId' => $this->_submission->getId(),
|
||||
'publicationId' => $this->_publication->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridCellProvider::getCellActions()
|
||||
*/
|
||||
public function getCellActions($request, $row, $column, $position = GridHandler::GRID_ACTION_POSITION_DEFAULT)
|
||||
{
|
||||
switch ($column->getId()) {
|
||||
case 'label':
|
||||
$element = $row->getData();
|
||||
if ($element->getRemoteUrl() || !$element->getData('submissionFileId')) {
|
||||
break;
|
||||
}
|
||||
|
||||
$submissionFile = Repo::submissionFile()
|
||||
->get($element->getData('submissionFileId'));
|
||||
return [new DownloadFileLinkAction($request, $submissionFile, WORKFLOW_STAGE_ID_PRODUCTION, $element->getLabel())];
|
||||
}
|
||||
return parent::getCellActions($request, $row, $column, $position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,481 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/grid/articleGalleys/ArticleGalleyGridHandler.php
|
||||
*
|
||||
* Copyright (c) 2016-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ArticleGalleyGridHandler
|
||||
*
|
||||
* @ingroup controllers_grid_articleGalleys
|
||||
*
|
||||
* @brief Handle article galley grid requests.
|
||||
*/
|
||||
|
||||
namespace APP\controllers\grid\articleGalleys;
|
||||
|
||||
use APP\controllers\grid\articleGalleys\form\ArticleGalleyForm;
|
||||
use APP\controllers\tab\pubIds\form\PublicIdentifiersForm;
|
||||
use APP\core\Application;
|
||||
use APP\core\Request;
|
||||
use APP\facades\Repo;
|
||||
use APP\notification\NotificationManager;
|
||||
use APP\publication\Publication;
|
||||
use APP\submission\Submission;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\controllers\grid\feature\OrderGridItemsFeature;
|
||||
use PKP\controllers\grid\GridColumn;
|
||||
use PKP\controllers\grid\GridHandler;
|
||||
use PKP\core\JSONMessage;
|
||||
use PKP\core\PKPApplication;
|
||||
use PKP\db\DAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\galley\Galley;
|
||||
use PKP\linkAction\LinkAction;
|
||||
use PKP\linkAction\request\AjaxModal;
|
||||
use PKP\notification\NotificationDAO;
|
||||
use PKP\notification\PKPNotification;
|
||||
use PKP\plugins\PluginRegistry;
|
||||
use PKP\security\authorization\internal\RepresentationRequiredPolicy;
|
||||
use PKP\security\authorization\PublicationAccessPolicy;
|
||||
use PKP\security\authorization\WorkflowStageAccessPolicy;
|
||||
use PKP\security\Role;
|
||||
use PKP\submission\PKPSubmission;
|
||||
|
||||
class ArticleGalleyGridHandler extends GridHandler
|
||||
{
|
||||
/** @var Request */
|
||||
public $_request;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->addRoleAssignment(
|
||||
[Role::ROLE_ID_AUTHOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT],
|
||||
['fetchGrid', 'fetchRow']
|
||||
);
|
||||
$this->addRoleAssignment(
|
||||
[Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT],
|
||||
['addGalley', 'editGalley', 'editGalleyTab', 'updateGalley', 'deleteGalley', 'identifiers', 'updateIdentifiers', 'clearPubId', 'saveSequence']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Getters/Setters
|
||||
//
|
||||
/**
|
||||
* Get the authorized submission.
|
||||
*
|
||||
* @return Submission
|
||||
*/
|
||||
public function getSubmission()
|
||||
{
|
||||
return $this->getAuthorizedContextObject(Application::ASSOC_TYPE_SUBMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorized publication.
|
||||
*
|
||||
* @return Publication
|
||||
*/
|
||||
public function getPublication()
|
||||
{
|
||||
return $this->getAuthorizedContextObject(Application::ASSOC_TYPE_PUBLICATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorized galley.
|
||||
*
|
||||
* @return Galley
|
||||
*/
|
||||
public function getGalley()
|
||||
{
|
||||
return $this->getAuthorizedContextObject(Application::ASSOC_TYPE_REPRESENTATION);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Overridden methods from PKPHandler.
|
||||
//
|
||||
/**
|
||||
* @see GridHandler::getJSHandler()
|
||||
*/
|
||||
public function getJSHandler()
|
||||
{
|
||||
return '$.pkp.controllers.grid.articleGalleys.ArticleGalleyGridHandler';
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc PKPHandler::authorize()
|
||||
*/
|
||||
public function authorize($request, &$args, $roleAssignments)
|
||||
{
|
||||
$this->_request = $request;
|
||||
|
||||
$this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', WORKFLOW_STAGE_ID_PRODUCTION));
|
||||
|
||||
$this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
|
||||
|
||||
if ($request->getUserVar('representationId')) {
|
||||
$this->addPolicy(new RepresentationRequiredPolicy($request, $args));
|
||||
}
|
||||
|
||||
return parent::authorize($request, $args, $roleAssignments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridHandler::initialize()
|
||||
*
|
||||
* @param null|mixed $args
|
||||
*/
|
||||
public function initialize($request, $args = null)
|
||||
{
|
||||
parent::initialize($request, $args);
|
||||
$this->setTitle('submission.layout.galleys');
|
||||
|
||||
$cellProvider = new ArticleGalleyGridCellProvider($this->getSubmission(), $this->getPublication(), $this->canEdit());
|
||||
|
||||
// Columns
|
||||
$this->addColumn(new GridColumn(
|
||||
'label',
|
||||
'common.name',
|
||||
null,
|
||||
null,
|
||||
$cellProvider
|
||||
));
|
||||
|
||||
if ($this->canEdit()) {
|
||||
$this->addAction(new LinkAction(
|
||||
'addGalley',
|
||||
new AjaxModal(
|
||||
$request->getRouter()->url($request, null, null, 'addGalley', null, $this->getRequestArgs()),
|
||||
__('submission.layout.newGalley'),
|
||||
'modal_add_item'
|
||||
),
|
||||
__('grid.action.addGalley'),
|
||||
'add_item'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Overridden methods from GridHandler
|
||||
//
|
||||
/**
|
||||
* @copydoc GridHandler::initFeatures()
|
||||
*/
|
||||
public function initFeatures($request, $args)
|
||||
{
|
||||
if ($this->canEdit()) {
|
||||
return [new OrderGridItemsFeature()];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridHandler::getDataElementSequence()
|
||||
*/
|
||||
public function getDataElementSequence($row)
|
||||
{
|
||||
return $row->getSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridHandler::setDataElementSequence()
|
||||
*/
|
||||
public function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
|
||||
{
|
||||
$galley = Repo::galley()->get((int) $rowId);
|
||||
Repo::galley()->edit($galley, ['seq' => $newSequence]);
|
||||
}
|
||||
|
||||
//
|
||||
// Overridden methods from GridHandler
|
||||
//
|
||||
/**
|
||||
* @copydoc GridHandler::getRowInstance()
|
||||
*
|
||||
* @return ArticleGalleyGridRow
|
||||
*/
|
||||
public function getRowInstance()
|
||||
{
|
||||
return new ArticleGalleyGridRow(
|
||||
$this->getSubmission(),
|
||||
$this->getPublication(),
|
||||
$this->canEdit()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the arguments that will identify the data in the grid.
|
||||
* Overridden by child grids.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestArgs()
|
||||
{
|
||||
return [
|
||||
'submissionId' => $this->getSubmission()->getId(),
|
||||
'publicationId' => $this->getPublication()->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridHandler::loadData()
|
||||
*
|
||||
* @param null|mixed $filter
|
||||
*/
|
||||
public function loadData($request, $filter = null)
|
||||
{
|
||||
return Repo::galley()->getCollector()
|
||||
->filterByPublicationIds([$this->getPublication()->getId()])
|
||||
->getMany();
|
||||
}
|
||||
|
||||
//
|
||||
// Public Galley Grid Actions
|
||||
//
|
||||
/**
|
||||
* Edit article galley pub ids
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function identifiers($args, $request)
|
||||
{
|
||||
$representation = $this->getGalley();
|
||||
$form = new PublicIdentifiersForm($representation, null, null, $this->canEdit());
|
||||
$form->initData();
|
||||
return new JSONMessage(true, $form->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update article galley pub ids
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function updateIdentifiers($args, $request)
|
||||
{
|
||||
$representation = $this->getGalley();
|
||||
$form = new PublicIdentifiersForm($representation, null, array_merge($this->getRequestArgs(), ['representationId' => $representation->getId()]), $this->canEdit());
|
||||
$form->readInputData();
|
||||
if ($form->validate()) {
|
||||
$form->execute();
|
||||
return DAO::getDataChangedEvent();
|
||||
} else {
|
||||
return new JSONMessage(true, $form->fetch($request));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear galley pub id
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function clearPubId($args, $request)
|
||||
{
|
||||
if (!$request->checkCSRF()) {
|
||||
return new JSONMessage(false);
|
||||
}
|
||||
|
||||
$representation = $this->getGalley();
|
||||
$form = new PublicIdentifiersForm($representation, null, null, $this->canEdit());
|
||||
$form->clearPubId($request->getUserVar('pubIdPlugIn'));
|
||||
return new JSONMessage(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a galley
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function addGalley($args, $request)
|
||||
{
|
||||
$galleyForm = new ArticleGalleyForm(
|
||||
$request,
|
||||
$this->getSubmission(),
|
||||
$this->getPublication()
|
||||
);
|
||||
$galleyForm->initData();
|
||||
return new JSONMessage(true, $galleyForm->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a galley.
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function deleteGalley($args, $request)
|
||||
{
|
||||
$galley = $this->getGalley();
|
||||
if (!$galley || !$request->checkCSRF()) {
|
||||
return new JSONMessage(false);
|
||||
}
|
||||
Repo::galley()->delete($galley);
|
||||
|
||||
$notificationDao = DAORegistry::getDAO('NotificationDAO'); /** @var NotificationDAO $notificationDao */
|
||||
$notificationDao->deleteByAssoc(Application::ASSOC_TYPE_REPRESENTATION, $galley->getId());
|
||||
|
||||
if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
|
||||
$this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
|
||||
$notificationMgr = new NotificationManager();
|
||||
$notificationMgr->updateNotification(
|
||||
$request,
|
||||
[PKPNotification::NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, PKPNotification::NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS],
|
||||
null,
|
||||
Application::ASSOC_TYPE_SUBMISSION,
|
||||
$this->getSubmission()->getId()
|
||||
);
|
||||
}
|
||||
|
||||
return DAO::getDataChangedEvent($galley->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a galley metadata modal
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function editGalley($args, $request)
|
||||
{
|
||||
$galley = $this->getGalley();
|
||||
|
||||
// Check if this is a remote galley
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$templateMgr->assign([
|
||||
'submissionId' => $this->getSubmission()->getId(),
|
||||
'publicationId' => $this->getPublication()->getId(),
|
||||
'representationId' => $galley->getId(),
|
||||
]);
|
||||
$publisherIdEnabled = in_array('galley', (array) $request->getContext()->getData('enablePublisherId'));
|
||||
$pubIdsEnabled = false;
|
||||
$pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $request->getContext()->getId());
|
||||
foreach ($pubIdPlugins as $pubIdPlugin) {
|
||||
if ($pubIdPlugin->isObjectTypeEnabled('Representation', $request->getContext()->getId())) {
|
||||
$pubIdsEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($publisherIdEnabled || $pubIdsEnabled) {
|
||||
$templateMgr->assign('enableIdentifiers', true);
|
||||
}
|
||||
return new JSONMessage(true, $templateMgr->fetch('controllers/grid/articleGalleys/editFormat.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a galley
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function editGalleyTab($args, $request)
|
||||
{
|
||||
// Form handling
|
||||
$galleyForm = new ArticleGalleyForm(
|
||||
$request,
|
||||
$this->getSubmission(),
|
||||
$this->getPublication(),
|
||||
$this->getGalley(),
|
||||
$this->canEdit()
|
||||
);
|
||||
$galleyForm->initData();
|
||||
return new JSONMessage(true, $galleyForm->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a galley
|
||||
*
|
||||
* @param array $args
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JSONMessage JSON object
|
||||
*/
|
||||
public function updateGalley($args, $request)
|
||||
{
|
||||
$galley = $this->getGalley();
|
||||
|
||||
$galleyForm = new ArticleGalleyForm($request, $this->getSubmission(), $this->getPublication(), $galley, $this->canEdit());
|
||||
$galleyForm->readInputData();
|
||||
|
||||
if ($galleyForm->validate()) {
|
||||
$galley = $galleyForm->execute();
|
||||
|
||||
if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
|
||||
$this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
|
||||
$notificationMgr = new NotificationManager();
|
||||
$notificationMgr->updateNotification(
|
||||
$request,
|
||||
[PKPNotification::NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, PKPNotification::NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS],
|
||||
null,
|
||||
Application::ASSOC_TYPE_SUBMISSION,
|
||||
$this->getSubmission()->getId()
|
||||
);
|
||||
}
|
||||
|
||||
return DAO::getDataChangedEvent($galley->getId());
|
||||
}
|
||||
return new JSONMessage(true, $galleyForm->fetch($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc GridHandler::fetchRow()
|
||||
*/
|
||||
public function fetchRow($args, $request)
|
||||
{
|
||||
$json = parent::fetchRow($args, $request);
|
||||
if ($row = $this->getRequestedRow($request, $args)) {
|
||||
$galley = $row->getData();
|
||||
if (!$galley->getRemoteUrl() && !$galley->getData('submissionFileId')) {
|
||||
$json->setEvent('uploadFile', $galley->getId());
|
||||
}
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the current user edit the galleys in this grid?
|
||||
*
|
||||
* The user must have an allowed role in one of the assigned stages.
|
||||
* If the user is not assigned, they can edit if they are an editor
|
||||
* or admin.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canEdit()
|
||||
{
|
||||
return $this->getPublication()->getData('status') !== PKPSubmission::STATUS_PUBLISHED &&
|
||||
Repo::user()->canUserAccessStage(
|
||||
WORKFLOW_STAGE_ID_PRODUCTION,
|
||||
PKPApplication::WORKFLOW_TYPE_EDITORIAL,
|
||||
$this->getAuthorizedContextObject(Application::ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES),
|
||||
$this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/grid/articleGalleys/ArticleGalleyGridRow.php
|
||||
*
|
||||
* Copyright (c) 2016-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ArticleGalleyGridRow
|
||||
*
|
||||
* @ingroup controllers_grid_articleGalleys
|
||||
*
|
||||
* @brief Representation of an article galley grid row.
|
||||
*/
|
||||
|
||||
namespace APP\controllers\grid\articleGalleys;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\publication\Publication;
|
||||
use APP\submission\Submission;
|
||||
use PKP\controllers\api\file\linkAction\AddFileLinkAction;
|
||||
use PKP\controllers\grid\GridRow;
|
||||
use PKP\linkAction\LinkAction;
|
||||
use PKP\linkAction\request\AjaxModal;
|
||||
use PKP\linkAction\request\RemoteActionConfirmationModal;
|
||||
use PKP\security\Role;
|
||||
use PKP\submissionFile\SubmissionFile;
|
||||
|
||||
class ArticleGalleyGridRow extends GridRow
|
||||
{
|
||||
/** @var Submission */
|
||||
public $_submission;
|
||||
|
||||
/** @var Publication */
|
||||
public $_publication;
|
||||
|
||||
/** @var bool */
|
||||
public $_isEditable;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Submission $submission
|
||||
* @param bool $isEditable
|
||||
*/
|
||||
public function __construct($submission, $publication, $isEditable)
|
||||
{
|
||||
$this->_submission = $submission;
|
||||
$this->_publication = $publication;
|
||||
$this->_isEditable = $isEditable;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
//
|
||||
// Overridden methods from GridRow
|
||||
//
|
||||
/**
|
||||
* @copydoc GridRow::initialize()
|
||||
*
|
||||
* @param null|mixed $template
|
||||
*/
|
||||
public function initialize($request, $template = null)
|
||||
{
|
||||
// Do the default initialization
|
||||
parent::initialize($request, $template);
|
||||
|
||||
// Is this a new row or an existing row?
|
||||
$rowId = $this->getId();
|
||||
if (!empty($rowId) && is_numeric($rowId)) {
|
||||
// Only add row actions if this is an existing row
|
||||
$router = $request->getRouter();
|
||||
$actionArgs = $this->getRequestArgs();
|
||||
$actionArgs['representationId'] = $rowId;
|
||||
|
||||
// Add row-level actions
|
||||
$this->addAction(new LinkAction(
|
||||
'editGalley',
|
||||
new AjaxModal(
|
||||
$router->url($request, null, null, 'editGalley', null, $actionArgs),
|
||||
($this->_isEditable) ? __('submission.layout.editGalley') : __('submission.layout.viewGalley'),
|
||||
'modal_edit'
|
||||
),
|
||||
($this->_isEditable) ? __('grid.action.edit') : __('grid.action.view'),
|
||||
'edit'
|
||||
));
|
||||
|
||||
if ($this->_isEditable) {
|
||||
$galley = $this->getData();
|
||||
if (!$galley->getRemoteUrl()) {
|
||||
$this->addAction(new AddFileLinkAction(
|
||||
$request,
|
||||
$this->getSubmission()->getId(),
|
||||
WORKFLOW_STAGE_ID_PRODUCTION,
|
||||
[Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT],
|
||||
SubmissionFile::SUBMISSION_FILE_PROOF,
|
||||
Application::ASSOC_TYPE_REPRESENTATION,
|
||||
$rowId,
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
$this->addAction(new LinkAction(
|
||||
'deleteGalley',
|
||||
new RemoteActionConfirmationModal(
|
||||
$request->getSession(),
|
||||
__('common.confirmDelete'),
|
||||
__('grid.action.delete'),
|
||||
$router->url($request, null, null, 'deleteGalley', null, $actionArgs),
|
||||
'modal_delete'
|
||||
),
|
||||
__('grid.action.delete'),
|
||||
'delete'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the submission for this row (already authorized)
|
||||
*
|
||||
* @return Submission
|
||||
*/
|
||||
public function getSubmission()
|
||||
{
|
||||
return $this->_submission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the publication for this row (already authorized)
|
||||
*
|
||||
* @return Publication
|
||||
*/
|
||||
public function getPublication()
|
||||
{
|
||||
return $this->_publication;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base arguments that will identify the data in the grid.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestArgs()
|
||||
{
|
||||
return [
|
||||
'submissionId' => $this->getSubmission()->getId(),
|
||||
'publicationId' => $this->getPublication()->getId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file controllers/grid/articleGalleys/form/ArticleGalleyForm.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 ArticleGalleyForm
|
||||
*
|
||||
* @ingroup controllers_grid_articleGalleys_form
|
||||
*
|
||||
* @see Galley
|
||||
*
|
||||
* @brief Article galley editing form.
|
||||
*/
|
||||
|
||||
namespace APP\controllers\grid\articleGalleys\form;
|
||||
|
||||
use APP\core\Request;
|
||||
use APP\facades\Repo;
|
||||
use APP\publication\Publication;
|
||||
use APP\submission\Submission;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\form\Form;
|
||||
use PKP\galley\Galley;
|
||||
|
||||
class ArticleGalleyForm extends Form
|
||||
{
|
||||
/** @var Submission */
|
||||
public $_submission = null;
|
||||
|
||||
/** @var Publication */
|
||||
public $_publication = null;
|
||||
|
||||
/** @var Galley current galley */
|
||||
public $_articleGalley = null;
|
||||
|
||||
public bool $_isEditable = true;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Submission $submission
|
||||
* @param Publication $publication
|
||||
* @param Galley $articleGalley (optional)
|
||||
* @param bool $isEditable (optional, default = true)
|
||||
*/
|
||||
public function __construct($request, $submission, $publication, $articleGalley = null, bool $isEditable = true)
|
||||
{
|
||||
parent::__construct('controllers/grid/articleGalleys/form/articleGalleyForm.tpl');
|
||||
$this->_submission = $submission;
|
||||
$this->_publication = $publication;
|
||||
$this->_articleGalley = $articleGalley;
|
||||
$this->_isEditable = $isEditable;
|
||||
|
||||
$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\FormValidator(
|
||||
$this,
|
||||
'locale',
|
||||
'required',
|
||||
'editor.issues.galleyLocaleRequired'
|
||||
),
|
||||
function ($locale) use ($journal) {
|
||||
return in_array($locale, $journal->getSupportedSubmissionLocaleNames());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::fetch()
|
||||
*
|
||||
* @param null|mixed $template
|
||||
*/
|
||||
public function fetch($request, $template = null, $display = false)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
if ($this->_articleGalley) {
|
||||
$articleGalleyFile = $this->_articleGalley->getFile();
|
||||
$templateMgr->assign([
|
||||
'representationId' => $this->_articleGalley->getId(),
|
||||
'articleGalley' => $this->_articleGalley,
|
||||
'articleGalleyFile' => $articleGalleyFile,
|
||||
'supportsDependentFiles' => $articleGalleyFile ? Repo::submissionFile()->supportsDependentFiles($articleGalleyFile) : null,
|
||||
]);
|
||||
}
|
||||
$context = $request->getContext();
|
||||
$templateMgr->assign([
|
||||
'supportedLocales' => $context->getSupportedSubmissionLocaleNames(),
|
||||
'submissionId' => $this->_submission->getId(),
|
||||
'publicationId' => $this->_publication->getId(),
|
||||
'formDisabled' => !$this->_isEditable
|
||||
]);
|
||||
|
||||
return parent::fetch($request, $template, $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::validate
|
||||
*/
|
||||
public function validate($callHooks = true)
|
||||
{
|
||||
// Validate the urlPath
|
||||
if (strlen((string) $this->getData('urlPath'))) {
|
||||
if (ctype_digit((string) $this->getData('urlPath'))) {
|
||||
$this->addError('urlPath', __('publication.urlPath.numberInvalid'));
|
||||
$this->addErrorField('urlPath');
|
||||
} else {
|
||||
$existingGalley = Repo::galley()->getByUrlPath((string) $this->getData('urlPath'), $this->_publication);
|
||||
if ($existingGalley && $this->_articleGalley?->getId() !== $existingGalley->getId()) {
|
||||
$this->addError('urlPath', __('publication.urlPath.duplicate'));
|
||||
$this->addErrorField('urlPath');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->_isEditable) {
|
||||
$this->addError('', __('galley.cantEditPublished'));
|
||||
}
|
||||
|
||||
return parent::validate($callHooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize form data from current galley (if applicable).
|
||||
*/
|
||||
public function initData()
|
||||
{
|
||||
if ($this->_articleGalley) {
|
||||
$this->_data = [
|
||||
'label' => $this->_articleGalley->getLabel(),
|
||||
'locale' => $this->_articleGalley->getLocale(),
|
||||
'urlPath' => $this->_articleGalley->getData('urlPath'),
|
||||
'urlRemote' => $this->_articleGalley->getData('urlRemote'),
|
||||
];
|
||||
} else {
|
||||
$this->_data = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign form data to user-submitted data.
|
||||
*/
|
||||
public function readInputData()
|
||||
{
|
||||
$this->readUserVars(
|
||||
[
|
||||
'label',
|
||||
'locale',
|
||||
'urlPath',
|
||||
'urlRemote',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes to the galley.
|
||||
*
|
||||
* @return Galley The resulting article galley.
|
||||
*/
|
||||
public function execute(...$functionArgs)
|
||||
{
|
||||
$data = [
|
||||
'publicationId' => $this->_publication->getId(),
|
||||
'label' => $this->getData('label'),
|
||||
'locale' => $this->getData('locale'),
|
||||
'urlPath' => strlen($urlPath = (string) $this->getData('urlPath')) ? $urlPath : null,
|
||||
'urlRemote' => strlen($urlRemote = (string) $this->getData('urlRemote')) ? $urlRemote : null
|
||||
];
|
||||
|
||||
if ($this->_articleGalley) {
|
||||
// Update galley in the db
|
||||
Repo::galley()->edit($this->_articleGalley, $data);
|
||||
$articleGalleyId = $this->_articleGalley->getId();
|
||||
} else {
|
||||
// Create a new galley
|
||||
$articleGalleyId = Repo::galley()->add(Repo::galley()->newDataObject($data));
|
||||
}
|
||||
|
||||
parent::execute(...$functionArgs);
|
||||
|
||||
return $this->_articleGalley = Repo::galley()->get($articleGalleyId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user