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 * Fetch object based on array of properties.
22 * @param array $params
23 * (reference ) an assoc array of name/value pairs.
24 * @param array $defaults
25 * (reference ) an assoc array to hold the flattened values.
27 * @return CRM_Core_BAO_LocationType.
29 public static function retrieve(&$params, &$defaults) {
30 $component = new CRM_Mailing_DAO_MailingComponent();
31 $component->copyValues($params);
32 if ($component->find(TRUE)) {
33 CRM_Core_DAO
::storeValues($component, $defaults);
40 * Update the is_active flag in the db.
43 * Id of the database record.
44 * @param bool $is_active
45 * Value we want to set the is_active field.
48 * true if we found and updated the object, else false
50 public static function setIsActive($id, $is_active) {
51 return CRM_Core_DAO
::setFieldValue('CRM_Mailing_DAO_MailingComponent', $id, 'is_active', $is_active);
55 * Create and Update mailing component.
57 * @param array $params
58 * (reference ) an assoc array of name/value pairs.
60 * (deprecated) the array that holds all the db ids.
62 * @return CRM_Mailing_BAO_MailingComponent
64 public static function add(&$params, $ids = []) {
65 $id = $params['id'] ??
$ids['id'] ??
NULL;
66 $component = new CRM_Mailing_BAO_MailingComponent();
69 $component->find(TRUE);
72 $component->copyValues($params);
73 if (empty($id) && empty($params['body_text'])) {
74 $component->body_text
= CRM_Utils_String
::htmlToText(CRM_Utils_Array
::value('body_html', $params));
77 if ($component->is_default
) {
79 $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2';
81 1 => [$component->component_type
, 'String'],
82 2 => [$id, 'Positive'],
86 $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1';
88 1 => [$component->component_type
, 'String'],
91 CRM_Core_DAO
::executeQuery($sql, $sqlParams);