-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConferencePlugin.php
214 lines (189 loc) · 4.79 KB
/
ConferencePlugin.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
<?php
/**
* @file plugins/generic/conference/ConferencePlugin.php
*
* Copyright (c) 2017-2020 Simon Fraser University
* Copyright (c) 2017-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ConferencePlugin
*
* @ingroup plugins_generic_conference
*
* @brief Conference plugin class.
*/
namespace APP\plugins\generic\conference;
use APP\core\Application;
use APP\i18n\AppLocale;
use APP\plugins\generic\conference\controllers\ConferenceHandler;
use APP\template\TemplateManager;
use Exception;
use PKP\core\PKPApplication;
use PKP\core\PKPRequest;
use PKP\facades\Locale;
use PKP\file\ContextFileManager;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use stdClass;
class ConferencePlugin extends GenericPlugin
{
public function __construct()
{
parent::__construct();
$this->application = Application::get()->getName();
}
/**
* @copydoc Plugin::register()
* @param $category
* @param $path
* @param $mainContextId
* @return bool
*/
public function register($category, $path, $mainContextId = NULL)
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
// issue metadata extension
Hook::add('Templates::Editor::Issues::IssueData::AdditionalMetadata', array($this, 'metadataFieldEdit'));
Hook::add('issueform::execute', array($this, 'formExecute'));
Hook::add('issuedao::getAdditionalFieldNames', array($this, 'handleAdditionalFieldNames'));
Hook::add('LoadComponentHandler', array($this, 'setupHandler'));
Hook::add('TemplateResource::getFilename', array($this, '_overridePluginTemplates'));
$locale = AppLocale::getLocale();
$customLocalePath = $this->getPluginPath() . "/customLocale/";
if(is_dir($customLocalePath)) {
$this->addConferenceLocalizationOverriding($customLocalePath);
}
}
Hook::add('Schema::get::issue', function ($hookName, $args) {
$schema = $args[0];
$this->addProperties($schema);
});
return $success;
}
public function addConferenceLocalizationOverriding($path): void
{
Locale::registerPath($path, PHP_INT_MAX);
}
/**
* @param mixed $schema
* @return void
*/
function addProperties($schema): void
{
foreach ($this->getAdditionalFields() as $field) {
$schema->properties->$field = (object)[
'type' => 'string',
'apiSummary' => true,
'validation' => ['nullable']
];
}
}
/**
* @return string[]
*/
function getAdditionalFields()
{
$fiellds = array(
'conferenceDateBegin',
'conferenceDateEnd',
'conferencePlaceStreet',
'conferencePlaceCity',
'conferencePlaceCountry',
'conferenceOnline'
);
return $fiellds;
}
/**
* @param $hookName
* @param $params
* @return false|mixed|string|null
*/
function issueViewHandler($hookName, $params)
{
$request = Application::get()->getRequest();
$templateManager = TemplateManager::getManager($request);
$metadataView = $templateManager->fetch($this->getTemplateResource('metadataView.tpl'));
$templateManager->assign('metadataView', $metadataView);
return $metadataView;
}
/**
* @param $hookName
* @param $params
* @return void
*/
function setupHandler($hookName, $params)
{
ConferenceHandler::setPlugin($this);
}
/***
* @param $hookName
* @param $params
* @return false
*/
function handleAdditionalFieldNames($hookName, $params): bool
{
$fields =& $params[1];
foreach ($this->getAdditionalFields() as $field) {
$fields[] = $field;
}
return false;
}
/**
* @return string
*/
public function getDisplayName()
{
return __('plugins.generic.conference.displayName');
}
/***
* @return string
*/
public function getDescription(): string
{
return __('plugins.generic.conference.description');
}
/**
* Insert metadataEditForm
*
* @param $hookName
* @param $params
* @return false
*/
function metadataFieldEdit($hookName, $params): bool
{
$smarty =& $params[1];
$output =& $params[2];
$issue = $smarty->getTemplateVars('issue');
if ($issue) {
foreach ($this->getAdditionalFields() as $field) {
$smarty->assign($field, $issue->getData($field));
}
}
$output .= $smarty->fetch($this->getTemplateResource('metadataForm.tpl'));
return false;
}
/**
* @param $hookName
* @param $params
* @return bool
*/
function formExecute($hookName, $params): bool
{
$issue =& $params[0]->issue;
if ($issue) {
$requestVars = $this->getRequest()->getUserVars();
foreach ($this->getAdditionalFields() as $field) {
if (array_key_exists($field, $requestVars)) {
$issue->setData($field, $requestVars[$field]);
}
else {
$issue->setData($field,"");
}
}
}
return false;
}
}