+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate {
/**
- * Fetch object based on array of properties
+ * 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.
*
- * @return CRM_Core_BAO_MessageTemplate object
- * @static
+ * @return CRM_Core_BAO_MessageTemplate
*/
public static function retrieve(&$params, &$defaults) {
$messageTemplates = new CRM_Core_DAO_MessageTemplate();
}
/**
- * Update the is_active flag in the db
+ * Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
* Value we want to set the is_active field.
*
* @return Object
- * DAO object on sucess, NULL otherwise
- * @static
+ * DAO object on success, NULL otherwise
*/
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
+ * Add the Message Templates.
*
* @param array $params
* Reference array contains the values submitted by the form.
*
- * @static
*
* @return object
*/
}
/**
- * Delete the Message Templates
- *
- * @static
+ * Delete the Message Templates.
*
* @param int $messageTemplatesID
- *
- * @return object
+ * @return void
*/
public static function del($messageTemplatesID) {
// make sure messageTemplatesID is an integer
}
/**
- * Get the Message Templates
+ * Get the Message Templates.
*
- * @static
*
* @param bool $all
*
$smarty = CRM_Core_Smarty::singleton();
foreach (array(
'text',
- 'html'
+ 'html',
) as $elem) {
$$elem = $smarty->fetch("string:{$$elem}");
}
/**
* Revert a message template to its default subject+text+HTML state
*
- * @param int id id of the template
+ * @param int $id id of the template
*
* @return void
*/
public static function revert($id) {
- $diverted = new self;
+ $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
+ * 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
- * of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
+ * 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(
else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(
1 => $params['groupName'],
- 2 => $params['valueName']
+ 2 => $params['valueName'],
)));
}
}
// 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 = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
$tokens = $mailing->getTokens();
$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,
array($contactID),
$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'
+ 'html',
) as $elem) {
$$elem = $smarty->fetch("string:{$$elem}");
}
return array($sent, $subject, $text, $html);
}
+
}