Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to support OMP and add namespaces #101

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
662 changes: 0 additions & 662 deletions CitationStyleLanguagePlugin.inc.php

This file was deleted.

1,006 changes: 1,006 additions & 0 deletions CitationStyleLanguagePlugin.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @file CitationStyleLanguageSettingsForm.inc.inc.php
* @file CitationStyleLanguageSettingsForm.php
*
* Copyright (c) 2017-2020 Simon Fraser University
* Copyright (c) 2017-2020 John Willinsky
Expand All @@ -12,65 +12,84 @@
* @brief Form for site admins to modify Citation Style Language settings.
*/

namespace APP\plugins\generic\citationStyleLanguage;

use APP\core\Application;
use APP\facades\Repo;
use APP\notification\NotificationManager;
use APP\template\TemplateManager;
use PKP\form\Form;

use PKP\form\validation\FormValidatorCSRF;
use PKP\form\validation\FormValidatorPost;
use PKP\notification\PKPNotification;
use PKP\security\Role;

class CitationStyleLanguageSettingsForm extends Form
{
/** @var object $plugin */
public $plugin;
/** @var CitationStyleLanguagePlugin $plugin */
public CitationStyleLanguagePlugin $plugin;

/**
* Constructor
*
* @param object $plugin
* @param CitationStyleLanguagePlugin $plugin object
*/
public function __construct($plugin)
public function __construct(CitationStyleLanguagePlugin $plugin)
{
parent::__construct($plugin->getTemplateResource('settings.tpl'));
$this->plugin = $plugin;
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}

/**
* @copydoc Form::init
*/
public function initData()
public function initData(): void
{
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
$contextId = $context->getId();
$this->setData('primaryCitationStyle', $this->plugin->getSetting($contextId, 'primaryCitationStyle'));
$this->setData('enabledCitationStyles', array_keys($this->plugin->getEnabledCitationStyles($contextId)));
$this->setData('enabledCitationDownloads', $this->plugin->getEnabledCitationDownloads($contextId));
$this->setData('publisherLocation', $this->plugin->getSetting($contextId, 'publisherLocation'));
$this->setData('groupAuthor', $this->plugin->getAuthorGroups($contextId));
$this->setData('groupTranslator', $this->plugin->getTranslatorGroups($contextId));
if ($this->plugin->application === 'omp') {
$this->setData('groupEditor', $this->plugin->getEditorGroups($contextId));
$this->setData('groupChapterAuthor', $this->plugin->getChapterAuthorGroups($contextId));
}
}

/**
* Assign form data to user-submitted data.
*/
public function readInputData()
public function readInputData(): void
{
$this->readUserVars([
'primaryCitationStyle',
'enabledCitationStyles',
'enabledCitationDownloads',
'publisherLocation',
'groupAuthor',
'groupTranslator'
]);
if ($this->plugin->application === 'omp') {
$this->readUserVars(['groupEditor']);
$this->readUserVars(['groupChapterAuthor']);
}
}

/**
* @copydoc Form::fetch()
*
* @param null|mixed $template
*/
public function fetch($request, $template = null, $display = false)
public function fetch($request, $template = null, $display = false): ?string
{
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
$contextId = $context->getId();

$allStyles = [];
foreach ($this->plugin->getCitationStyles() as $style) {
Expand All @@ -82,6 +101,14 @@ public function fetch($request, $template = null, $display = false)
$allDownloads[$style['id']] = $style['title'];
}

$allUserGroups = [];
$userGroups = Repo::userGroup()->getByRoleIds( [Role::ROLE_ID_AUTHOR], $contextId );
$userGroups = $userGroups->toArray();
foreach ($userGroups as $userGroup) {
$allUserGroups[(int) $userGroup->getId()] = $userGroup->getLocalizedName();
}
asort($allUserGroups);

$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'pluginName' => $this->plugin->getName(),
Expand All @@ -90,8 +117,19 @@ public function fetch($request, $template = null, $display = false)
'primaryCitationStyle' => $this->getData('primaryCitationStyle'),
'enabledStyles' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationStyles($contextId)),
'enabledDownloads' => $this->plugin->mapCitationIds($this->plugin->getEnabledCitationDownloads($contextId)),
'application' => $this->plugin->application,
'groupAuthor' => $this->getData('groupAuthor'),
'groupTranslator' => $this->getData('groupTranslator'),
'allUserGroups' => $allUserGroups,
]);

if ($this->plugin->application === 'omp') {
$templateMgr->assign([
'groupEditor' => $this->getData('groupEditor'),
'groupChapterAuthor' => $this->getData('groupChapterAuthor'),
]);
}

return parent::fetch($request, $template, $display);
}

Expand All @@ -102,13 +140,19 @@ public function execute(...$functionArgs)
{
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
$contextId = $context->getId();
$this->plugin->updateSetting($contextId, 'primaryCitationStyle', $this->getData('primaryCitationStyle'));
$enabledCitationStyles = $this->getData('enabledCitationStyles') ? $this->getData('enabledCitationStyles') : [];
$enabledCitationStyles = $this->getData('enabledCitationStyles') ?: [];
$this->plugin->updateSetting($contextId, 'enabledCitationStyles', $enabledCitationStyles);
$enabledCitationDownloads = $this->getData('enabledCitationDownloads') ? $this->getData('enabledCitationDownloads') : [];
$enabledCitationDownloads = $this->getData('enabledCitationDownloads') ?: [];
$this->plugin->updateSetting($contextId, 'enabledCitationDownloads', $enabledCitationDownloads);
$this->plugin->updateSetting($contextId, 'publisherLocation', $this->getData('publisherLocation'));
$this->plugin->updateSetting($contextId, 'groupAuthor', $this->getData('groupAuthor'));
$this->plugin->updateSetting($contextId, 'groupTranslator', $this->getData('groupTranslator'));
if( $this->plugin->application === 'omp') {
$this->plugin->updateSetting($contextId, 'groupEditor', $this->getData('groupEditor'));
$this->plugin->updateSetting($contextId, 'groupChapterAuthor', $this->getData('groupChapterAuthor'));
}

$notificationMgr = new NotificationManager();
$user = $request->getUser();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": {
"citation-style-language/locales":"@dev",
"seboettg/citeproc-php": "^2.2.0"
"seboettg/citeproc-php": "^2.4.1"
},
"config": {
"vendor-dir": "lib/vendor",
Expand Down
83 changes: 46 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading