BxDolStudioPolyglotKeys.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxTemplStudioGrid');
  10. bx_import('BxDolStudioTemplate');
  11. bx_import('BxDolStudioPolyglotQuery');
  12. define('BX_DOL_STUDIO_PK_PREVIEW', 100);
  13. class BxDolStudioPolyglotKeys extends BxTemplStudioGrid
  14. {
  15. protected $iPreviewLength;
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $this->oDb = new BxDolStudioPolyglotQuery();
  20. $this->iPreviewLength = BX_DOL_STUDIO_PK_PREVIEW;
  21. }
  22. protected function add(&$oForm)
  23. {
  24. $sKey = $oForm->getCleanValue('key');
  25. $iCategoryId = (int)$oForm->getCleanValue('category_id');
  26. $aLanguages = explode(',', $oForm->getCleanValue('languages'));
  27. if(empty($sKey) || empty($iCategoryId))
  28. return _t('_adm_pgt_err_create_key_empty_fields');
  29. $aStrings = array();
  30. foreach($aLanguages as $iLanguageId)
  31. $aStrings[$iLanguageId] = $oForm->getCleanValue('language_' . $iLanguageId);
  32. bx_import('BxDolStudioLanguagesUtils');
  33. $mixedResult = BxDolStudioLanguagesUtils::getInstance()->addLanguageString($sKey, $aStrings, 0, $iCategoryId);
  34. if($mixedResult === false)
  35. return _t('_adm_pgt_err_create_key');
  36. return $mixedResult;
  37. }
  38. protected function edit(&$oForm)
  39. {
  40. $iId = $oForm->getCleanValue('id');
  41. $aLanguages = explode(',', $oForm->getCleanValue('languages'));
  42. if(empty($iId) || empty($aLanguages))
  43. return _t('_adm_pgt_err_save');
  44. $aStrings = array();
  45. foreach($aLanguages as $iLanguageId)
  46. $aStrings[$iLanguageId] = $oForm->getCleanValue('language_' . $iLanguageId);
  47. bx_import('BxDolStudioLanguagesUtils');
  48. if(!BxDolStudioLanguagesUtils::getInstance()->updateLanguageStringById($iId, $aStrings))
  49. return _t('_adm_pgt_err_save');
  50. return $iId;
  51. }
  52. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  53. {
  54. $iModule = 0;
  55. if(strpos($sFilter, $this->sParamsDivider) !== false)
  56. list($iModule, $sFilter) = explode($this->sParamsDivider, $sFilter);
  57. $aLanguage = array();
  58. $iLanguage = $this->oDb->getLanguagesBy(array('type' => 'default'), $aLanguage);
  59. if($iLanguage <= 0 || empty($aLanguage)) {
  60. $aLanguages = array();
  61. $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'active'), $aLanguages);
  62. if($iLanguages <= 0 || empty($aLanguages))
  63. return array();
  64. $aLanguage = $aLanguages[0];
  65. }
  66. $this->_aOptions['source'] = sprintf($this->_aOptions['source'], $aLanguage['id']);
  67. if((int)$iModule != 0)
  68. $this->_aOptions['source'] .= $this->oDb->prepare(" AND `tlk`.`IDCategory`=?", $iModule);
  69. $aResults = parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  70. foreach($aResults as $iIndex => $aResult) {
  71. $aKey = $this->oDb->getKeyFullInfo($aResult['id'], $this->iPreviewLength);
  72. if(empty($aKey))
  73. continue;
  74. $aResults[$iIndex]['module'] = $aKey['module'];
  75. $aResults[$iIndex]['string'] = $aKey['strings'][$aLanguage['name']]['preview'];
  76. $aResults[$iIndex]['languages'] = implode(', ', array_keys($aKey['strings']));
  77. }
  78. return $aResults;
  79. }
  80. }
  81. /** @} */