BxBaseMenuSwitchLanguage.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Site main menu representation.
  11. */
  12. class BxBaseMenuSwitchLanguage extends BxTemplMenu
  13. {
  14. protected $_sType;
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. parent::__construct ($aObject, $oTemplate);
  18. $this->_sType = str_replace('sys_switch_language_', '', $this->_sObject);
  19. }
  20. public function getMenuItems ()
  21. {
  22. $this->loadData();
  23. return parent::getMenuItems();
  24. }
  25. protected function loadData()
  26. {
  27. $aLanguages = BxDolLanguagesQuery::getInstance()->getLanguages(false, true);
  28. if(empty($aLanguages) || !is_array($aLanguages) || count($aLanguages) < 2)
  29. return;
  30. $sLanguage = BxDolLanguages::getInstance()->getCurrentLangName();
  31. $this->setSelected('', $sLanguage);
  32. list($sPageLink, $aPageParams) = $this->{'getBaseUrl' . bx_gen_method_name($this->_sType)}();
  33. $oPermalink = BxDolPermalinks::getInstance();
  34. $sMethod = 'getItemTitle' . bx_gen_method_name($this->_sType);
  35. $aItems = array();
  36. foreach( $aLanguages as $sName => $sLang ) {
  37. $aPageParams['lang'] = $sName;
  38. $aItems[] = array(
  39. 'id' => $sName,
  40. 'name' => $sName,
  41. 'class' => '',
  42. 'title' => $this->$sMethod($sName, $sLang),
  43. 'target' => '_self',
  44. 'icon' => '',
  45. 'link' => bx_html_attribute($oPermalink->permalink(bx_append_url_params($sPageLink, $aPageParams))),
  46. 'onclick' => ''
  47. );
  48. }
  49. $this->_aObject['menu_items'] = $aItems;
  50. }
  51. protected function getBaseUrlPopup()
  52. {
  53. return bx_get_base_url_popup();
  54. }
  55. protected function getBaseUrlInline()
  56. {
  57. return bx_get_base_url_inline();
  58. }
  59. protected function getItemTitlePopup($sName, $sTitle)
  60. {
  61. return genFlag($sName) . ' ' . $sTitle;
  62. }
  63. protected function getItemTitleInline($sName, $sTitle)
  64. {
  65. return genFlag($sName);
  66. }
  67. }
  68. /** @} */