本文整理汇总了PHP中CRM_Utils_Hook::alterMailContent方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Hook::alterMailContent方法的具体用法?PHP CRM_Utils_Hook::alterMailContent怎么用?PHP CRM_Utils_Hook::alterMailContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Hook
的用法示例。
在下文中一共展示了CRM_Utils_Hook::alterMailContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendTemplate
/**
* Send an email from the specified template based on an array of params.
*
* @param array $params
* A string-keyed array of function params, see function body for details.
*
* @return array
* Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
public static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$mailContent = array('subject' => $dao->subject, 'text' => $dao->text, 'html' => $dao->html, 'format' => $dao->format);
$dao->free();
CRM_Utils_Hook::alterMailContent($mailContent);
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$mailContent['subject'] = $testDao->subject . $mailContent['subject'];
$mailContent['text'] = $testDao->text . $mailContent['text'];
$mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $mailContent['html']);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->subject = $mailContent['subject'];
$mailing->body_text = $mailContent['text'];
$mailing->body_html = $mailContent['html'];
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['subject']['contact'])) {
foreach ($tokens['subject']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
// @todo CRM-17253 don't resolve contact details if there are no tokens
// effectively comment out this next (performance-expensive) line
// but unfortunately testing is a bit think on the ground to that needs to
// be added.
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
//.........这里部分代码省略.........
示例2: array
/**
* Retrieve a ref to an array that holds the email and text templates for this email
* assembles the complete template including the header and footer
* that the user has uploaded or declared (if they have dome that)
*
* @return array
* reference to an assoc array
*/
private function &getTemplates()
{
if (!$this->templates) {
$this->getHeaderFooter();
$this->templates = array();
if ($this->body_text || !empty($this->header)) {
$template = array();
if (!empty($this->header->body_text)) {
$template[] = $this->header->body_text;
} elseif (!empty($this->header->body_html)) {
$template[] = CRM_Utils_String::htmlToText($this->header->body_html);
}
if ($this->body_text) {
$template[] = $this->body_text;
} else {
$template[] = CRM_Utils_String::htmlToText($this->body_html);
}
if (!empty($this->footer->body_text)) {
$template[] = $this->footer->body_text;
} elseif (!empty($this->footer->body_html)) {
$template[] = CRM_Utils_String::htmlToText($this->footer->body_html);
}
$this->templates['text'] = implode("\n", $template);
}
if ($this->body_html) {
$template = array();
if ($this->header) {
$template[] = $this->header->body_html;
}
$template[] = $this->body_html;
if ($this->footer) {
$template[] = $this->footer->body_html;
}
$this->templates['html'] = implode("\n", $template);
// this is where we create a text template from the html template if the text template did not exist
// this way we ensure that every recipient will receive an email even if the pref is set to text and the
// user uploads an html email only
if (empty($this->templates['text'])) {
$this->templates['text'] = CRM_Utils_String::htmlToText($this->templates['html']);
}
}
if ($this->subject) {
$template = array();
$template[] = $this->subject;
$this->templates['subject'] = implode("\n", $template);
}
CRM_Utils_Hook::alterMailContent($this->templates);
}
return $this->templates;
}