_pubObject = $pubObject; $this->_stageId = $stageId; $this->_formParams = $formParams; $this->_isEditable = $isEditable; $request = Application::get()->getRequest(); $context = $request->getContext(); $this->_contextId = $context->getId(); $this->addCheck(new \PKP\form\validation\FormValidatorPost($this)); $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); // action links for pub id reset requests $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->setLinkActions($this->getContextId(), $this, $pubObject); } /** * @copydoc Form::fetch() * * @param null|mixed $template */ public function fetch($request, $template = null, $display = false) { $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ 'pubIdPlugins' => PluginRegistry::loadCategory('pubIds', true, $this->getContextId()), 'pubObject' => $this->getPubObject(), 'stageId' => $this->getStageId(), 'formParams' => $this->getFormParams(), 'formDisabled' => !$this->_isEditable, ]); if ($this->getPubObject() instanceof Representation || $this->getPubObject() instanceof \APP\monograph\Chapter) { $publicationId = $this->getPubObject()->getData('publicationId'); $publication = Repo::publication()->get($publicationId); $templateMgr->assign([ 'submissionId' => $publication->getData('submissionId'), ]); } // consider JavaScripts $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->addJavaScripts($this->getContextId(), $request, $templateMgr); return parent::fetch($request, $template, $display); } /** * @copydoc Form::initData() */ public function initData() { $pubObject = $this->getPubObject(); $this->setData('publisherId', $pubObject->getStoredPubId('publisher-id')); $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->init($this->getContextId(), $this, $pubObject); return parent::initData(); } // // Getters // /** * Get the pub object * * @return object */ public function getPubObject() { return $this->_pubObject; } /** * Get the stage id * * @return int WORKFLOW_STAGE_ID_ */ public function getStageId() { return $this->_stageId; } /** * Get the context id * * @return int */ public function getContextId() { return $this->_contextId; } /** * Get the extra form parameters. * * @return array */ public function getFormParams() { return $this->_formParams; } // // Form methods // /** * @copydoc Form::readInputData() */ public function readInputData() { $this->readUserVars(['publisherId']); $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->readInputData($this->getContextId(), $this); } /** * @copydoc Form::validate() */ public function validate($callHooks = true) { $pubObject = $this->getPubObject(); $assocType = $this->getAssocType($pubObject); $publisherId = $this->getData('publisherId'); $pubObjectId = $pubObject->getId(); if ($assocType == Application::ASSOC_TYPE_SUBMISSION_FILE) { $pubObjectId = $pubObject->getId(); } $contextDao = Application::getContextDAO(); if ($publisherId) { if (ctype_digit((string) $publisherId)) { $this->addError('publisherId', __('editor.publicIdentificationNumericNotAllowed', ['publicIdentifier' => $publisherId])); $this->addErrorField('$publisherId'); } elseif (count(explode('/', $publisherId)) > 1) { $this->addError('publisherId', __('editor.publicIdentificationPatternNotAllowed', ['pattern' => '"/"'])); $this->addErrorField('$publisherId'); } elseif ($pubObject instanceof SubmissionFile && preg_match('/^(\d+)-(\d+)$/', $publisherId)) { $this->addError('publisherId', __('editor.publicIdentificationPatternNotAllowed', ['pattern' => '\'/^(\d+)-(\d+)$/\' i.e. \'number-number\''])); $this->addErrorField('$publisherId'); } elseif ($contextDao->anyPubIdExists($this->getContextId(), 'publisher-id', $publisherId, $assocType, $pubObjectId, true)) { $this->addError('publisherId', __('editor.publicIdentificationExistsForTheSameType', ['publicIdentifier' => $publisherId])); $this->addErrorField('$publisherId'); } } $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->validate($this->getContextId(), $this, $this->getPubObject()); if (!$this->_isEditable) { $this->addError('', __('galley.cantEditPublished')); } return parent::validate($callHooks); } /** * Store objects with pub ids. * * @copydoc Form::execute() */ public function execute(...$functionArgs) { parent::execute(...$functionArgs); $pubObject = $this->getPubObject(); $pubObject->setStoredPubId('publisher-id', $this->getData('publisherId')); $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->execute($this->getContextId(), $this, $pubObject); if ($pubObject instanceof Representation) { $representationDao = Application::getRepresentationDAO(); $representationDao->updateObject($pubObject); return; } if ($pubObject instanceof SubmissionFile) { Repo::submissionFile()->edit($pubObject, []); return; } } /** * Clear pub id. * * @param string $pubIdPlugInClassName */ public function clearPubId($pubIdPlugInClassName) { $pubIdPluginHelper = new PKPPubIdPluginHelper(); $pubIdPluginHelper->clearPubId($this->getContextId(), $pubIdPlugInClassName, $this->getPubObject()); } /** * Get assoc type of the given object. * * @param object $pubObject * * @return ?int Application::ASSOC_TYPE_ */ public function getAssocType($pubObject) { if ($pubObject instanceof Submission) { return Application::ASSOC_TYPE_SUBMISSION; } if ($pubObject instanceof Publication) { return Application::ASSOC_TYPE_PUBLICATION; } if ($pubObject instanceof Representation) { return Application::ASSOC_TYPE_REPRESENTATION; } if ($pubObject instanceof SubmissionFile) { return Application::ASSOC_TYPE_SUBMISSION_FILE; } return null; } }