BxDolEmailTemplatesQuery.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolDb');
  10. /**
  11. * Database queries for BxDolEmailTemplates object.
  12. * @see BxDolEmailTemplates
  13. */
  14. class BxDolEmailTemplatesQuery extends BxDolDb {
  15. public function __construct() {
  16. parent::__construct();
  17. }
  18. public function getTemplate ($sTemplateName, $iLangAccount, $iLangDefault, $iLangFallback) {
  19. // get email templates keys
  20. $sSql = $this->prepare("SELECT `Subject`, `Body` FROM `sys_email_templates` WHERE `Name`=? LIMIT 1", $sTemplateName);
  21. $a = $this->getRow($sSql);
  22. if (!$a)
  23. return false;
  24. // build languages idsto search for translation in
  25. $aLangs = array ($iLangAccount);
  26. if ($iLangDefault != $iLangAccount)
  27. $aLangs[] = $iLangDefault;
  28. if ($iLangFallback != $iLangAccount && $iLangFallback != $iLangDefault)
  29. $aLangs[] = $iLangFallback;
  30. // get translation for subject
  31. $sSubject = false;
  32. foreach ($aLangs as $iLang)
  33. if ($sSubject = $this->getLangTranslation($a['Subject'], $iLang))
  34. break;
  35. if (!$sSubject)
  36. return false;
  37. // get translation for body
  38. $sBody = false;
  39. foreach ($aLangs as $iLang)
  40. if ($sBody = $this->getLangTranslation($a['Body'], $iLang))
  41. break;
  42. if (!$sBody)
  43. return false;
  44. // return result
  45. return array ('Subject' => $sSubject, 'Body' => $sBody);
  46. }
  47. public function getLangTranslation ($sKey, $iLangId) {
  48. $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);
  49. return $this->getOne($sSql);
  50. }
  51. }
  52. /** @} */