BxDevPolyglotManage.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModule');
  12. bx_import('BxTemplStudioGrid');
  13. class BxDevPolyglotManage extends BxTemplStudioGrid
  14. {
  15. private $sAllUri = 'all';
  16. private $aActions = array(
  17. 'restore' => 'eraser',
  18. 'recompile' => 'refresh'
  19. );
  20. protected $oModule;
  21. protected $aLanguage;
  22. function __construct($aOptions, $oTemplate = false)
  23. {
  24. parent::__construct($aOptions, $oTemplate);
  25. $this->oModule = BxDolModule::getInstance('bx_developer');
  26. bx_import('BxDolLanguages');
  27. $this->aLanguages = BxDolLanguages::getInstance()->getLanguages();
  28. $iWidth = floor(100 / (count($this->aLanguages) + 1));
  29. $this->_aOptions['fields']['title']['width'] = $iWidth;
  30. foreach($this->aLanguages as $sName => $sTitle)
  31. $this->_aOptions['fields'][$sName] = array(
  32. 'title' => $sTitle,
  33. 'width' => $iWidth,
  34. 'translatable' => '0',
  35. 'chars_limit' => '0'
  36. );
  37. }
  38. public function performActionRecompile()
  39. {
  40. bx_import('BxDolStudioLanguagesUtils');
  41. $aResult = array('msg' => _t(BxDolStudioLanguagesUtils::getInstance()->compileLanguage() ? '_adm_pgt_scs_recompiled' : '_adm_pgt_err_cannot_recompile_lang'));
  42. $this->_echoResultJson($aResult, true);
  43. }
  44. public function performActionRestore()
  45. {
  46. bx_import('BxDolStudioLanguagesUtils');
  47. $aResult = array('msg' => _t(BxDolStudioLanguagesUtils::getInstance()->restoreLanguage() ? '_adm_pgt_scs_restored' : '_adm_pgt_err_cannot_restore_lang'));
  48. $this->_echoResultJson($aResult, true);
  49. }
  50. protected function _getCellDefault($mixedValue, $sKey, $aField, $aRow)
  51. {
  52. $sJsObject = $this->oModule->_oConfig->getJsObject('polyglot');
  53. $aLangNames = array_keys($this->aLanguages);
  54. if(in_array($sKey, $aLangNames)) {
  55. $bAll = false;
  56. $aActions = array('restore');
  57. $sOnclickMask = "javascript:%s.%s('%s', '%s')";
  58. if($aRow['uri'] == $this->sAllUri) {
  59. $bAll = true;
  60. $aActions[] = 'recompile';
  61. $sOnclickMask = "javascript:%s.%s('%s')";
  62. }
  63. $mixedValue = '';
  64. foreach($aActions as $sAction) {
  65. $sIcon = $this->aActions[$sAction];
  66. $sTitle = _t('_bx_dev_pgt_txt_manage_' . $sAction . '_title' . ($bAll ? '_plur' : '_sing'));
  67. $sContent = _t('_bx_dev_pgt_txt_manage_' . $sAction);
  68. $mixedValue .= $this->_oTemplate->parseHtmlByName('bx_btn.html', array(
  69. 'title' => sprintf($sTitle, $aField['title'], $aRow['title']),
  70. 'bx_repeat:attrs' => array(
  71. array('key' => 'class', 'value' => 'bx-btn bx-def-margin-sec-left-auto'),
  72. array('key' => 'onclick', 'value' => sprintf($sOnclickMask, $sJsObject, $sAction, $sKey, $aRow['uri']))
  73. ),
  74. 'content' => $this->_oTemplate->parseHtmlByName('bx_icon.html', array('name' => $sIcon))
  75. ));
  76. }
  77. }
  78. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  79. }
  80. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  81. {
  82. $this->_aOptions['source'] .= " AND `name`<>'system'";
  83. $aData = array(
  84. array('id' => 0, 'title' => _t('_bx_dev_pgt_txt_manage_modules_all'), 'uri' => $this->sAllUri)
  85. );
  86. return array_merge($aData, parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage));
  87. }
  88. }
  89. /** @} */