BxDolStudioPolyglotKeys.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_PK_PREVIEW', 100);
  10. class BxDolStudioPolyglotKeys extends BxTemplStudioGrid
  11. {
  12. protected $iPreviewLength;
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. $this->oDb = new BxDolStudioPolyglotQuery();
  17. $this->iPreviewLength = BX_DOL_STUDIO_PK_PREVIEW;
  18. }
  19. protected function add(&$oForm)
  20. {
  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. $mixedResult = BxDolStudioLanguagesUtils::getInstance()->addLanguageString($sKey, $aStrings, 0, $iCategoryId);
  30. if($mixedResult === false)
  31. return _t('_adm_pgt_err_create_key');
  32. return $mixedResult;
  33. }
  34. protected function edit(&$oForm)
  35. {
  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. if(!BxDolStudioLanguagesUtils::getInstance()->updateLanguageStringById($iId, $aStrings))
  44. return _t('_adm_pgt_err_save');
  45. return $iId;
  46. }
  47. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  48. {
  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. /** @} */