Open Journal Systems  3.3.0
InstallLanguageForm.inc.php
1 <?php
2 
16 // Import the base Form.
17 import('lib.pkp.classes.form.Form');
18 
19 class InstallLanguageForm extends Form {
20 
24  function __construct() {
25  parent::__construct('controllers/grid/languages/installLanguageForm.tpl');
26  }
27 
28  //
29  // Overridden methods from Form.
30  //
34  function initData() {
35  parent::initData();
36 
37  $request = Application::get()->getRequest();
38  $site = $request->getSite();
39  $this->setData('installedLocales', $site->getInstalledLocales());
40  }
41 
45  function fetch($request, $template = null, $display = false) {
46  $site = $request->getSite();
47  $allLocales = AppLocale::getAllLocales();
48  $installedLocales = $this->getData('installedLocales');
49  $notInstalledLocales = array_diff(array_keys($allLocales), $installedLocales);
50 
51  $templateMgr = TemplateManager::getManager($request);
52  $templateMgr->assign(array(
53  'allLocales' => $allLocales,
54  'notInstalledLocales' => $notInstalledLocales,
55  ));
56 
57  return parent::fetch($request, $template, $display);
58  }
59 
63  function readInputData() {
64  parent::readInputData();
65 
66  $request = Application::get()->getRequest();
67  $localesToInstall = $request->getUserVar('localesToInstall');
68  $this->setData('localesToInstall', $localesToInstall);
69  }
70 
74  function execute(...$functionArgs) {
75  $request = Application::get()->getRequest();
76  $site = $request->getSite();
77  $localesToInstall = $this->getData('localesToInstall');
78 
79  parent::execute(...$functionArgs);
80 
81  if (isset($localesToInstall) && is_array($localesToInstall)) {
82  $installedLocales = $site->getInstalledLocales();
83  $supportedLocales = $site->getSupportedLocales();
84 
85  foreach ($localesToInstall as $locale) {
86  if (AppLocale::isLocaleValid($locale) && !in_array($locale, $installedLocales)) {
87  array_push($installedLocales, $locale);
88  // Activate/support by default.
89  if (!in_array($locale, $supportedLocales)) array_push($supportedLocales, $locale);
90  AppLocale::installLocale($locale);
91  }
92  }
93 
94  $site->setInstalledLocales($installedLocales);
95  $site->setSupportedLocales($supportedLocales);
96  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
97  $siteDao->updateObject($site);
98  }
99  }
100 }
PKPLocale\getAllLocales
static & getAllLocales()
Definition: PKPLocale.inc.php:537
InstallLanguageForm\readInputData
readInputData()
Definition: InstallLanguageForm.inc.php:63
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Form\setData
setData($key, $value=null)
Definition: Form.inc.php:229
Form\getData
getData($key)
Definition: Form.inc.php:220
InstallLanguageForm\fetch
fetch($request, $template=null, $display=false)
Definition: InstallLanguageForm.inc.php:45
InstallLanguageForm\__construct
__construct()
Definition: InstallLanguageForm.inc.php:24
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
InstallLanguageForm\execute
execute(... $functionArgs)
Definition: InstallLanguageForm.inc.php:74
PKPLocale\installLocale
static installLocale($locale)
Definition: PKPLocale.inc.php:557
InstallLanguageForm
Form for installing languages.
Definition: InstallLanguageForm.inc.php:19
Form\$supportedLocales
$supportedLocales
Definition: Form.inc.php:83
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PKPLocale\isLocaleValid
static isLocaleValid($locale)
Definition: PKPLocale.inc.php:505
InstallLanguageForm\initData
initData()
Definition: InstallLanguageForm.inc.php:34