You are here

function subscriptions_mail_template_load in Subscriptions 7

Same name and namespace in other branches
  1. 6 subscriptions_mail.templates.inc \subscriptions_mail_template_load()
  2. 2.0.x subscriptions_mail/subscriptions_mail.templates.inc \subscriptions_mail_template_load()

Retrieve a mail template, either from the mail_edit table or take our default template in this file, passing it through t().

Parameters

string $mailmod: The module requesting the template (part of the full mailkey).

string $mailkey: The mailkey, used with $mailmod as id in the {mail_edit} table.

string $langcode: The language code, used as language in the {mail_edit} table or for translating out default template.

string $part: Either 'subject' or 'body', used to indicate the column to retrieve from the {mail_edit} table.

string $key: The key for calling subscriptions_mail_template() to retrieve the default template, if there's no match in the {mail_edit} table.

File

./subscriptions_mail.templates.inc, line 122
Subscriptions module mail templates constants.

Code

function subscriptions_mail_template_load($mailmod, $mailkey, $langcode, $part, $key) {
  if (module_exists('mail_edit')) {
    $id = $mailmod . '_' . $mailkey;
    static $cache = array();
    if (!isset($cache[$langcode][$id])) {
      $query = db_select('mail_edit', 'me')
        ->fields('me')
        ->condition('me.id', $id)
        ->condition('me.language', $langcode);
      $cache[$langcode][$id] = $query
        ->execute()
        ->fetchObject();
    }
    if (isset($cache[$langcode][$id]->{$part})) {
      return $cache[$langcode][$id]->{$part};
    }
  }
  return subscriptions_mail_template($key, $langcode);
}