forked from withanage/conference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConferencePlugin.inc.php
208 lines (177 loc) · 4.85 KB
/
ConferencePlugin.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
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
class ConferencePlugin extends GenericPlugin
{
/**
* @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
HookRegistry::register('Templates::Editor::Issues::IssueData::AdditionalMetadata', array($this, 'metadataFieldEdit'));
HookRegistry::register('issueform::execute', array($this, 'formExecute'));
HookRegistry::register('issuedao::getAdditionalFieldNames', array($this, 'handleAdditionalFieldNames'));
HookRegistry::register('LoadComponentHandler', array($this, 'setupHandler'));
HookRegistry::register('TemplateResource::getFilename', array($this, '_overridePluginTemplates'));
$locale = AppLocale::getLocale();
$customLocalePath = $this->getPluginPath() . "/customLocale/" . $locale . '/';
$dir = new RecursiveDirectoryIterator($customLocalePath);
$files = new RecursiveIteratorIterator($dir);
foreach ($files as $file) {
$pathinfo = pathinfo($file->getFileName());
if ($pathinfo && $pathinfo['extension'] == 'po') {
AppLocale::registerLocaleFile($locale, Core::getBaseDir() . '/' . $file);
}
}
HookRegistry::register('PKPLocale::registerLocaleFile', array($this, 'addCustomLocale'));
}
HookRegistry::register('Schema::get::issue', function ($hookName, $args) {
$schema = $args[0];
$this->addProperties($schema);
});
return $success;
}
/**
* @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'
);
return $fiellds;
}
/**
* @param $hookName
* @param $args
* @return bool
*/
function addCustomLocale($hookName, $args)
{
import('lib.pkp.classes.file.ContextFileManager');
$locale =& $args[0];
$request = Application::get()->getRequest();
$context = $request->getContext();
$localeFilename =& $args[1];
if ($context) {
$contextFileManager = new ContextFileManager($context->getId());
$customLocalePath = Core::getBaseDir() . '/' . $this->getPluginPath() . "/customLocale/$locale/$localeFilename";
if ($contextFileManager->fileExists($customLocalePath)) {
AppLocale::registerLocaleFile($locale, $customLocalePath, false);
}
}
return true;
}
/**
* @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)
{
import('plugins.generic.conference.controllers.ConferenceHandler');
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;
$requestVars = $this->getRequest()->getUserVars();
foreach ($this->getAdditionalFields() as $field) {
if (array_key_exists($field, $requestVars)) {
$conferenceDateBegin = $requestVars[$field];
if ($issue && $conferenceDateBegin) {
$issue->setData($field, $conferenceDateBegin);
}
}
}
return false;
}
}