BxDolEmailTemplatesQuery.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for BxDolEmailTemplates object.
  11. * @see BxDolEmailTemplates
  12. */
  13. class BxDolEmailTemplatesQuery extends BxDolDb implements iBxDolSingleton
  14. {
  15. public static function getInstance()
  16. {
  17. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  18. $o = new BxDolEmailTemplatesQuery();
  19. $GLOBALS['bxDolClasses'][__CLASS__] = $o;
  20. }
  21. return $GLOBALS['bxDolClasses'][__CLASS__];
  22. }
  23. public function getTemplate ($sTemplateName, $iLangAccount, $iLangDefault, $iLangFallback)
  24. {
  25. // get email templates keys
  26. $sSql = $this->prepare("SELECT `Subject`, `Body` FROM `sys_email_templates` WHERE `Name`=? LIMIT 1", $sTemplateName);
  27. $a = $this->getRow($sSql);
  28. if (!$a)
  29. return false;
  30. // build languages idsto search for translation in
  31. $aLangs = array ($iLangAccount);
  32. if ($iLangDefault != $iLangAccount)
  33. $aLangs[] = $iLangDefault;
  34. if ($iLangFallback != $iLangAccount && $iLangFallback != $iLangDefault)
  35. $aLangs[] = $iLangFallback;
  36. // get translation for subject
  37. $sSubject = false;
  38. foreach ($aLangs as $iLang)
  39. if ($sSubject = $this->getLangTranslation($a['Subject'], $iLang))
  40. break;
  41. if (!$sSubject)
  42. return false;
  43. // get translation for body
  44. $sBody = false;
  45. foreach ($aLangs as $iLang)
  46. if ($sBody = $this->getLangTranslation($a['Body'], $iLang))
  47. break;
  48. if (!$sBody)
  49. return false;
  50. // return result
  51. return array ('Subject' => $sSubject, 'Body' => $sBody);
  52. }
  53. public function getLangTranslation ($sKey, $iLangId)
  54. {
  55. $sSql = $this->prepare("SELECT `s`.`String` FROM `sys_localization_strings` as `s` INNER JOIN `sys_localization_keys` AS `k` ON (`s`.`IDKey` = `k`.`ID`) WHERE `k`.`Key` = ? AND `s`.`IDLanguage` = ? LIMIT 1", $sKey, $iLangId);
  56. return $this->getOne($sSql);
  57. }
  58. }
  59. /** @} */