1
0

BxDolStudioPolyglotKeys.php 3.6 KB

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