From eba608682f381be989f343c5ab042d5e2c90967a Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 10 Jun 2016 11:56:06 +0200 Subject: * language select on profile page --- app/frontend/controls/LanguageSelect.php | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/frontend/controls/LanguageSelect.php (limited to 'app/frontend/controls/LanguageSelect.php') diff --git a/app/frontend/controls/LanguageSelect.php b/app/frontend/controls/LanguageSelect.php new file mode 100644 index 0000000..08cdcb7 --- /dev/null +++ b/app/frontend/controls/LanguageSelect.php @@ -0,0 +1,59 @@ +getControlState('user'); + } + + public function setUserToChange(DbUser $user) { + if ($user->IsGuest && !$this->Page->IsCallBack) { + throw new TInvalidDataValueException( + Prado::localize( + 'Language preference change impossible for guest user' + ) + ); + } + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Languages->DataSource = $this->_getLanguages(); + $this->Languages->DataValueField = 'Name'; + $this->Languages->DataTextField = 'Label'; + $this->Languages->dataBind(); + $this->Languages->setSelectedValue( + $this->Application->Globalization->getCulture() + ); + } + + public function saveLang($sender, $param) { + $this->getFacade()->setLanguagePreference( + $this->UserToChange, + $this->Languages->SelectedValue + ); + $this->Response->redirect($this->Service->constructUrl('Profile')); + } + + private function _getLanguages() { + $langs = array_map( + function($lang) { + return new LanguageDTO($lang); + }, + $this->Application->Globalization->getAllowedCultures() + ); + usort($langs, ['LanguageDTO', '__compare']); + return $langs; + } + +} + +?> -- cgit v1.2.3