* @access public
* @static
*/
- static function add(&$params, &$ids = array()) {
- // action is taken depending upon the mode
+ 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->name = $params['name'];
- $component->component_type = CRM_Utils_Array::value('component_type', $params);
- $component->subject = CRM_Utils_Array::value('subject', $params);
- if (CRM_Utils_Array::value('body_text', $params)) {
- $component->body_text = CRM_Utils_Array::value('body_text', $params);
- }
- else {
+ $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));
}
- $component->body_html = CRM_Utils_Array::value('body_html', $params);
- $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);
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type ='{$component->component_type}' AND id <> $id");
}
- $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');
+ return $component;
}
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
- $ids = array();
-
if ($this->_action & CRM_Core_Action::UPDATE) {
- $ids['id'] = $this->_id;
+ $params['id'] = $this->_id;
}
- CRM_Mailing_BAO_Component::add($params, $ids);
+ $component = CRM_Mailing_BAO_Component::add($params);
+ CRM_Core_Session::setStatus(ts('The mailing component \'%1\' has been saved.', array(
+ 1 => $component->name
+ )
+ ), ts('Saved'), 'success');
+
}
//end of function