Exemplo n.º 1
0
 /**
  * takes an associative array and adds email
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  *
  * @return object       CRM_Core_BAO_Email object on success, null otherwise
  * @access public
  * @static
  */
 static function add(&$params)
 {
     $email = new CRM_Core_DAO_Email();
     $email->copyValues($params);
     // CRM-11006 move calls to pre hook from create function to add function
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'Email', $params['id'], $email);
     } else {
         CRM_Utils_Hook::pre('create', 'Email', NULL, $e);
     }
     // lower case email field to optimize queries
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $email->email = $strtolower($email->email);
     // since we're setting bulkmail for 1 of this contact's emails, first reset all their emails to is_bulkmail false
     // (only 1 email address can have is_bulkmail = true)
     if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) {
         $sql = "\nUPDATE civicrm_email\nSET    is_bulkmail = 0\nWHERE  contact_id = {$params['contact_id']}\n";
         CRM_Core_DAO::executeQuery($sql);
     }
     // handle if email is on hold
     self::holdEmail($email);
     $email->save();
     // CRM-11006 move calls to pre hook from create function to add function
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Email', $email->id, $email);
     } else {
         CRM_Utils_Hook::post('create', 'Email', $email->id, $email);
     }
     return $email;
 }
Exemplo n.º 2
0
 /**
  * Takes an associative array and adds email.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return object
  *   CRM_Core_BAO_Email object on success, null otherwise
  */
 public static function add(&$params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'Email', CRM_Utils_Array::value('id', $params), $params);
     $email = new CRM_Core_DAO_Email();
     $email->copyValues($params);
     // lower case email field to optimize queries
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $email->email = $strtolower($email->email);
     /*
      * since we're setting bulkmail for 1 of this contact's emails, first reset all their other emails to is_bulkmail false
      *  We shouldn't not set the current email to false even though we
      *  are about to reset it to avoid contaminating the changelog if logging is enabled
      * (only 1 email address can have is_bulkmail = true)
      */
     if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) {
         $sql = "\nUPDATE civicrm_email\nSET    is_bulkmail = 0\nWHERE  contact_id = {$params['contact_id']}\n";
         if ($hook == 'edit') {
             $sql .= " AND id <> {$params['id']}";
         }
         CRM_Core_DAO::executeQuery($sql);
     }
     // handle if email is on hold
     self::holdEmail($email);
     $email->save();
     if ($email->is_primary) {
         // update the UF user email if that has changed
         CRM_Core_BAO_UFMatch::updateUFName($email->contact_id);
     }
     CRM_Utils_Hook::post($hook, 'Email', $email->id, $email);
     return $email;
 }
Exemplo n.º 3
0
 /**
  * takes an associative array and adds email
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  *
  * @return object       CRM_Core_BAO_Email object on success, null otherwise
  * @access public
  * @static
  */
 static function add(&$params)
 {
     $email = new CRM_Core_DAO_Email();
     $email->copyValues($params);
     // lower case email field to optimize queries
     $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
     $email->email = $strtolower($email->email);
     // since we're setting bulkmail for 1 of this contact's emails, first reset all their emails to is_bulkmail false
     // (only 1 email address can have is_bulkmail = true)
     if ($email->is_bulkmail != 'null' && $params['contact_id']) {
         $sql = "\nUPDATE civicrm_email \nSET is_bulkmail = 0\nWHERE \ncontact_id = {$params['contact_id']}";
         CRM_Core_DAO::executeQuery($sql);
     }
     // handle if email is on hold
     self::holdEmail($email);
     return $email->save();
 }