/** * Takes a bunch of params that are needed to match certain criteria and * retrieves the relevant objects. Typically the valid params are only * contact_id. We'll tweak this function to be more full featured over a period * of time. This is the inverse function of create. It also stores all the retrieved * values in the default array * * @param array $params (reference ) an assoc array of name/value pairs * @param array $defaults (reference ) an assoc array to hold the flattened values * * @return object CRM_Core_BAO_LocaationType object * @access public * @static */ static function retrieve(&$params, &$defaults) { $component = new CRM_Mailing_DAO_Component(); $component->copyValues($params); if ($component->find(TRUE)) { CRM_Core_DAO::storeValues($component, $defaults); return $component; } return NULL; }
/** * 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 (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; }