16 import(
'lib.pkp.classes.controllers.grid.GridHandler');
17 import(
'lib.pkp.controllers.grid.languages.LanguageGridRow');
18 import(
'lib.pkp.controllers.grid.languages.LanguageGridCellProvider');
25 parent::__construct();
28 array(
'saveLanguageSetting',
'setContextPrimaryLocale')
40 parent::initialize($request, $args);
44 LOCALE_COMPONENT_PKP_USER,
45 LOCALE_COMPONENT_PKP_MANAGER
69 $locale = (string) $request->getUserVar(
'rowId');
70 $settingName = (string) $request->getUserVar(
'setting');
71 $settingValue = (boolean) $request->getUserVar(
'value');
73 $context = $request->getContext();
75 import(
'classes.core.Services');
78 $permittedSettings = array(
'supportedFormLocales',
'supportedSubmissionLocales',
'supportedLocales');
79 if (in_array($settingName, $permittedSettings) && $locale) {
80 $currentSettingValue = (array) $context->getData($settingName);
83 array_push($currentSettingValue, $locale);
84 if ($settingName ==
'supportedFormLocales') {
86 $contextService->restoreLocaleDefaults($context, $request, $locale);
87 } elseif ($settingName ==
'supportedSubmissionLocales') {
89 $supportedFormLocales = (array) $context->getData(
'supportedFormLocales');
90 if (!in_array($locale, $supportedFormLocales)) {
91 array_push($supportedFormLocales, $locale);
92 $context = $contextService->edit($context, [
'supportedFormLocales' => $supportedFormLocales], $request);
94 $contextService->restoreLocaleDefaults($context, $request, $locale);
98 $key = array_search($locale, $currentSettingValue);
99 if ($key !==
false) unset($currentSettingValue[$key]);
100 if ($settingName ==
'supportedFormLocales') {
102 $supportedSubmissionLocales = (array) $context->getData(
'supportedSubmissionLocales');
103 $key = array_search($locale, $supportedSubmissionLocales);
104 if ($key !==
false) unset($supportedSubmissionLocales[$key]);
105 $supportedSubmissionLocales = array_values($supportedSubmissionLocales);
106 $context = $contextService->edit($context, [
'supportedSubmissionLocales' => $supportedSubmissionLocales], $request);
112 $context = $contextService->edit($context, [$settingName => $currentSettingValue], $request);
115 $user = $request->getUser();
116 $notificationManager->createTrivialNotification(
117 $user->getId(), NOTIFICATION_TYPE_SUCCESS, array(
'contents' => __(
'notification.localeSettingsSaved')));
120 $newFormLocales = array_map(
function($localeKey) use ($localeNames) {
121 return [
'key' => $localeKey,
'label' => $localeNames[$localeKey]];
122 }, $context->getData(
'supportedFormLocales'));
125 $json->setGlobalEvent(
'set-form-languages', $newFormLocales);
136 $locale = (string) $request->getUserVar(
'rowId');
137 $context = $request->getContext();
142 foreach (array(
'supportedLocales',
'supportedSubmissionLocales',
'supportedFormLocales') as $name) {
143 $$name = $context->getData($name);
144 if (!in_array($locale, $$name)) {
145 array_push($$name, $locale);
146 $context->updateSetting($name, $$name);
150 $context->setPrimaryLocale($locale);
152 $contextDao->updateObject($context);
155 $user = $request->getUser();
156 $notificationManager->createTrivialNotification(
157 $user->getId(), NOTIFICATION_TYPE_SUCCESS, array(
'contents' => __(
'notification.localeSettingsSaved')));
185 'grid.columns.locale',
187 'controllers/grid/languages/localeNameCell.tpl',
205 'controllers/grid/common/cell/radioButtonCell.tpl',
219 'manager.language.ui',
221 'controllers/grid/common/cell/selectStatusCell.tpl',
229 'manager.language.forms',
231 'controllers/grid/common/cell/selectStatusCell.tpl',
239 'manager.language.submissions',
241 'controllers/grid/common/cell/selectStatusCell.tpl',
255 $context = $request->getContext();
257 if (is_array($data)) {
258 foreach ($data as $locale => $localeData) {
259 foreach (array(
'supportedFormLocales',
'supportedSubmissionLocales',
'supportedLocales') as $name) {
260 $data[$locale][$name] = in_array($locale, $context->getData($name));