classes/manager/form/LanguageSettingsForm.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('form.Form');
00018 
00019 class LanguageSettingsForm extends Form {
00020 
00022    var $settings;
00023 
00025    var $availableLocales;
00026 
00030    function LanguageSettingsForm() {
00031       parent::Form('manager/languageSettings.tpl');
00032 
00033       $this->settings = array(
00034          'supportedLocales' => 'object',
00035          'supportedFormLocales' => 'object'
00036       );
00037 
00038       $site =& Request::getSite();
00039       $this->availableLocales = $site->getSupportedLocales();
00040 
00041       $localeCheck = create_function('$locale,$availableLocales', 'return in_array($locale,$availableLocales);');
00042 
00043       // Validation checks for this form
00044       $this->addCheck(new FormValidator($this, 'primaryLocale', 'required', 'manager.languages.form.primaryLocaleRequired'), array('AppLocale', 'isLocaleValid'));
00045       $this->addCheck(new FormValidator($this, 'primaryLocale', 'required', 'manager.languages.form.primaryLocaleRequired'), $localeCheck, array(&$this->availableLocales));
00046       $this->addCheck(new FormValidatorPost($this));
00047    }
00048 
00052    function display() {
00053       $templateMgr =& TemplateManager::getManager();
00054       $site =& Request::getSite();
00055       $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00056       $templateMgr->assign('helpTopicId','conference.generalManagement.languages');
00057       parent::display();
00058    }
00059 
00063    function initData() {
00064       $conference =& Request::getConference();
00065       foreach (array_keys($this->settings) as $settingName) {
00066          $this->_data[$settingName] = $conference->getSetting($settingName);
00067       }
00068 
00069       $this->setData('primaryLocale', $conference->getPrimaryLocale());
00070 
00071       foreach (array('supportedFormLocales', 'supportedLocales') as $name) {
00072          if ($this->getData($name) == null || !is_array($this->getData($name))) {
00073             $this->setData($name, array());
00074          }
00075       }
00076    }
00077 
00081    function readInputData() {
00082       $vars = array_keys($this->settings);
00083       $vars[] = 'primaryLocale';
00084       $this->readUserVars($vars);
00085 
00086       foreach (array('supportedFormLocales', 'supportedLocales') as $name) {
00087          if ($this->getData($name) == null || !is_array($this->getData($name))) {
00088             $this->setData($name, array());
00089          }
00090       }
00091    }
00092 
00096    function execute() {
00097       $conference =& Request::getConference();
00098       $settingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
00099 
00100       // Verify additional locales
00101       foreach (array('supportedLocales', 'supportedFormLocales') as $name) {
00102          $$name = array();
00103          foreach ($this->getData($name) as $locale) {
00104             if (AppLocale::isLocaleValid($locale) && in_array($locale, $this->availableLocales)) {
00105                array_push($$name, $locale);
00106             }
00107          }
00108       }
00109 
00110       $primaryLocale = $this->getData('primaryLocale');
00111 
00112       // Make sure at least the primary locale is chosen as available
00113       if ($primaryLocale != null && !empty($primaryLocale)) {
00114          foreach (array('supportedLocales', 'supportedFormLocales') as $name) {
00115             if (!in_array($primaryLocale, $$name)) {
00116                array_push($$name, $primaryLocale);
00117             }
00118          }
00119       }
00120       $this->setData('supportedLocales', $supportedLocales);
00121       $this->setData('supportedFormLocales', $supportedFormLocales);
00122 
00123       foreach ($this->_data as $name => $value) {
00124          if (!in_array($name, array_keys($this->settings))) continue;
00125          $settingsDao->updateSetting(
00126             $conference->getId(),
00127             $name,
00128             $value,
00129             $this->settings[$name]
00130          );
00131       }
00132 
00133       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00134       $conference->setPrimaryLocale($this->getData('primaryLocale'));
00135       $conferenceDao->updateConference($conference);
00136    }
00137 }
00138 
00139 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7