BxDolEmailTemplatesQuery.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 implements iBxDolSingleton
  15. {
  16. public static function getInstance()
  17. {
  18. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  19. $o = new BxDolEmailTemplatesQuery();
  20. $GLOBALS['bxDolClasses'][__CLASS__] = $o;
  21. }
  22. return $GLOBALS['bxDolClasses'][__CLASS__];
  23. }
  24. public function getTemplate ($sTemplateName, $iLangAccount, $iLangDefault, $iLangFallback)
  25. {
  26. // get email templates keys
  27. $sSql = $this->prepare("SELECT `Subject`, `Body` FROM `sys_email_templates` WHERE `Name`=? LIMIT 1", $sTemplateName);
  28. $a = $this->getRow($sSql);
  29. if (!$a)
  30. return false;
  31. // build languages idsto search for translation in
  32. $aLangs = array ($iLangAccount);
  33. if ($iLangDefault != $iLangAccount)
  34. $aLangs[] = $iLangDefault;
  35. if ($iLangFallback != $iLangAccount && $iLangFallback != $iLangDefault)
  36. $aLangs[] = $iLangFallback;
  37. // get translation for subject
  38. $sSubject = false;
  39. foreach ($aLangs as $iLang)
  40. if ($sSubject = $this->getLangTranslation($a['Subject'], $iLang))
  41. break;
  42. if (!$sSubject)
  43. return false;
  44. // get translation for body
  45. $sBody = false;
  46. foreach ($aLangs as $iLang)
  47. if ($sBody = $this->getLangTranslation($a['Body'], $iLang))
  48. break;
  49. if (!$sBody)
  50. return false;
  51. // return result
  52. return array ('Subject' => $sSubject, 'Body' => $sBody);
  53. }
  54. public function getLangTranslation ($sKey, $iLangId)
  55. {
  56. $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);
  57. return $this->getOne($sSql);
  58. }
  59. }
  60. /** @} */