-
Notifications
You must be signed in to change notification settings - Fork 10
/
BrowseBlockPlugin.php
72 lines (64 loc) · 1.86 KB
/
BrowseBlockPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file plugins/blocks/browse/BrowseBlockPlugin.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2003-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class BrowseBlockPlugin
* @brief Class for browse block plugin
*/
namespace APP\plugins\blocks\browse;
use APP\facades\Repo;
use PKP\plugins\BlockPlugin;
class BrowseBlockPlugin extends BlockPlugin
{
/**
* Get the display name of this plugin.
*
* @return string
*/
public function getDisplayName()
{
return __('plugins.block.browse.displayName');
}
/**
* Get a description of the plugin.
*/
public function getDescription()
{
return __('plugins.block.browse.description');
}
/**
* Get the HTML contents of the browse block.
*
* @param PKPTemplateManager $templateMgr
* @param null|mixed $request
*
* @return string
*/
public function getContents($templateMgr, $request = null)
{
$context = $request->getContext();
if (!$context) {
return '';
}
$router = $request->getRouter();
$requestedCategoryPath = null;
if ($router->getRequestedPage($request) . '/' . $router->getRequestedOp($request) == 'catalog/category') {
$args = $router->getRequestedArgs($request);
$requestedCategoryPath = reset($args);
}
$templateMgr->assign([
'browseBlockSelectedCategory' => $requestedCategoryPath,
'browseCategories' => Repo::category()->getCollector()
->filterByContextIds([$context->getId()])
->getMany()
]);
return parent::getContents($templateMgr);
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\blocks\browse\BrowseBlockPlugin', '\BrowseBlockPlugin');
}