/** * Get all the mailing components of a particular type * * @param $type the type of component needed * @access public * * @return array - array reference of all mailing components * @static */ public static function &component($type = NULL) { $name = $type ? $type : 'ALL'; if (!self::$component || !array_key_exists($name, self::$component)) { if (!self::$component) { self::$component = array(); } if (!$type) { self::$component[$name] = NULL; CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_DAO_Component'); } else { // we need to add an additional filter for $type self::$component[$name] = array(); $object = new CRM_Mailing_DAO_Component(); $object->component_type = $type; $object->selectAdd(); $object->selectAdd("id, name"); $object->orderBy('component_type, is_default, name'); $object->is_active = 1; $object->find(); while ($object->fetch()) { self::$component[$name][$object->id] = $object->name; } } } return self::$component[$name]; }
/** * 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; }
/** * adds $value['foo_display'] for each $value['foo'] enum from civicrm_mailing_component * * @param array $values (reference) the array up for enhancing * @return void */ static function addDisplayEnums(&$values) { $enumFields =& CRM_Mailing_DAO_Component::getEnums(); foreach ($enumFields as $enum) { if (isset($values[$enum])) { $values[$enum . '_display'] = CRM_Mailing_DAO_Component::tsEnum($enum, $values[$enum]); } } }
/** * 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; }
/** * class constructor */ function __construct() { parent::__construct(); }
/** * 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'); }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['mailing_component'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * class constructor */ function CRM_Mailing_BAO_Component() { parent::CRM_Mailing_DAO_Component(); }