Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
LanguageGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridHandler');
17 import('lib.pkp.controllers.grid.languages.LanguageGridRow');
18 import('lib.pkp.controllers.grid.languages.LanguageGridCellProvider');
19 
24  function LanguageGridHandler() {
25  parent::GridHandler();
26  $this->addRoleAssignment(
27  ROLE_ID_MANAGER,
28  array('saveLanguageSetting', 'setContextPrimaryLocale')
29  );
30  }
31 
32 
33  //
34  // Implement template methods from PKPHandler.
35  //
39  function initialize($request) {
40  parent::initialize($request);
41 
42  // Load user-related translations.
44  LOCALE_COMPONENT_PKP_USER,
45  LOCALE_COMPONENT_PKP_MANAGER
46  );
47 
48  // Basic grid configuration.
49  $this->setTitle('common.languages');
50  }
51 
52  //
53  // Public handler methods.
54  //
61  function saveLanguageSetting($args, $request) {
62  $locale = (string) $request->getUserVar('rowId');
63  $settingName = (string) $request->getUserVar('setting');
64  $settingValue = (boolean) $request->getUserVar('value');
65  $availableLocales = $this->getGridDataElements($request);
66  $context = $request->getContext();
67 
68  $permittedSettings = array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales');
69  if (in_array($settingName, $permittedSettings) && $locale) {
70  $currentSettingValue = (array) $context->getSetting($settingName);
71  if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
72  if ($settingValue) {
73  array_push($currentSettingValue, $locale);
74  } else {
75  $key = array_search($locale, $currentSettingValue);
76  if ($key !== false) unset($currentSettingValue[$key]);
77  }
78  }
79  }
80 
81  $context->updateSetting($settingName, $currentSettingValue);
82 
83  $notificationManager = new NotificationManager();
84  $user = $request->getUser();
85  $notificationManager->createTrivialNotification(
86  $user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.localeSettingsSaved')));
87 
88  return DAO::getDataChangedEvent($locale);
89  }
90 
97  function setContextPrimaryLocale($args, $request) {
98  $locale = (string) $request->getUserVar('rowId');
99  $context = $request->getContext();
100  $availableLocales = $this->getGridDataElements($request);
101 
102  if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
103  // Make sure at least the primary locale is chosen as available
104  foreach (array('supportedLocales', 'supportedSubmissionLocales', 'supportedFormLocales') as $name) {
105  $$name = $context->getSetting($name);
106  if (!in_array($locale, $$name)) {
107  array_push($$name, $locale);
108  $context->updateSetting($name, $$name);
109  }
110  }
111 
112  $context->setPrimaryLocale($locale);
113  $contextDao = $context->getDAO();
114  $contextDao->updateObject($context);
115 
116  $notificationManager = new NotificationManager();
117  $user = $request->getUser();
118  $notificationManager->createTrivialNotification(
119  $user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.localeSettingsSaved')));
120  }
121 
122  return DAO::getDataChangedEvent();
123  }
124 
125  //
126  // Protected methods.
127  //
133  function getCellProvider() {
134  return new LanguageGridCellProvider();
135  }
136 
140  function addNameColumn() {
141  $cellProvider = $this->getCellProvider();
142 
143  // Locale name.
144  $this->addColumn(
145  new GridColumn(
146  'locale',
147  'grid.columns.locale',
148  null,
149  'controllers/grid/languages/localeNameCell.tpl',
150  $cellProvider
151  )
152  );
153  }
154 
159  function addPrimaryColumn($columnId) {
160  $cellProvider = $this->getCellProvider();
161 
162  $this->addColumn(
163  new GridColumn(
164  $columnId,
165  'locale.primary',
166  null,
167  'controllers/grid/common/cell/radioButtonCell.tpl',
168  $cellProvider
169  )
170  );
171  }
172 
176  function addManagementColumns() {
177  $cellProvider = $this->getCellProvider();
178  $this->addColumn(
179  new GridColumn(
180  'uiLocale',
181  'manager.language.ui',
182  null,
183  'controllers/grid/common/cell/selectStatusCell.tpl',
184  $cellProvider
185  )
186  );
187 
188  $this->addColumn(
189  new GridColumn(
190  'submissionLocale',
191  'manager.language.submissions',
192  null,
193  'controllers/grid/common/cell/selectStatusCell.tpl',
194  $cellProvider
195  )
196  );
197 
198  $this->addColumn(
199  new GridColumn(
200  'formLocale',
201  'manager.language.forms',
202  null,
203  'controllers/grid/common/cell/selectStatusCell.tpl',
204  $cellProvider
205  )
206  );
207  }
208 
216  function addManagementData($request, $data) {
217  $context = $request->getContext();
218 
219  if (is_array($data)) {
220  foreach ($data as $locale => $localeData) {
221  foreach (array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales') as $name) {
222  $data[$locale][$name] = in_array($locale, (array) $context->getSetting($name));
223  }
224  }
225  } else {
226  assert(false);
227  }
228 
229  return $data;
230  }
231 }
232 
233 ?>
setContextPrimaryLocale($args, $request)
static requireComponents()
addColumn($column)
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
Subclass for a language grid column&#39;s cell provider.
addRoleAssignment($roleIds, $operations)
& getGridDataElements($request)
saveLanguageSetting($args, $request)
addManagementData($request, $data)
Handle language grid requests.
static isLocaleValid($locale)
The GridColumn class represents a column within a grid. It is used to format the data presented in a ...
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633