Skip to content

Commit

Permalink
pkp#9914 editorial history public page
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed May 3, 2024
1 parent ef85efc commit ffe1643
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
3 changes: 3 additions & 0 deletions locale/en/common.po
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ msgstr "Peer Reviewers"
msgid "common.editorialMasthead.peerReviewers.description"
msgstr "The editors express their appreciation of the reviewers for {$year} listed below."

msgid "common.editorialHistory"
msgstr "Editorial History"

msgid "common.name"
msgstr "Name"

Expand Down
117 changes: 117 additions & 0 deletions pages/about/AboutContextHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
use APP\facades\Repo;
use APP\handler\Handler;
use APP\template\TemplateManager;
use DateInterval;
use DatePeriod;
use DateTime;
use DateTimeImmutable;
use PKP\facades\Locale;
use PKP\plugins\Hook;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\Role;
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
use PKP\userGroup\relationships\enums\UserUserGroupStatus;
use PKP\userGroup\relationships\UserUserGroup;

class AboutContextHandler extends Handler
Expand Down Expand Up @@ -138,6 +143,118 @@ public function editorialMasthead($args, $request)
$templateMgr->display('frontend/pages/editorialMasthead.tpl');
}

/**
* Display editorial history page.
*
* @param array $args
* @param \PKP\core\PKPRequest $request
*
* @hook AboutContextHandler::editorialHistory [[$mastheadRoles, $mastheadUsers]]
*/
public function editorialHistory($args, $request)
{
$context = $request->getContext();

$savedMastheadUserGroupIdsOrder = (array) $context->getData('mastheadUserGroupIds');

$collector = Repo::userGroup()->getCollector();
$allMastheadUserGroups = $collector
->filterByContextIds([$context->getId()])
->filterByMasthead(true)
->orderBy($collector::ORDERBY_ROLE_ID)
->getMany()
->toArray();

// sort the masthead roles in their saved order for display
$mastheadRoles = array_replace(array_flip($savedMastheadUserGroupIdsOrder), $allMastheadUserGroups);

$mastheadUsers = [];
foreach ($mastheadRoles as $mastheadUserGroup) {
if ($mastheadUserGroup->getRoleId() == Role::ROLE_ID_REVIEWER) {
continue;
}
// Get all users that were active and are not active any more in the given role
// and that have accepted to be displayed on the masthead for that role.
// No need to filter by context ID, because the user groups are already filtered so.
$usersCollector = Repo::user()->getCollector();
$users = $usersCollector
->filterByUserGroupIds([$mastheadUserGroup->getId()])
->filterByUserUserGroupStatus(UserUserGroupStatus::STATUS_ENDED)
->filterByUserUserGroupMastheadStatus(UserUserGroupMastheadStatus::STATUS_ON)
->orderBy($usersCollector::ORDERBY_GIVENNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()])
->getMany();

foreach ($users as $user) {
$userUserGroups = UserUserGroup::withUserId($user->getId())
->withUserGroupId($mastheadUserGroup->getId())
->withEnded()
->withMasthead()
->get();
$services = [];
foreach ($userUserGroups as $userUserGroup) {
$startDatetime = new DateTime($userUserGroup->dateStart);
$endDatetime = new DateTime($userUserGroup->dateEnd);
$services[] = [
'dateStart' => $startDatetime->format('Y'),
'dateEnd' => $endDatetime->format('Y'),
];
}
if (!empty($services)) {
$mastheadUsers[$mastheadUserGroup->getId()][$user->getId()] = [
'user' => $user,
'services' => $services
];
}

}
}

// Get the first date published for the context
// to get the first year the reviewers should be listed for
$dateRange = Repo::publication()->getDateBoundaries(
Repo::publication()
->getCollector()
->filterByContextIds([$context->getId()])
);
$startDate = DateTimeImmutable::createFromFormat('Y-m-d', $dateRange->min_date_published);
// The year before the previous year is the last to be considered
$endDate = DateTimeImmutable::createFromFormat('Y', date('Y') - 1);
$period = new DatePeriod(
$startDate,
new DateInterval('P1Y'),
$endDate
);
$reviewers = [];
foreach ($period as $key => $value) {
$year = $value->format('Y');
$reviewerIds = Repo::reviewAssignment()->getReviewerIdsByCompletedYear($context->getId(), $year);
if ($reviewerIds->isNotEmpty()) {
$usersCollector = Repo::user()->getCollector();
$reviewers[$year] = $usersCollector
->filterByUserIds($reviewerIds->toArray())
->orderBy($usersCollector::ORDERBY_GIVENNAME, $usersCollector::ORDER_DIR_ASC, [Locale::getLocale(), Application::get()->getRequest()->getSite()->getPrimaryLocale()])
->getMany();
}
}

