BxDolStudioPolyglotKeys.php 3.6 KB

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