Skip to content

Commit

Permalink
pkp/pkp-lib#10671 3.5 compatibility and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Jan 10, 2025
1 parent 1c07453 commit d6eeafb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions BrowseBySectionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function initDataSectionFormFields($hookName, $args)
$sectionForm = $args[0];
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = $context ? $context->getId() : PKPApplication::CONTEXT_ID_NONE;
$contextId = $context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID;

$section = $sectionForm->getSectionId() ? Repo::section()->get($sectionForm->getSectionId(), $contextId) : null;

Expand Down Expand Up @@ -281,7 +281,7 @@ public function setMenuItemDisplayDetails($hookName, $args)
if (substr($navigationMenuItem->getType(), 0, $typePrefixLength) === BROWSEBYSECTION_NMI_TYPE) {
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = $context ? $context->getId() : PKPApplication::CONTEXT_ID_NONE;
$contextId = $context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID;
$sectionId = substr($navigationMenuItem->getType(), $typePrefixLength);
$section = Repo::section()->get($sectionId, $contextId);

Expand All @@ -297,7 +297,7 @@ public function setMenuItemDisplayDetails($hookName, $args)
null,
'section',
'view',
htmlspecialchars($sectionPath)
[htmlspecialchars($sectionPath)]
));
}
}
Expand Down
47 changes: 22 additions & 25 deletions pages/BrowseBySectionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/generic/browseBySection/pages/BrowseBySectionHandler.php
*
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Copyright (c) 2014-2025 Simon Fraser University
* Copyright (c) 2003-2025 John Willinsky
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
*
* @class BrowseBySectionHandler
Expand All @@ -13,17 +13,20 @@

namespace APP\plugins\generic\browseBySection\pages;

use APP\facades\Repo;
use APP\handler\Handler;
use APP\security\authorization\OjsJournalMustPublishPolicy;
use APP\submission\Collector as SubmissionCollector;
use APP\template\TemplateManager;
use PKP\core\JSONMessage;
use PKP\core\PKPApplication;
use PKP\core\PKPRequest;
use PKP\security\authorization\ContextRequiredPolicy;
use APP\security\authorization\OjsJournalMustPublishPolicy;
use APP\facades\Repo;
use APP\template\TemplateManager;
use PKP\plugins\PluginRegistry;
use APP\submission\Collector as SubmissionCollector;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\Role;
use PKP\submission\PKPSubmission;
use PKP\userGroup\UserGroup;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class BrowseBySectionHandler extends Handler
{
Expand Down Expand Up @@ -52,18 +55,16 @@ public function view($args, $request)
$sectionPath = $args[0] ?? null;
$page = isset($args[1]) && ctype_digit($args[1]) ? (int) $args[1] : 1;
$context = $request->getContext();
$contextId = $context ? $context->getId() : PKPApplication::CONTEXT_ID_NONE;
$contextId = $context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID;

// The page $arg can only contain an integer that's not 1. The first page
// URL does not include page $arg
if (isset($args[1]) && (!ctype_digit($args[1]) || $args[1] == 1)) {
$request->getDispatcher()->handle404();
exit;
throw new NotFoundHttpException();
}

if (!$sectionPath || !$contextId) {
$request->getDispatcher()->handle404();
exit;
throw new NotFoundHttpException();
}

$sections = Repo::section()->getCollector()->filterByContextIds([$contextId])->getMany();
Expand All @@ -77,8 +78,7 @@ public function view($args, $request)
}

if (!$sectionExists) {
$request->getDispatcher()->handle404();
exit;
throw new NotFoundHttpException();
}

$browseByPerPage = $section->getData('browseByPerPage');
Expand All @@ -99,16 +99,15 @@ public function view($args, $request)
$collector = Repo::submission()->getCollector()
->filterByContextIds([$contextId])
->filterBySectionIds([$section->getId()])
->filterByStatus([STATUS_PUBLISHED])
->filterByStatus([PKPSubmission::STATUS_PUBLISHED])
->offset($offset)
->limit($browseByPerPage)
->orderBy($orderBy, $orderDir);
$submissionsIterator = $collector->getMany();
$total = $collector->limit(null)->offset(null)->getCount();

if ($page > 1 && !count($submissionsIterator)) {
$request->getDispatcher()->handle404();
exit;
throw new NotFoundHttpException();
}

$articleGroups = [];
Expand All @@ -125,13 +124,13 @@ public function view($args, $request)
$key = '';
$group = [];
foreach ($submissions as $article) {
$newkey = mb_substr($article->getLocalizedTitle(), 0, 1);
if ($newkey !== $key) {
$newKey = mb_substr($article->getLocalizedTitle(), 0, 1);
if ($newKey !== $key) {
if (count($group)) {
$articleGroups[] = ['key' => $key, 'articles' => $group];
}
$group = [];
$key = $newkey;
$key = $newKey;
}
$group[] = $article;
}
Expand Down Expand Up @@ -159,11 +158,9 @@ public function view($args, $request)
$templateMgr->assign([
'section' => $section,
'sectionPath' => $sectionPath,
'authorUserGroups' => Repo::userGroup()->getCollector()
->filterByRoleIds([Role::ROLE_ID_AUTHOR])
->filterByContextIds([$context->getId()])
->getMany()
->remember(),
'authorUserGroups' => UserGroup::withRoleIds([Role::ROLE_ID_AUTHOR])
->withContextIds([$context->getId()])
->get(),
'sectionDescription' => $section->getLocalizedData('browseByDescription'),
'articleGroups' => $articleGroups,
'issues' => $issues,
Expand Down
18 changes: 9 additions & 9 deletions templates/frontend/pages/section.tpl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{**
* plugins/generic/browseBySection/templates/frontend/pages/section.tpl
*
* Copyright (c) 2017 Simon Fraser University
* Copyright (c) 2017 John Willinsky
* Copyright (c) 2017-2025 Simon Fraser University
* Copyright (c) 2017-2025 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @brief Display the reader-facing section page.
*
* @uses $section Section
* @uses $sectionPath string The URL path for this section
* @uses $sectionDescription string
* @uses $articles array List of Submission objects
* @uses $articleGroups array List of Submission objects
* @uses $issues array List of Issue objects the $articles are published in
* @uses $currentlyShowingStart int 20 in `20-30 of 100 results`
* @uses $currentlyShowingEnd int 30 in `20-30 of 100 results`
* @uses $countMax int 100 in `20-30 of 100 results`
* @uses $currentlyShowingPage int 2 in `2 of 10 pages`
* @uses $countMaxPage int 10 in `2 of 10 pages`.
* @uses $prevPage int The previous page number
* @uses $nextPage int The next page number
* @uses $showingStart int The number of the first item on this page
* @uses $showingEnd int The number of the last item on this page
* @uses $total int Count of all published submissions in this category
*}

{include file="frontend/components/header.tpl" pageTitleTranslated=$section->getLocalizedTitle()|escape}
Expand All @@ -31,7 +31,7 @@
</div>

{if $articleGroups|@count}
{foreach from=$articleGroups item=group}
{foreach from=$articleGroups item=group}
{if $group.key}
<div class="cmp_article_header" id="browse_by_section_group_{$group.key|escape}">
{$group.key|escape}
Expand Down

0 comments on commit d6eeafb

Please sign in to comment.