Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
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 InstallLanguageForm($wizardMode = false) {
25  parent::Form('controllers/grid/languages/installLanguageForm.tpl');
26  }
27 
28  //
29  // Overridden methods from Form.
30  //
34  function initData($request) {
35  parent::initData($request);
36 
37  $site = $request->getSite();
38  $this->setData('installedLocales', $site->getInstalledLocales());
39  }
40 
44  function fetch($request) {
45  $site = $request->getSite();
46  $allLocales = AppLocale::getAllLocales();
47  $installedLocales = $this->getData('installedLocales');
48  $notInstalledLocales = array_diff(array_keys($allLocales), $installedLocales);
49 
50  $templateMgr = TemplateManager::getManager($request);
51  $templateMgr->assign('allLocales', $allLocales);
52  $templateMgr->assign('notInstalledLocales', $notInstalledLocales);
53 
54  import('classes.i18n.LanguageAction');
55  $languageAction = new LanguageAction();
56  if ($languageAction->isDownloadAvailable()) {
57  $downloadableLocales = $languageAction->getDownloadableLocales();
58  $downloadableLocaleLinks = array();
59 
60  import('lib.pkp.classes.linkAction.request.AjaxAction');
61  $router = $request->getRouter();
62  foreach ($downloadableLocales as $locale => $name) {
63  $downloadableLocaleLinks[$locale] = new LinkAction($locale,
64  new AjaxAction($router->url($request, null, null, 'downloadLocale', array('locale' => $locale))),
65  $name . ' (' . $locale . ')');
66  }
67 
68  $templateMgr->assign('downloadAvailable', true);
69  $templateMgr->assign('downloadableLocaleLinks', $downloadableLocaleLinks);
70  }
71 
72  return parent::fetch($request);
73  }
74 
78  function readInputData($request) {
79  parent::readInputData($request);
80 
81  $localesToInstall = $request->getUserVar('localesToInstall');
82  $this->setData('localesToInstall', $localesToInstall);
83  }
84 
88  function execute($request) {
89  $site = $request->getSite();
90  $localesToInstall = $this->getData('localesToInstall');
91 
92  if (isset($localesToInstall) && is_array($localesToInstall)) {
93  $installedLocales = $site->getInstalledLocales();
94  $supportedLocales = $site->getSupportedLocales();
95 
96  foreach ($localesToInstall as $locale) {
97  if (AppLocale::isLocaleValid($locale) && !in_array($locale, $installedLocales)) {
98  array_push($installedLocales, $locale);
99  // Activate/support by default.
100  if (!in_array($locale, $supportedLocales)) array_push($supportedLocales, $locale);
101  AppLocale::installLocale($locale);
102  }
103  }
104 
105  $site->setInstalledLocales($installedLocales);
106  $site->setSupportedLocales($supportedLocales);
107  $siteDao = DAORegistry::getDAO('SiteDAO');
108  $siteDao->updateObject($site);
109  }
110  }
111 }
112 
113 ?>
static & getDAO($name, $dbconn=null)
setData($key, $value)
Definition: Form.inc.php:219
static installLocale($locale)
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
getData($key)
Definition: Form.inc.php:210
static & getAllLocales()
LanguageAction class.
Class defining an AJAX action.
$supportedLocales
Definition: Form.inc.php:83
static isLocaleValid($locale)
Form for installing languages.
InstallLanguageForm($wizardMode=false)
Base class defining an action that can be performed by the user in the user interface.