* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-use Civi\Api4\Email;
use Civi\Api4\MessageTemplate;
use Civi\WorkflowMessage\WorkflowMessage;
/**
* Class CRM_Core_BAO_MessageTemplate.
*/
-class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implements \Civi\Test\HookInterface {
+class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implements \Civi\Core\HookInterface {
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Core_DAO_MessageTemplate
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $messageTemplates = new CRM_Core_DAO_MessageTemplate();
- $messageTemplates->copyValues($params);
- if ($messageTemplates->find(TRUE)) {
- CRM_Core_DAO::storeValues($messageTemplates, $defaults);
- return $messageTemplates;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
// send the template, honouring the target user’s preferences (if any)
$sent = FALSE;
if (!empty($params['toEmail'])) {
- // @todo - consider whether we really should be loading
- // this based on 'the first email in the db that matches'.
- // when we likely have the contact id. OTOH people probably barely
- // use preferredMailFormat these days - the good fight against html
- // emails was lost a decade ago...
- $preferredMailFormatArray = Email::get(FALSE)->addWhere('email', '=', $params['toEmail'])->addSelect('contact_id.preferred_mail_format')->execute()->first();
- $preferredMailFormat = $preferredMailFormatArray['contact_id.preferred_mail_format'] ?? 'Both';
-
- if ($preferredMailFormat === 'HTML') {
- $params['text'] = NULL;
- }
- if ($preferredMailFormat === 'Text') {
- $params['html'] = NULL;
- }
$config = CRM_Core_Config::singleton();
if ($isAttachPDF) {