3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_BAO_MailingComponent
extends CRM_Mailing_DAO_MailingComponent
{
20 * Retrieve DB object and copy to defaults array.
22 * @param array $params
23 * Array of criteria values.
24 * @param array $defaults
25 * Array to be populated with found values.
28 * The DAO object, if found.
32 public static function retrieve($params, &$defaults) {
33 return self
::commonRetrieve(self
::class, $params, $defaults);
37 * Update the is_active flag in the db.
40 * Id of the database record.
41 * @param bool $is_active
42 * Value we want to set the is_active field.
45 * true if we found and updated the object, else false
47 public static function setIsActive($id, $is_active) {
48 return CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_MailingComponent', $id, 'is_active', $is_active);
52 * Create and Update mailing component.
54 * @param array $params
55 * (reference ) an assoc array of name/value pairs.
57 * (deprecated) the array that holds all the db ids.
59 * @return CRM_Mailing_BAO_MailingComponent
61 public static function add(&$params, $ids = []) {
62 $id = $params['id'] ??
$ids['id'] ??
NULL;
63 $component = new CRM_Mailing_BAO_MailingComponent();
66 $component->find(TRUE);
69 $component->copyValues($params);
70 if (empty($id) && empty($params['body_text'])) {
71 $component->body_text
= CRM_Utils_String
::htmlToText(CRM_Utils_Array
::value('body_html', $params));
74 if ($component->is_default
) {
76 $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2';
78 1 => [$component->component_type
, 'String'],
79 2 => [$id, 'Positive'],
83 $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1';
85 1 => [$component->component_type
, 'String'],
88 CRM_Core_DAO
::executeQuery($sql, $sqlParams);