BxDevPolyglotManage.php 3.6 KB

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