copyValues($params); if ($component->find(TRUE)) { CRM_Core_DAO::storeValues($component, $defaults); return $component; } return NULL; } /** * Update the is_active flag in the db. * * @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 */ public static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Component', $id, 'is_active', $is_active); } /** * Create and Update mailing component. * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $ids * (deprecated) the array that holds all the db ids. * * @return CRM_Mailing_BAO_Component * */ public static function add(&$params, $ids = array()) { $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); $component = new CRM_Mailing_DAO_Component(); if ($id) { $component->id = $id; $component->find(TRUE); } $component->copyValues($params); if (empty($id) && empty($params['body_text'])) { $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params)); } if ($component->is_default) { if (!empty($id)) { $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2'; $sqlParams = array( 1 => array($component->component_type, 'String'), 2 => array($id, 'Positive'), ); } else { $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1'; $sqlParams = array( 1 => array($component->component_type, 'String'), ); } CRM_Core_DAO::executeQuery($sql, $sqlParams); } $component->save(); return $component; } }