Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * Get all the mailing components of a particular type.
  *
  * @param $type
  *   The type of component needed.
  *
  * @return array
  *   array reference of all mailing components
  */
 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];
 }