-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabsForSubmissionStagesPlugin.php
160 lines (132 loc) · 5.23 KB
/
TabsForSubmissionStagesPlugin.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* @file plugins/generic/tabsForSubmissionStages/TabsForSubmissionStagesPlugin.php
*
* Copyright (c) 2025 Lepidus Tecnologia
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class TabsForSubmissionStagesPlugin
* @ingroup plugins_generic_tabsForSubmissionStages
*
* @brief Tabs for Submission Stages plugin class
*/
namespace APP\plugins\generic\tabsForSubmissionStages;
use PKP\plugins\GenericPlugin;
use APP\core\Application;
use PKP\plugins\Hook;
use PKP\db\DAORegistry;
use PKP\security\Role;
use PKP\template\PKPTemplateManager;
use PKP\submission\PKPSubmission;
class TabsForSubmissionStagesPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
Hook::add('TemplateManager::display', [$this, 'displayTabs']);
}
return $success;
}
public function getDisplayName()
{
return __('plugins.generic.tabsForSubmissionStages.displayName');
}
public function getDescription()
{
return __('plugins.generic.tabsForSubmissionStages.description');
}
public function displayTabs(string $hookName, array $params): bool
{
[$templateManager, $template] = $params;
if ($template !== 'dashboard/index.tpl') {
return false;
}
$userRoles = $templateManager->getTemplateVars('userRoles');
if (!array_intersect([Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER], $userRoles)) {
return false;
}
$request = Application::get()->getRequest();
$context = $request->getContext();
$dispatcher = $request->getDispatcher();
$apiUrl = $dispatcher->url($request, Application::ROUTE_API, $context->getPath(), '_submissions');
$componentsState = $templateManager->getState('components');
$this->loadResources($request, $templateManager);
$inReviewListPanel = new \APP\components\listPanels\SubmissionsListPanel(
'customSubmissions',
__('common.queue.short.submissionsInReview'),
[
'apiUrl' => $apiUrl,
'getParams' => [
'stageIds' => [WORKFLOW_STAGE_ID_INTERNAL_REVIEW, WORKFLOW_STAGE_ID_EXTERNAL_REVIEW],
],
'lazyLoad' => true,
'includeIssuesFilter' => $includeIssuesFilter,
'includeAssignedEditorsFilter' => $includeAssignedEditorsFilter,
'includeActiveSectionFiltersOnly' => true,
]
);
$componentsState[$inReviewListPanel->id] = $inReviewListPanel->getConfig();
$inProductionListPanel = new \APP\components\listPanels\SubmissionsListPanel(
'inProduction',
__('plugins.generic.tabsForSubmissionStages.acceptedOrInProductionTabLabel'),
[
'apiUrl' => $apiUrl,
'getParams' => [
'stageIds' => [WORKFLOW_STAGE_ID_EDITING, WORKFLOW_STAGE_ID_PRODUCTION],
'status' => [PKPSubmission::STATUS_QUEUED]
],
'lazyLoad' => true,
'includeIssuesFilter' => $includeIssuesFilter,
'includeAssignedEditorsFilter' => $includeAssignedEditorsFilter,
'includeActiveSectionFiltersOnly' => true,
]
);
$componentsState[$inProductionListPanel->id] = $inProductionListPanel->getConfig();
$templateManager->setState(['components' => $componentsState]);
$templateManager->registerFilter('output', [$this, 'tabsFilter']);
return Hook::CONTINUE;
}
public function tabsFilter($output, $templateMgr): string
{
if (!preg_match('/(<tab[^>]+id="archive"[^>]*>.*?<\/tab>)/s', $output, $matches, PREG_OFFSET_CAPTURE)) {
return $output;
}
$offset = $matches[0][1] + strlen($matches[0][0]);
$newOutput = substr($output, 0, $offset);
$newOutput .= $templateMgr->fetch($this->getTemplateResource('tabs.tpl'));
$newOutput .= substr($output, $offset);
$output = $newOutput;
return $output;
}
public function getCanEnable()
{
$request = Application::get()->getRequest();
return $request->getContext() !== null;
}
public function getCanDisable()
{
$request = Application::get()->getRequest();
return $request->getContext() !== null;
}
private function loadResources($request, $templateMgr)
{
$pluginFullPath = $request->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getPluginPath();
$templateMgr->addJavaScript(
'custom-submissions-list-item',
$pluginFullPath . '/js/components/CustomSubmissionsListItem.js',
[
'priority' => PKPTemplateManager::STYLE_SEQUENCE_LAST,
'contexts' => ['backend']
]
);
$templateMgr->addStyleSheet(
'custom-submissions-list-style',
$pluginFullPath . '/styles/submissionsPage.css',
[
'priority' => PKPTemplateManager::STYLE_SEQUENCE_LAST,
'contexts' => ['backend']
]
);
}
}