summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-06-10 11:56:06 +0200
committeremkael <emkael@tlen.pl>2016-06-10 11:56:06 +0200
commiteba608682f381be989f343c5ab042d5e2c90967a (patch)
treee3542667c133d5df641c3ae86be234912b9676f1
parentb295cc96cf16fd025385bc2009ab29223d7c90fd (diff)
* language select on profile page
-rw-r--r--app/frontend/controls/LanguageSelect.php59
-rw-r--r--app/frontend/controls/LanguageSelect.tpl5
-rw-r--r--app/frontend/pages/Profile.page5
3 files changed, 69 insertions, 0 deletions
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 @@
+<?php
+
+Prado::using('Application.web.FacadeTemplateControl');
+
+Prado::using('Application.user.DbUser');
+Prado::using('Application.facades.UserFacade');
+
+Prado::using('Application.dto.LanguageDTO');
+
+class LanguageSelect extends FacadeTemplateControl {
+
+ public function getUserToChange() {
+ return $this->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;
+ }
+
+}
+
+?>
diff --git a/app/frontend/controls/LanguageSelect.tpl b/app/frontend/controls/LanguageSelect.tpl
new file mode 100644
index 0000000..d83f703
--- /dev/null
+++ b/app/frontend/controls/LanguageSelect.tpl
@@ -0,0 +1,5 @@
+<com:TDropDownList ID="Languages" />
+<com:TButton
+ OnCommand="saveLang">
+ <prop:Text><%[ Save language ]%></prop:Text>
+</com:TButton>
diff --git a/app/frontend/pages/Profile.page b/app/frontend/pages/Profile.page
index 163d3fa..0d531cf 100644
--- a/app/frontend/pages/Profile.page
+++ b/app/frontend/pages/Profile.page
@@ -9,6 +9,11 @@
<prop:UserToChange><%= $this->User %></prop:UserToChange>
</com:TimezoneSelect>
<br />
+ <com:LanguageSelect>
+ <prop:Facade><%= UserFacade::getInstance() %></prop:Facade>
+ <prop:UserToChange><%= $this->User %></prop:UserToChange>
+ </com:LanguageSelect>
+ <br />
<com:UserSelection>
<prop:UserToDisplay><%= $this->User %></prop:UserToDisplay>
<prop:Facade><%= CalendarFacade::getInstance() %></prop:Facade>