/** * 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 object CRM_Mailing_BAO_Component object * * @access public * @static */ 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(); $component->id = $id; $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 && !empty($id)) { CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> {$id}"); } $component->save(); return $component; }
/** * 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; }
/** * Create and Update mailing component * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids (reference ) the array that holds all the db ids * * @return object CRM_Mailing_BAO_Component object * * @access public * @static */ static function add(&$params, &$ids) { // action is taken depending upon the mode $component = new CRM_Mailing_DAO_Component(); $component->name = $params['name']; $component->component_type = $params['component_type']; $component->subject = $params['subject']; if ($params['body_text']) { $component->body_text = $params['body_text']; } else { $component->body_text = CRM_Utils_String::htmlToText($params['body_html']); } $component->body_html = $params['body_html']; $component->is_active = CRM_Utils_Array::value('is_active', $params, FALSE); $component->is_default = CRM_Utils_Array::value('is_default', $params, FALSE); if ($component->is_default) { $query = "UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}'"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } $component->id = CRM_Utils_Array::value('id', $ids); $component->save(); CRM_Core_Session::setStatus(ts('The mailing component \'%1\' has been saved.', array(1 => $component->name)), ts('Saved'), 'success'); }