<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
/**
* Fetch object based on array of properties
*
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param array $defaults (reference ) an assoc array to hold the flattened values
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
+ * @param array $defaults
+ * (reference ) an assoc array to hold the flattened values.
*
- * @return CRM_Core_BAO_MessageTemplate object
- * @access public
- * @static
+ * @return CRM_Core_BAO_MessageTemplate
*/
- static function retrieve(&$params, &$defaults) {
+ public static function retrieve(&$params, &$defaults) {
$messageTemplates = new CRM_Core_DAO_MessageTemplate();
$messageTemplates->copyValues($params);
if ($messageTemplates->find(TRUE)) {
/**
* Update the is_active flag in the db
*
- * @param int $id id of the database record
- * @param boolean $is_active value we want to set the is_active field
+ * @param int $id
+ * Id of the database record.
+ * @param bool $is_active
+ * Value we want to set the is_active field.
*
- * @return Object DAO object on sucess, null otherwise
- * @static
+ * @return Object
+ * DAO object on sucess, NULL otherwise
*/
- static function setIsActive($id, $is_active) {
+ public static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_MessageTemplate', $id, 'is_active', $is_active);
}
/**
* Add the Message Templates
*
- * @param array $params reference array contains the values submitted by the form
+ * @param array $params
+ * Reference array contains the values submitted by the form.
*
- * @access public
- * @static
*
* @return object
*/
- static function add(&$params) {
+ public static function add(&$params) {
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'MessageTemplate', CRM_Utils_Array::value('id', $params), $params);
/**
* Delete the Message Templates
*
- * @access public
- * @static
- *
* @param int $messageTemplatesID
- *
- * @return object
+ * @return void
*/
- static function del($messageTemplatesID) {
+ public static function del($messageTemplatesID) {
// make sure messageTemplatesID is an integer
if (!CRM_Utils_Rule::positiveInteger($messageTemplatesID)) {
CRM_Core_Error::fatal(ts('Invalid Message template'));
/**
* Get the Message Templates
*
- * @access public
- * @static
*
* @param bool $all
*
* @return object
*/
- static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
+ public static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
$msgTpls = array();
$messageTemplates = new CRM_Core_DAO_MessageTemplate();
* @param int $messageTemplateID
* @param $from
*
- * @return bool|null
+ * @return bool|NULL
*/
- static function sendReminder($contactId, $email, $messageTemplateID, $from) {
+ public static function sendReminder($contactId, $email, $messageTemplateID, $from) {
$messageTemplates = new CRM_Core_DAO_MessageTemplate();
$messageTemplates->id = $messageTemplateID;
- $domain = CRM_Core_BAO_Domain::getDomain();
- $result = NULL;
+ $domain = CRM_Core_BAO_Domain::getDomain();
+ $result = NULL;
$hookTokens = array();
if ($messageTemplates->find(TRUE)) {
- $body_text = $messageTemplates->msg_text;
- $body_html = $messageTemplates->msg_html;
+ $body_text = $messageTemplates->msg_text;
+ $body_html = $messageTemplates->msg_html;
$body_subject = $messageTemplates->msg_subject;
if (!$body_text) {
$body_text = CRM_Utils_String::htmlToText($body_html);
// get tokens to be replaced
$tokens = array_merge(CRM_Utils_Token::getTokens($body_text),
- CRM_Utils_Token::getTokens($body_html),
- CRM_Utils_Token::getTokens($body_subject));
+ CRM_Utils_Token::getTokens($body_html),
+ CRM_Utils_Token::getTokens($body_subject));
// get replacement text for these tokens
$returnProperties = array("preferred_mail_format" => 1);
}
}
list($details) = CRM_Utils_Token::getTokenDetails(array($contactId),
- $returnProperties,
- null, null, false,
- $tokens,
- 'CRM_Core_BAO_MessageTemplate');
- $contact = reset( $details );
+ $returnProperties,
+ NULL, NULL, FALSE,
+ $tokens,
+ 'CRM_Core_BAO_MessageTemplate');
+ $contact = reset($details);
// call token hook
$hookTokens = array();
$bodyType = "body_{$value}";
if ($$bodyType) {
CRM_Utils_Token::replaceGreetingTokens($$bodyType, NULL, $contact['contact_id']);
- $$bodyType = CRM_Utils_Token::replaceDomainTokens($$bodyType, $domain, true, $tokens, true);
- $$bodyType = CRM_Utils_Token::replaceContactTokens($$bodyType, $contact, false, $tokens, false, true);
- $$bodyType = CRM_Utils_Token::replaceComponentTokens($$bodyType, $contact, $tokens, true);
- $$bodyType = CRM_Utils_Token::replaceHookTokens($$bodyType, $contact , $categories, true);
+ $$bodyType = CRM_Utils_Token::replaceDomainTokens($$bodyType, $domain, TRUE, $tokens, TRUE);
+ $$bodyType = CRM_Utils_Token::replaceContactTokens($$bodyType, $contact, FALSE, $tokens, FALSE, TRUE);
+ $$bodyType = CRM_Utils_Token::replaceComponentTokens($$bodyType, $contact, $tokens, TRUE);
+ $$bodyType = CRM_Utils_Token::replaceHookTokens($$bodyType, $contact, $categories, TRUE);
}
}
$html = $body_html;
$smarty = CRM_Core_Smarty::singleton();
foreach (array(
- 'text', 'html') as $elem) {
+ 'text',
+ 'html',
+ ) as $elem) {
$$elem = $smarty->fetch("string:{$$elem}");
}
// do replacements in message subject
- $messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, false, $tokens);
- $messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, true, $tokens);
- $messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $tokens, true);
- $messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, true);
+ $messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, FALSE, $tokens);
+ $messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, TRUE, $tokens);
+ $messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $tokens, TRUE);
+ $messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, TRUE);
$messageSubject = $smarty->fetch("string:{$messageSubject}");
}
if ($html && ($contact['preferred_mail_format'] == 'HTML' ||
$contact['preferred_mail_format'] == 'Both'
- )) {
+ )
+ ) {
$mailParams['html'] = $html;
}
/**
* Revert a message template to its default subject+text+HTML state
*
- * @param integer id id of the template
+ * @param int $id id of the template
*
* @return void
*/
- static function revert($id) {
- $diverted = new self;
+ public static function revert($id) {
+ $diverted = new CRM_Core_BAO_MessageTemplate();
$diverted->id = (int) $id;
$diverted->find(1);
CRM_Core_Error::fatal(ts('Did not find a message template with id of %1.', array(1 => $id)));
}
- $orig = new self;
+ $orig = new CRM_Core_BAO_MessageTemplate();
$orig->workflow_id = $diverted->workflow_id;
$orig->is_reserved = 1;
$orig->find(1);
/**
* 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
+ * @param array $params
+ * A string-keyed array of function params, see function body for details.
*
- * @return array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
+ * @return array
+ * Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
- static function sendTemplate($params) {
+ public static function sendTemplate($params) {
$defaults = array(
// option group name of the template
'groupName' => NULL,
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'])));
+ CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(
+ 1 => $params['groupName'],
+ 2 => $params['valueName'],
+ )));
}
}
$subject = $dao->subject;
- $text = $dao->text;
- $html = $dao->html;
- $format = $dao->format;
+ $text = $dao->text;
+ $html = $dao->html;
+ $format = $dao->format;
$dao->free();
// add the test banner (if requested)
$testDao->fetch();
$subject = $testDao->subject . $subject;
- $text = $testDao->text . $text;
- $html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
+ $text = $testDao->text . $text;
+ $html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $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;
+ $domain = CRM_Core_BAO_Domain::getDomain();
+ $hookTokens = array();
+ $mailing = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
- $tokens = $mailing->getTokens();
+ $tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
}
$subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, FALSE, $tokens['text'], TRUE);
- $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text'], TRUE);
- $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
+ $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text'], TRUE);
+ $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE);
- $text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
- $html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
-
+ $text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
+ $html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray,
$contact = $contactArray[$contactID];
$subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE);
- $text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
- $html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
+ $text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
+ $html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
}
// strip whitespace from ends and turn into a single line
$subject = "{strip}$subject{/strip}";
// parse the three elements with Smarty
-
-
$smarty = CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
foreach (array(
- 'subject', 'text', 'html') as $elem) {
+ 'subject',
+ 'text',
+ 'html',
+ ) as $elem) {
$$elem = $smarty->fetch("string:{$$elem}");
}
// create the params array
$params['subject'] = $subject;
- $params['text'] = $text;
- $params['html'] = $html;
+ $params['text'] = $text;
+ $params['html'] = $html;
if ($params['toEmail']) {
$contactParams = array(array('email', 'LIKE', $params['toEmail'], 0, 1));
if (empty($params['attachments'])) {
$params['attachments'] = array();
}
- $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $format) ;
+ $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $format);
}
$pdf_filename = '';
if ($config->doNotAttachPDFReceipt &&