BxDolEmailTemplatesQuery.php 1.9 KB

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