-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnouncementBlocksPlugin.inc.php
221 lines (177 loc) · 7.42 KB
/
AnnouncementBlocksPlugin.inc.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* @file plugins/generic/announcementBlocks/AnnouncementBlocksPlugin.inc.php
*
* Copyright Lara Marziali
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class AnnouncementBlocksPlugin
* @ingroup plugins_generic_AnnouncementBlocks
*
* @brief Manage the Announcement Types.
*/
import('classes.core.Application');
//import('lib.pkp.classes.facades.Repo');
import('lib.pkp.classes.plugins.GenericPlugin');
import('lib.pkp.pages.announcement.AnnouncementHandler');
import('lib.pkp.classes.announcement.AnnouncementTypeDAO');
class AnnouncementBlocksPlugin extends GenericPlugin {
/**
* @copydoc GenericPlugin::register()
*/
public function register($category, $path, $mainContextId = NULL) {
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)){
$this->import('AnnouncementBlocksPlugin');
// Ensure that there is a context (journal or press)
if ($request = Application::get()->getRequest()) {
if ($mainContextId) {
$contextId = $mainContextId;
} else {
$context = $request->getContext();
$contextId = $context ? $context->getId() : \PKP\core\PKPApplication::CONTEXT_SITE;
}
}
//Hook::add('Template::Settings::website', [$this, 'callbackShowWebsiteSettingsTabs']); NO
// Intercept the LoadHandler hook to present
// announcement pages when requested.
//Hook::add('LoadHandler', [$this, 'callbackHandleContent']); Uncaught Error: Class "Hook" not found in /var/www/ojs_locale/plugins/generic/announcementBlocks/AnnouncementBlocksPlugin.inc.php:45
HookRegistry::register('TemplateManager::setupBackendPage', [$this, 'trySomething']);
}
return $success;
}
//see also https://github.com/pkp/pkp-lib/blob/main/pages/announcement/AnnouncementHandler.php
//and https://github.com/pkp/customBlockManager/blob/main/controllers/grid/form/CustomBlockForm.inc.php
//and https://github.com/pkp/pkp-lib/blob/efb124de36758eaece88ad911326302635198d03/controllers/grid/announcements/form/AnnouncementTypeForm.php
public function trySomething($hookName, $param)
{
$request = Application::get()->getRequest();
$context = $request->getContext(); #https://docs.pkp.sfu.ca/dev/documentation/en/architecture
$contextId = $context ? $context->getId() : \PKP\core\PKPApplication::CONTEXT_SITE;
$announcementTypeDao = DAORegistry::getDAO('AnnouncementTypeDAO');
$result = (new DAO())->retrieve( #https://php.watch/versions/8.0/non-static-static-call-fatal-error
"SELECT type_id,GROUP_CONCAT(announcement_id) as announcement_id FROM announcements WHERE assoc_id = '$contextId' GROUP BY type_id"
);
$result_array = [];
foreach ($result as $row) {
$result_array[] = json_decode(json_encode($row), true);
}
print_r($result_array);
//print_r($contextId);
//setPath() WRONG
$params = [(int) $announcement_id];
if ($contextId !== null) {
$params[] = (int) $contextId;
}
foreach ($params as $param) {
echo 'typeId: ' . print_r($param, true); //https://stackoverflow.com/a/35934745/5102877
}
}
/**
* Declare the handler function to process the actual page PATH
*
* @param string $hookName The name of the invoked hook
* @param array $args Hook parameters
*
* @return bool Hook handling status
*/
public function callbackHandleContent($hookName, $args)
{
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$page = & $args[0];
$op = & $args[1];
$handler = & $args[3];
/** @var StaticPagesDAO */
$staticPagesDao = DAORegistry::getDAO('StaticPagesDAO');
if ($page == 'pages' && $op == 'preview') {
// This is a preview request; mock up a static page to display.
// The handler class ensures that only managers and administrators
// can do this.
$staticPage = $staticPagesDao->newDataObject();
$staticPage->setContent((array) $request->getUserVar('content'), null);
$staticPage->setTitle((array) $request->getUserVar('title'), null);
} else {
// Construct a path to look for
$path = $page;
if ($op !== 'index') {
$path .= "/${op}";
}
if ($ops = $request->getRequestedArgs()) {
$path .= '/' . implode('/', $ops);
}
// Look for a static page with the given path
$context = $request->getContext();
$staticPage = $staticPagesDao->getByPath(
$context ? $context->getId() : Application::CONTEXT_ID_NONE,
$path
);
}
// Check if this is a request for a static page or preview.
if ($staticPage) {
// Trick the handler into dealing with it normally
$page = 'pages';
$op = 'view';
// It is -- attach the static pages handler.
$handler = new StaticPagesHandler($this, $staticPage);
return true;
}
return false;
}
//TO ELIMINATE, FOR ME
/**
* Permit requests to the announcement block grid handler
*
* @param string $hookName The name of the hook being invoked
*/
/**
* Provide a name for this plugin
*
* The name will appear in the plugins list where editors can
* enable and disable plugins.
*
* @return string
*/
public function getDisplayName() {
return __('plugins.generic.announcementBlocks.displayName');
}
/**
* Provide a description for this plugin
*
* The description will appear in the plugins list where editors can
* enable and disable plugins.
*
* @return string
*/
public function getDescription() {
return __('plugins.generic.announcementBlocks.description');
}
}
/* CHUNK OF CODE NOT TO USE
public function setupGridHandler($hookName, $params) //see https://github.com/pkp/staticPages/blob/175fbddcb2e86933f90360e78f5472873748644a/StaticPagesPlugin.php
{
$component = & $params[0];
$componentInstance = & $params[2];
if ($component == 'plugins.generic.staticPages.controllers.grid.StaticPageGridHandler') {
// Allow the static page grid handler to get the plugin object
$componentInstance = new StaticPageGridHandler($this);
return true;
}
return false;
}
public function manage($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$dispatcher = $request->getDispatcher();
return $templateMgr->fetchAjax(
'announcementBlocksGridUrlGridContainer',
$dispatcher->url(
$request,
Application::ROUTE_COMPONENT,
null,
'plugins.generic.announcementBlocks.controllers.grid.AnnouncementTypesHandler',
'fetchGrid'
)
);
}
*/