Hook::call('AboutContextHandler::editorialHistory', [$mastheadRoles, $mastheadUsers, $reviewers]);

// To come after https://github.com/pkp/pkp-lib/issues/9771
// $orcidIcon = OrcidManager::getIcon();
$orcidIcon = '';

$templateMgr = TemplateManager::getManager($request);
$this->setupTemplate($request);
$templateMgr->assign([
'mastheadRoles' => $mastheadRoles,
'mastheadUsers' => $mastheadUsers,
'reviewers' => $reviewers,
'orcidIcon' => $orcidIcon
]);
$templateMgr->display('frontend/pages/editorialHistory.tpl');
}


/**
* Display editorialTeam page.
*
Expand Down
1 change: 1 addition & 0 deletions pages/about/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
switch ($op) {
case 'index':
case 'editorialMasthead':
case 'editorialHistory':
case 'editorialTeam':
case 'submissions':
case 'contact':
Expand Down
70 changes: 70 additions & 0 deletions templates/frontend/pages/editorialHistory.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{**
* templates/frontend/pages/editorialHistory.tpl
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief Display journal's editorial history page.
*
*}
{include file="frontend/components/header.tpl" pageTitle="common.editorialHistory"}

<div class="page page_masthead">
{include file="frontend/components/breadcrumbs.tpl" currentTitleKey="common.editorialHistory"}

<h1>{translate key="common.editorialHistory"}</h1>
{foreach from=$mastheadRoles item="mastheadRole"}
{if array_key_exists($mastheadRole->getId(), $mastheadUsers)}
<h2>{$mastheadRole->getLocalizedName()|escape}</h2>
<ul>
{foreach from=$mastheadUsers[$mastheadRole->getId()] item="mastheadUser"}
{foreach from=$mastheadUser['services'] item="service"}
<li>
{$mastheadUser['user']->getFullName()|escape},
{$mastheadUser['user']->getLocalizedData('affiliation')|escape},
{$service['dateStart']} - {$service['dateEnd']}
{if $mastheadUser['user']->getData('orcid')}
<span class="orcid">
{if $mastheadUser['user']->getData('orcidAccessToken')}
{$orcidIcon}
{/if}
<a href="{$mastheadUser['user']->getData('orcid')|escape}" target="_blank">
{$mastheadUser['user']->getData('orcid')|escape}
</a>
</span>
{/if}
</li>
{/foreach}
{/foreach}
</ul>
{/if}
{/foreach}

{if !empty($reviewers)}
<h2>{translate key="common.editorialMasthead.peerReviewers"}</h2>
{foreach from=$reviewers item="users" key="year"}
<p>{$year}</p>
<ul>
{foreach from=$users item="reviewer"}
<li>
{$reviewer->getFullName()|escape},
{$reviewer->getLocalizedData('affiliation')|escape}
{if $reviewer->getData('orcid')}
<span class="orcid">
{if $reviewer->getData('orcidAccessToken')}
{$orcidIcon}
{/if}
<a href="{$reviewer->getData('orcid')|escape}" target="_blank">
{$reviewer->getData('orcid')|escape}
</a>
</span>
{/if}
</li>
{/foreach}
</ul>
{{/foreach}}
{/if}
</div><!-- .page -->

{include file="frontend/components/footer.tpl"}
5 changes: 5 additions & 0 deletions templates/frontend/pages/editorialMasthead.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<div class="page page_masthead">
{include file="frontend/components/breadcrumbs.tpl" currentTitleKey="common.editorialMasthead"}

<p>
<a href="{url page="about" op="editorialHistory" router=\PKP\core\PKPApplication::ROUTE_PAGE}">
{translate key="common.editorialHistory"}
</a>
</p>
<h1>{translate key="common.editorialMasthead"}</h1>
{foreach from=$mastheadRoles item="mastheadRole"}
{if array_key_exists($mastheadRole->getId(), $mastheadUsers)}
Expand Down

0 comments on commit ffe1643

Please sign in to comment.