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 boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * @static */ 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 (reference ) the array that holds all the db ids * * @return object CRM_Mailing_BAO_Component object * * @access public * @static */ static function add(&$params, &$ids = array()) { // action is taken depending upon the mode $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->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); } $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'); } }