-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubmittedFilterPlugin.php
More file actions
135 lines (117 loc) · 4.14 KB
/
SubmittedFilterPlugin.php
File metadata and controls
135 lines (117 loc) · 4.14 KB
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
<?php
/**
* @file plugins/generic/submittedFilter/SubmittedFilterPlugin.php
*
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class SubmittedFilterPlugin
*
* @brief Adds a "Submitted" filter to the editorial submissions lists that shows
* only completed (fully submitted) submissions, excluding incomplete ones still
* in the submission wizard.
*/
namespace APP\plugins\generic\submittedFilter;
use APP\core\Application;
use Illuminate\Database\Query\Builder;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class SubmittedFilterPlugin extends GenericPlugin
{
/** Query string parameter used by the new filter. */
public const PARAM = 'isSubmitted';
/**
* @copydoc Plugin::register()
*
* @param null|mixed $mainContextId
*/
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
// Apply the filter to the submission query when the param is present.
Hook::add('Submission::Collector', [$this, 'addQueryConstraint']);
// Inject the filter control into the dashboard list panels.
Hook::add('TemplateManager::display', [$this, 'addFilterToDashboard']);
}
return $success;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return __('plugins.generic.submittedFilter.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return __('plugins.generic.submittedFilter.description');
}
/**
* Restrict the submissions query to completed submissions when the
* isSubmitted filter is active.
*
* @param string $hookName
* @param array $args [&$q (Builder), $collector (Collector)]
*/
public function addQueryConstraint(string $hookName, array $args): bool
{
/** @var Builder $q */
$q = $args[0];
$request = Application::get()->getRequest();
if (!$request || !$request->getUserVar(self::PARAM)) {
return Hook::CONTINUE;
}
// Completed submission: wizard finished (submission_progress = '') and still
// sitting in the Submission stage, i.e. not yet advanced to review,
// copyediting or production.
$q->where('s.submission_progress', '=', '')
->where('s.stage_id', '=', WORKFLOW_STAGE_ID_SUBMISSION);
return Hook::CONTINUE;
}
/**
* Add the "Submitted" filter alongside the existing "Incomplete" filter in
* every submissions list panel on the editorial dashboard.
*
* @param string $hookName
* @param array $args [$templateMgr, &$template, &$output]
*/
public function addFilterToDashboard(string $hookName, array $args): bool
{
$templateMgr = $args[0];
$template = $args[1];
if ($template !== 'dashboard/index.tpl') {
return Hook::CONTINUE;
}
$components = $templateMgr->getState('components');
if (!is_array($components)) {
return Hook::CONTINUE;
}
$submittedFilter = [
'param' => self::PARAM,
'value' => true,
'title' => __('plugins.generic.submittedFilter.filter.submitted'),
];
foreach ($components as &$component) {
if (empty($component['filters']) || !is_array($component['filters'])) {
continue;
}
foreach ($component['filters'] as &$group) {
if (empty($group['filters']) || !is_array($group['filters'])) {
continue;
}
foreach ($group['filters'] as $filter) {
if (($filter['param'] ?? null) === 'isIncomplete') {
$group['filters'][] = $submittedFilter;
continue 3;
}
}
}
}
unset($component, $group);
$templateMgr->setState(['components' => $components]);
return Hook::CONTINUE;
}
}