Open Journal Systems  3.0.0
 All Classes 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  //
60  function saveLanguageSetting($args, $request) {
61  $locale = (string) $request->getUserVar('rowId');
62  $settingName = (string) $request->getUserVar('setting');
63  $settingValue = (boolean) $request->getUserVar('value');
64  $availableLocales = $this->getGridDataElements($request);
65  $context = $request->getContext();
66 
67  $permittedSettings = array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales');
68  if (in_array($settingName, $permittedSettings) && $locale) {
69  $currentSettingValue = (array) $context->getSetting($settingName);
70  if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
71  if ($settingValue) {
72  array_push($currentSettingValue, $locale);
73  } else {
74  $key = array_search($locale, $currentSettingValue);
75  if ($key !== false) unset($currentSettingValue[$key]);
76  }
77  }
78  }
79 
80  $context->updateSetting($settingName, $currentSettingValue);
81 
82  $notificationManager = new NotificationManager();
83  $user = $request->getUser();
84  $notificationManager->createTrivialNotification(
85  $user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.localeSettingsSaved')));
86 
87  return DAO::getDataChangedEvent($locale);
88  }
89 
95  function setContextPrimaryLocale($args, $request) {
96  $locale = (string) $request->getUserVar('rowId');
97  $context = $request->getContext();
98  $availableLocales = $this->getGridDataElements($request);
99 
100  if (AppLocale::isLocaleValid($locale) && array_key_exists($locale, $availableLocales)) {
101  // Make sure at least the primary locale is chosen as available
102  foreach (array('supportedLocales', 'supportedSubmissionLocales', 'supportedFormLocales') as $name) {
103  $$name = $context->getSetting($name);
104  if (!in_array($locale, $$name)) {
105  array_push($$name, $locale);
106  $context->updateSetting($name, $$name);
107  }
108  }
109 
110  $context->setPrimaryLocale($locale);
111  $contextDao = $context->getDAO();
112  $contextDao->updateObject($context);
113 
114  $notificationManager = new NotificationManager();
115  $user = $request->getUser();
116  $notificationManager->createTrivialNotification(
117  $user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.localeSettingsSaved')));
118  }
119 
120  return DAO::getDataChangedEvent();
121  }
122 
123  //
124  // Protected methods.
125  //
131  function getCellProvider() {
132  return new LanguageGridCellProvider();
133  }
134 
138  function addNameColumn() {
139  $cellProvider = $this->getCellProvider();
140 
141  // Locale name.
142  $this->addColumn(
143  new GridColumn(
144  'locale',
145  'grid.columns.locale',
146  null,
147  'controllers/grid/languages/localeNameCell.tpl',
148  $cellProvider
149  )
150  );
151  }
152 
157  function addPrimaryColumn($columnId) {
158  $cellProvider = $this->getCellProvider();
159 
160  $this->addColumn(
161  new GridColumn(
162  $columnId,
163  'locale.primary',
164  null,
165  'controllers/grid/common/cell/radioButtonCell.tpl',
166  $cellProvider
167  )
168  );
169  }
170 
174  function addManagementColumns() {
175  $cellProvider = $this->getCellProvider();
176  $this->addColumn(
177  new GridColumn(
178  'uiLocale',
179  'manager.language.ui',
180  null,
181  'controllers/grid/common/cell/selectStatusCell.tpl',
182  $cellProvider
183  )
184  );
185 
186  $this->addColumn(
187  new GridColumn(
188  'submissionLocale',
189  'manager.language.submissions',
190  null,
191  'controllers/grid/common/cell/selectStatusCell.tpl',
192  $cellProvider
193  )
194  );
195 
196  $this->addColumn(
197  new GridColumn(
198  'formLocale',
199  'manager.language.forms',
200  null,
201  'controllers/grid/common/cell/selectStatusCell.tpl',
202  $cellProvider
203  )
204  );
205  }
206 
214  function addManagementData($request, $data) {
215  $context = $request->getContext();
216 
217  if (is_array($data)) {
218  foreach ($data as $locale => $localeData) {
219  foreach (array('supportedFormLocales', 'supportedSubmissionLocales', 'supportedLocales') as $name) {
220  $data[$locale][$name] = in_array($locale, (array) $context->getSetting($name));
221  }
222  }
223  } else {
224  assert(false);
225  }
226 
227  return $data;
228  }
229 }
230 
231 ?>
setContextPrimaryLocale($args, $request)
static requireComponents()
addColumn($column)
Class defining basic operations for handling HTML grids.
Subclass for a language grid column&#39;s cell provider.
addRoleAssignment($roleIds, $operations)
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
& getGridDataElements($request)
saveLanguageSetting($args, $request)
addManagementData($request, $data)
Handle language grid requests.
static isLocaleValid($locale)
Represents a column within a grid. It is used to configure the way cells within a column are displaye...