本文整理汇总了PHP中CRM_Core_BAO_Email::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Email::add方法的具体用法?PHP CRM_Core_BAO_Email::add怎么用?PHP CRM_Core_BAO_Email::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Email
的用法示例。
在下文中一共展示了CRM_Core_BAO_Email::add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHoldEmail
/**
* HoldEmail() method (set and reset on_hold condition)
*/
public function testHoldEmail()
{
$contactId = Contact::createIndividual();
$params = array();
$params = array('email' => 'jane.doe@example.com', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId);
CRM_Core_BAO_Email::add($params);
$emailId = $this->assertDBNotNull('CRM_Core_DAO_Email', 'jane.doe@example.com', 'id', 'email', 'Database check for created email address.');
// Now call add() to update on_hold=true and check record state
$params = array();
$params = array('id' => $emailId, 'contact_id' => $contactId, 'on_hold' => 1);
CRM_Core_BAO_Email::add($params);
// Use assertDBNotNull to get back value of hold_date and check if it's in the current year.
// NOTE: The assertEquals will fail IF this test is run just as the year is changing (low likelihood).
$holdDate = $this->assertDBNotNull('CRM_Core_DAO_Email', $emailId, 'hold_date', 'id', 'Retrieve hold_date from the updated email record.');
$this->assertEquals(substr($holdDate, 0, 4), substr(date('YmdHis'), 0, 4), 'Compare hold_date (' . $holdDate . ') in DB to current year.');
$this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 1, 'Check if on_hold=1 in updated email record.');
// Now call add() with on_hold=false and verify that reset_date is set.
$params = array();
$params = array('id' => $emailId, 'contact_id' => $contactId, 'on_hold' => 'null');
CRM_Core_BAO_Email::add($params);
$this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 0, 'Check if on_hold=0 in updated email record.');
$this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'hold_date', 'id', '', 'Check if hold_date has been set to empty string.');
// Use assertDBNotNull to get back value of reset_date and check if it's in the current year.
// NOTE: The assertEquals will fail IF this test is run just as the year is changing (low likelihood).
$resetDate = $this->assertDBNotNull('CRM_Core_DAO_Email', $emailId, 'reset_date', 'id', 'Retrieve reset_date from the updated email record.');
$this->assertEquals(substr($resetDate, 0, 4), substr(date('YmdHis'), 0, 4), 'Compare reset_date (' . $resetDate . ') in DB to current year.');
Contact::delete($contactId);
}
示例2: create
static function create($params)
{
if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) || empty($params['id'])) {
CRM_Core_BAO_Block::handlePrimary($params, get_class());
}
$email = CRM_Core_BAO_Email::add($params);
return $email;
}
示例3: create
/**
* Create email address - note that the create function calls 'add' but
* has more business logic
*
* @param array $params
* Input parameters.
*
* @return object
*/
public static function create($params)
{
// if id is set & is_primary isn't we can assume no change
if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) || empty($params['id'])) {
CRM_Core_BAO_Block::handlePrimary($params, get_class());
}
$email = CRM_Core_BAO_Email::add($params);
return $email;
}
示例4: testFindReferences
function testFindReferences()
{
$params = array('first_name' => 'Testy', 'last_name' => 'McScallion', 'contact_type' => 'Individual');
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertNotNull($contact->id);
$params = array('email' => 'spam@dev.null', 'contact_id' => $contact->id, 'is_primary' => 0, 'location_type_id' => 1);
$email = CRM_Core_BAO_Email::add($params);
$refs = $contact->findReferences();
$refsByTable = array();
foreach ($refs as $refObj) {
$refsByTable[$refObj->__table] = $refObj;
}
$this->assertTrue(array_key_exists('civicrm_email', $refsByTable));
$refDao = $refsByTable['civicrm_email'];
$refDao->find(TRUE);
$this->assertEquals($contact->id, $refDao->contact_id);
}
示例5: testTimestampsEmail
/**
* Ensure that civicrm_contact.modified_date is updated when manipulating a phone record.
*/
public function testTimestampsEmail()
{
$test = $this;
$this->_testTimestamps(array('INSERT' => function ($contactId) use($test) {
$params = array('email' => 'ex-1@example.com', 'is_primary' => 1, 'location_type_id' => 1, 'contact_id' => $contactId);
CRM_Core_BAO_Email::add($params);
$test->assertDBQuery('ex-1@example.com', 'SELECT email FROM civicrm_email WHERE contact_id = %1 ORDER BY id DESC LIMIT 1', array(1 => array($contactId, 'Integer')));
}, 'UPDATE' => function ($contactId) use($test) {
CRM_Core_DAO::executeQuery('UPDATE civicrm_email SET email = "ex-2@example.com" WHERE contact_id = %1', array(1 => array($contactId, 'Integer')));
}, 'DELETE' => function ($contactId) use($test) {
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_email WHERE contact_id = %1', array(1 => array($contactId, 'Integer')));
}));
}
示例6: mailchimpWebhookCleaned
/**
* Put a Mailchimp subscriber's email On Hold in CiviCRM.
*/
static function mailchimpWebhookCleaned($request_data)
{
$mailchimp_contact = CRM_CiviMailchimp_Utils::getContactInMailchimpListByEmail($request_data['email'], $request_data['list_id']);
foreach ($mailchimp_contact->email as $email) {
if ($email->email === $request_data['email']) {
// We have to go the circuitous route to saving so we can trigger
// CiviCRM's hooks to allow other extensions to act.
$params = array();
CRM_Core_DAO::storeValues($email, $params);
$params['on_hold'] = 1;
CRM_Core_BAO_Email::add($params);
}
}
}
示例7: add
/**
* takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
* @param array $locationId
*
* @return object CRM_Core_BAO_Location object on success, null otherwise
* @access public
* @static
*/
function add(&$params, &$ids, $locationId)
{
if (!CRM_Core_BAO_Location::dataExists($params, $locationId, $ids)) {
return null;
}
$location =& new CRM_Core_BAO_Location();
if (!isset($params['contact_id'])) {
require_once 'CRM/Core/BAO/Domain.php';
$location->entity_table = CRM_Core_BAO_Domain::getTableName();
$location->entity_id = $params['domain_id'];
} else {
$location->entity_table = CRM_Contact_BAO_Contact::getTableName();
$location->entity_id = $params['contact_id'];
}
$location->location_type_id = CRM_Utils_Array::value('location_type_id', $params['location'][$locationId]);
$location->name = CRM_Utils_Array::value('name', $params['location'][$locationId]);
$location->is_primary = CRM_Utils_Array::value('is_primary', $params['location'][$locationId], false);
// check if there exists another location has is_primary set, and if so reset that
// if no location has is_primary, make this one is_primart
if ($location->is_primary) {
// reset all other locations with the same entity table entity id
$sql = "UPDATE " . CRM_Core_BAO_Location::getTableName() . "\n SET is_primary = 0 WHERE \n entity_table = '{$location->entity_table}' AND\n entity_id = '{$location->entity_id}' ";
CRM_Core_DAO::executeQuery($sql);
} else {
// make sure there is at once location with is_primary set
$sql = "SELECT count( " . CRM_Core_BAO_Location::getTableName() . ".id )\n FROM " . CRM_Core_BAO_Location::getTableName() . " WHERE\n entity_table = '{$location->entity_table}' AND\n entity_id = '{$location->entity_id}' AND\n is_primary = 1";
$count = CRM_Core_DAO::singleValueQuery($sql);
if ($count == 0) {
$location->is_primary = true;
}
}
$location->id = CRM_Utils_Array::value('id', $ids['location'][$locationId]);
$location->save();
$params['location'][$locationId]['id'] = $location->id;
$address_object = CRM_Core_BAO_Address::add($params, $ids, $locationId);
$location->address = $address_object;
// set this to true if this has been made the primary IM.
// the rule is the first entered value is the primary object
$isPrimaryPhone = $isPrimaryEmail = $isPrimaryIM = true;
$location->phone = array();
$location->email = array();
$location->im = array();
for ($i = 1; $i <= CRM_CONTACT_FORM_LOCATION_BLOCKS; $i++) {
$location->phone[$i] = CRM_Core_BAO_Phone::add($params, $ids, $locationId, $i, $isPrimaryPhone);
$location->email[$i] = CRM_Core_BAO_Email::add($params, $ids, $locationId, $i, $isPrimaryEmail);
$location->im[$i] = CRM_Core_BAO_IM::add($params, $ids, $locationId, $i, $isPrimaryIM);
}
return $location;
}