本文整理汇总了PHP中CRM_Contact_BAO_Contact::getTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Contact::getTableName方法的具体用法?PHP CRM_Contact_BAO_Contact::getTableName怎么用?PHP CRM_Contact_BAO_Contact::getTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Contact
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Contact::getTableName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: array
/**
* Register a subscription event. Create a new contact if one does not
* already exist.
*
* @param int $domain_id The domain id of the new subscription
* @param int $group_id The group id to subscribe to
* @param string $email The email address of the (new) contact
* @return int|null $se_id The id of the subscription event, null on failure
* @access public
* @static
*/
function &subscribe($domain_id, $group_id, $email)
{
/* First, find out if the contact already exists */
$params = array('email' => $email, 'domain_id' => $domain_id);
require_once 'CRM/Core/BAO/UFGroup.php';
$contact_id = CRM_Core_BAO_UFGroup::findContact($params);
CRM_Core_DAO::transaction('BEGIN');
if (is_a($contact_id, CRM_Core_Error)) {
require_once 'CRM/Core/BAO/LocationType.php';
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual');
$value = array('email' => $email, 'location_type' => CRM_Core_BAO_LocationType::getDefaultID());
_crm_add_formatted_param($value, $formatted);
$contact =& crm_create_contact_formatted($formatted, CRM_IMPORT_PARSER_DUPLICATE_SKIP);
if (is_a($contact, CRM_Core_Error)) {
return null;
}
$contact_id = $contact->id;
}
require_once 'CRM/Core/BAO/Email.php';
require_once 'CRM/Core/BAO/Location.php';
require_once 'CRM/Contact/BAO/Contact.php';
/* Get the primary email id from the contact to use as a hash input */
$dao =& new CRM_Core_DAO();
$emailTable = CRM_Core_BAO_Email::getTableName();
$locTable = CRM_Core_BAO_Location::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$dao->query("SELECT {$emailTable}.id as email_id\n FROM {$emailTable}\n INNER JOIN {$locTable}\n ON {$emailTable}.location_id = {$locTable}.id\n WHERE {$emailTable}.is_primary = 1\n AND {$locTable}.is_primary = 1\n AND {$locTable}.entity_table = '{$contactTable}'\n AND {$locTable}.entity_id = " . CRM_Utils_Type::escape($contact_id, 'Integer'));
$dao->fetch();
$se =& new CRM_Mailing_Event_BAO_Subscribe();
$se->group_id = $group_id;
$se->contact_id = $contact_id;
$se->time_stamp = date('YmdHis');
$se->hash = sha1("{$group_id}:{$contact_id}:{$dao->email_id}");
$se->save();
$contacts = array($contact_id);
require_once 'CRM/Contact/BAO/GroupContact.php';
CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id);
CRM_Core_DAO::transaction('COMMIT');
return $se;
}
示例3: getGroupContacts
/**
* Returns array of contacts who are members of the specified group.
*
* @param CRM_Contact $group A valid group object (passed by reference)
* @param array $returnProperties Which properties
* should be included in the returned Contact object(s). If NULL,
* the default set of contact properties will be
* included. group_contact properties (such as 'status',
* ' in_date', etc.) are included automatically.Note:Do not inclue
* Id releted properties.
* @param text $status A valid status value ('Added', 'Pending', 'Removed').
* @param text $sort Associative array of
* one or more "property_name"=>"sort direction"
* pairs which will control order of Contact objects returned.
* @param Int $offset Starting row index.
* @param Int $row_count Maximum number of rows to returns.
*
*
* @return $contactArray Array of contacts who are members of the specified group
*
* @access public
*/
static function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null, $includeChildGroups = false)
{
$groupDAO =& new CRM_Contact_DAO_Group();
$groupDAO->id = $group->id;
if (!$groupDAO->find(true)) {
return CRM_Core_Error::createError("Could not locate group with id: {$id}");
}
// make sure user has got permission to view this group
require_once 'CRM/Contact/BAO/Group.php';
if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
}
$query = '';
if (empty($returnProperties)) {
$query = "SELECT contact_a.id as contact_id,\n civicrm_email.email as email";
} else {
$query = "SELECT contact_a.id as contact_id , {$grpStatus} as status,";
$query .= implode(',', $returnProperties);
}
$params = array();
if ($includeChildGroups) {
require_once 'CRM/Contact/BAO/GroupNesting.php';
$groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds(array($group->id));
} else {
$groupIds = array($group->id);
}
foreach ($groupIds as $groupId) {
$params[] = array('group', 'IN', array($group->id => true), 0, 0);
}
require_once 'CRM/Core/BAO/Email.php';
require_once 'CRM/Contact/BAO/Contact.php';
$tables = array(CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true);
$inner = array();
$whereTables = array();
$where = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
$permission = CRM_Core_Permission::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
$from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
$query .= " {$from} WHERE {$permission} AND {$where} ";
if ($sort != null) {
$order = array();
foreach ($sort as $key => $direction) {
$order[] = " {$key} {$direction} ";
}
$query .= " ORDER BY " . implode(',', $order);
}
if (!is_null($offset) && !is_null($row_count)) {
$query .= " LIMIT {$offset}, {$row_count}";
}
$dao =& new CRM_Contact_DAO_Contact();
$dao->query($query);
// this is quite inefficient, we need to change the return
// values in docs
$contactArray = array();
while ($dao->fetch()) {
$contactArray[] = clone $dao;
}
return $contactArray;
}
示例4: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param boolean $is_distinct Group by queue id?
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
* @return array Result set
* @access public
* @static
*/
function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
{
$dao =& new CRM_Core_Dao();
$bounce = CRM_Mailing_Event_BAO_Bounce::getTableName();
$bounceType = CRM_Mailing_DAO_BounceType::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$bounce}.time_stamp as date,\n {$bounce}.bounce_reason as reason,\n {$bounceType}.name as bounce_type\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$bounce}\n ON {$bounce}.event_queue_id = {$queue}.id\n LEFT JOIN {$bounceType}\n ON {$bounce}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$query .= " ORDER BY {$contact}.sort_name, {$bounce}.time_stamp ";
if ($offset) {
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例5: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param boolean $is_distinct Group by queue id?
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
* @return array Result set
* @access public
* @static
*/
public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
{
$dao =& new CRM_Core_Dao();
$unsub = self::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$unsub}.time_stamp as date,\n {$unsub}.org_unsubscribe as org_unsubscribe\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$unsub}\n ON {$unsub}.event_queue_id = {$queue}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$query .= " ORDER BY {$contact}.sort_name, {$unsub}.time_stamp DESC ";
if ($offset) {
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'org' => $dao->org_unsubscribe ? ts('Yes') : ts('No'), 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例6: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param boolean $is_distinct Group by queue id?
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
* @return array Result set
* @access public
* @static
*/
public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
{
$dao =& new CRM_Core_Dao();
$forward = self::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$query = "\n SELECT {$contact}.display_name as from_name,\n {$contact}.id as from_id,\n {$email}.email as from_email,\n dest_contact.id as dest_id,\n dest_email.email as dest_email,\n {$forward}.time_stamp as date\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$forward}\n ON {$forward}.event_queue_id = {$queue}.id\n INNER JOIN {$queue} as dest_queue\n ON {$forward}.dest_queue_id = dest_queue.id\n INNER JOIN {$contact} as dest_contact\n ON dest_queue.contact_id = dest_contact.id\n INNER JOIN {$email} as dest_email\n ON dest_queue.email_id = dest_email.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$query .= " ORDER BY {$contact}.sort_name, {$forward}.time_stamp DESC ";
if ($offset || $rowCount) {
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$from_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->from_id}");
$dest_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->dest_id}");
$results[] = array('from_name' => "<a href=\"{$from_url}\">{$dao->from_name}</a>", 'from_email' => $dao->from_email, 'dest_email' => "<a href=\"{$dest_url}\">{$dao->dest_email}</a>", 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例7: array
/**
* returns the column headers as an array of tuples:
* (name, sortName (key to the sort array))
*
* @param string $action the action being performed
* @param enum $output what should the result set include (web/email/csv)
*
* @return array the column headers that need to be displayed
* @access public
*/
function &getColumnHeaders($action = NULL, $output = NULL)
{
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
if (!isset($this->_columnHeaders)) {
$this->_columnHeaders = array(array('name' => ts('Contact'), 'sort' => $contact . '.sort_name', 'direction' => CRM_Utils_Sort::ASCENDING), array('name' => ts('Email Address'), 'sort' => $email . '.email', 'direction' => CRM_Utils_Sort::DONTCARE));
switch ($this->_event_type) {
case 'queue':
$dateSort = $job . '.start_date';
break;
case 'delivered':
$dateSort = CRM_Mailing_Event_BAO_Delivered::getTableName() . '.time_stamp';
break;
case 'opened':
$dateSort = CRM_Mailing_Event_BAO_Opened::getTableName() . '.time_stamp';
break;
case 'bounce':
$dateSort = CRM_Mailing_Event_BAO_Bounce::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason'))));
break;
case 'forward':
$dateSort = CRM_Mailing_Event_BAO_Forward::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email'))));
break;
case 'reply':
$dateSort = CRM_Mailing_Event_BAO_Reply::getTableName() . '.time_stamp';
break;
case 'unsubscribe':
$dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Unsubscribe'))));
break;
case 'optout':
$dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out'))));
break;
case 'click':
$dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL'))));
break;
default:
return 0;
}
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date'), 'sort' => $dateSort, 'direction' => CRM_Utils_Sort::DESCENDING)));
}
return $this->_columnHeaders;
}
示例8: CRM_Core_BAO_ACL
/**
* Get all of the ACLs through ACL groups
*
* @param int $contact_id - ID of a contact to search for
* @param int $group_id - ID of a group to search for
* @return array - Array of assoc. arrays of ACL rules
* @access public
* @static
*/
function &getACLGroups($contact_id = null, $group_id = null)
{
$contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
$group_id = CRM_Utils_Type::escape($group_id, 'Integer');
$rule =& new CRM_Core_BAO_ACL();
$acl = CRM_Core_BAO_ACL::getTableName();
$aclGroup = CRM_Core_BAO_ACLGroup::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$domain = CRM_Core_DAO_Domain::getTableName();
$c2g = CRM_Contact_BAO_GroupContact::getTableName();
$group = CRM_Contact_BAO_Group::getTableName();
$session =& CRM_Core_Session::singleton();
$domainId = $session->get('domainID');
$query = " SELECT {$acl}.* \n FROM {$acl}\n INNER JOIN {$aclGroup}\n ON {$acl}.entity_table = '{$aclGroup}'\n AND {$acl}.entity_id = {$aclGroup}.id";
if (!empty($group_id)) {
$query .= " INNER JOIN {$c2g}\n ON {$aclGroup}.entity_id = {$c2g}.group_id\n WHERE {$aclGroup}.entity_table = '{$group}'\n AND {$aclGroup}.is_active = 1\n AND {$c2g}.group_id = {$group_id}";
if (!empty($contact_id)) {
$query .= " AND {$c2g}.contact_id = {$contact_id}\n AND {$c2g}.status = 'Added'";
}
} else {
if (!empty($contact_id)) {
$query .= " WHERE {$aclGroup}.entity_table = '{$contact}'\n AND {$aclGroup}.is_active = 1\n AND {$aclGroup}.entity_id = {$contact_id}";
} else {
$query .= " WHERE {$aclGroup}.entity_table = '{$domain}'\n AND {$aclGroup}.is_active = 1\n AND {$aclGroup}.entity_id = {$domain_id}";
}
}
$results = array();
$rule->query($query);
while ($rule->fetch()) {
$results[] =& $rule->toArray();
}
return $results;
}
示例9: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param boolean $is_distinct Group by queue id?
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
*
* @return array Result set
* @access public
* @static
*/
public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL)
{
$dao = new CRM_Core_Dao();
$bounce = self::getTableName();
$bounceType = CRM_Mailing_DAO_BounceType::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$bounce}.time_stamp as date,\n {$bounce}.bounce_reason as reason,\n {$bounceType}.name as bounce_type\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$bounce}\n ON {$bounce}.event_queue_id = {$queue}.id\n LEFT JOIN {$bounceType}\n ON {$bounce}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n AND {$job}.is_test = 0\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$orderBy = "sort_name ASC, {$bounce}.time_stamp DESC";
if ($sort) {
if (is_string($sort)) {
$sort = CRM_Utils_Type::escape($sort, 'String');
$orderBy = $sort;
} else {
$orderBy = trim($sort->orderBy());
}
}
$query .= " ORDER BY {$orderBy} ";
if ($offset || $rowCount) {
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例10: trim
/**
* Get rows for the event browser.
*
* @param int $mailing_id
* ID of the mailing.
* @param int $job_id
* Optional ID of the job.
* @param bool $is_distinct
* Group by queue id?.
* @param int $offset
* Offset.
* @param int $rowCount
* Number of rows.
* @param array $sort
* Sort array.
*
* @param null $org_unsubscribe
* @return array
* Result set
*/
public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL, $org_unsubscribe = NULL)
{
$dao = new CRM_Core_Dao();
$unsub = self::$_tableName;
$queueObject = new CRM_Mailing_Event_BAO_Queue();
$queue = $queueObject->getTableName();
$mailingObject = new CRM_Mailing_BAO_Mailing();
$mailing = $mailingObject->getTableName();
$jobObject = new CRM_Mailing_BAO_MailingJob();
$job = $jobObject->getTableName();
$contactObject = new CRM_Contact_BAO_Contact();
$contact = $contactObject->getTableName();
$emailObject = new CRM_Core_BAO_Email();
$email = $emailObject->getTableName();
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$unsub}.time_stamp as date,\n {$unsub}.org_unsubscribe as org_unsubscribe\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$unsub}\n ON {$unsub}.event_queue_id = {$queue}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($org_unsubscribe !== NULL) {
$query .= " AND {$unsub}.org_unsubscribe = " . ($org_unsubscribe ? 0 : 1);
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$orderBy = "sort_name ASC, {$unsub}.time_stamp DESC";
if ($sort) {
if (is_string($sort)) {
$sort = CRM_Utils_Type::escape($sort, 'String');
$orderBy = $sort;
} else {
$orderBy = trim($sort->orderBy());
}
}
$query .= " ORDER BY {$orderBy} ";
if ($offset || $rowCount) {
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'unsubOrOptout' => ts('Yes'), 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例11: deliver
/**
* Send the mailing
*
* @param object $mailer A Mail object to send the messages
* @return void
* @access public
*/
public function deliver(&$mailer, $testParams = null)
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(true);
$eq =& new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null";
$eq->query($query);
static $config = null;
$mailsProcessed = 0;
if ($config == null) {
$config =& CRM_Core_Config::singleton();
}
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
if (!empty($testParams)) {
$mailing->from_name = ts('CiviCRM Test Mailer (%1)', array(1 => $mailing->from_name));
$mailing->subject = ts('Test Mailing:') . ' ' . $mailing->subject;
}
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
if (defined('CIVICRM_MAIL_SMARTY')) {
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
}
// make sure that there's no more than $config->mailerBatchLimit mails processed in a run
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
if ($config->mailerBatchLimit > 0 && $mailsProcessed >= $config->mailerBatchLimit) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
return false;
}
$mailsProcessed++;
$fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email);
if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
if (!$isDelivered) {
return $isDelivered;
}
$fields = array();
}
}
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
return $isDelivered;
}
示例12: _crm_update_contact
//.........这里部分代码省略.........
$contact->location[1] =& new CRM_Core_BAO_Location();
}
$primary_location = null;
foreach ($contact->location as $key => $loc) {
if ($loc->is_primary) {
$primary_location = $key;
break;
}
}
if (is_array($values['location'])) {
foreach ($values['location'] as $updateLocation) {
$emptyBlock = $contactLocationBlock = null;
/* Scan the location array for the correct block to update */
foreach ($contact->location as $key => $loc) {
if ($loc->location_type_id == $updateLocation['location_type_id']) {
$contactLocationBlock = $key;
break;
} else {
if (!isset($loc->location_type_id)) {
$emptyBlock = $key;
}
}
}
if ($contactLocationBlock == null) {
if ($emptyBlock != null) {
$contactLocationBlock = $emptyBlock;
} else {
/* no matching blocks and no empty blocks, make a new one */
$contact->location[] =& new CRM_Core_BAO_Location();
$contactLocationBlock = count($contact->location);
}
}
$updateLocation['entity_id'] = $contact->id;
$updateLocation['entity_table'] = CRM_Contact_BAO_Contact::getTableName();
/* If we're not overwriting, copy old data back before updating */
if (!$overwrite) {
_crm_update_from_object($contact->location[$contactLocationBlock], $updateLocation, true);
}
/* Make sure we only have one primary location */
if ($primary_location == null && $updateLocation['is_primary']) {
$primary_location = $contactLocationBlock;
} else {
if ($primary_location != $contactLocationBlock) {
$updateLocation['is_primary'] = false;
}
}
_crm_update_object($contact->location[$contactLocationBlock], $updateLocation);
if (!isset($contact->location[$contactLocationBlock]->address)) {
$contact->location[$contactLocationBlock]->address =& new CRM_Core_BAO_Address();
}
$updateLocation['address']['location_id'] = $contact->location[$contactLocationBlock]->id;
if ($updateLocation['address']['state_province']) {
$state_province =& new CRM_Core_DAO_StateProvince();
$state_province->name = $updateLocation['address']['state_province'];
if (!$state_province->find(true)) {
$state_province->name = null;
$state_province->abbreviation = $updateLocation['address']['state_province'];
$state_province->find(true);
}
$updateLocation['address']['state_province_id'] = $state_province->id;
}
if ($updateLocation['address']['country']) {
$country =& new CRM_Core_DAO_Country();
$country->name = $updateLocation['address']['country'];
if (!$country->find(true)) {
$country->name = null;
示例13: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
* @return array Result set
* @access public
* @static
*/
public static function &getRows($mailing_id, $job_id = null, $offset = null, $rowCount = null, $sort = null)
{
$dao = new CRM_Core_Dao();
$queue = self::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$orderBy = "sort_name ASC, {$job}.start_date DESC";
if ($sort) {
if (is_string($sort)) {
$orderBy = $sort;
} else {
$orderBy = trim($sort->orderBy());
}
}
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$job}.start_date as date\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
$query .= " ORDER BY {$orderBy} ";
if ($offset || $rowCount) {
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例14: retryRecipients
/**
* Generate an event queue for a retry job (ie the contacts who bounced)
*
* @param int $job_id The job marked retry
* @return object A DAO loaded with email_id/contact_id results
* @access public
*/
function retryRecipients($job_id)
{
$eq =& new CRM_Mailing_Event_BAO_Queue();
$job = CRM_Mailing_BAO_Job::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$bounce = CRM_Mailing_Event_BAO_Bounce::getTableName();
$delivered = CRM_Mailing_Event_BAO_Delivered::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$query = "SELECT {$queue}.email_id as email_id, \n {$queue}.contact_id as contact_id\n FROM {$queue}\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$bounce}\n ON {$bounce}.event_queue_id = {$queue}.id\n INNER JOIN {$contact}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n LEFT JOIN {$queue} as queue_d\n ON queue_d.contact_id = {$queue}.contact_id\n LEFT JOIN {$delivered}\n ON {$delivered}.event_queue_id = queue_d.id\n LEFT JOIN {$bounce} as bounce_d\n ON bounce_d.event_queue_id = queue_d.id\n WHERE \n {$job}.mailing_id = {$this->id}\n AND {$job}.id <> {$job_id}\n AND {$contact}.do_not_email = 0\n AND {$contact}.is_opt_out = 0\n AND {$email}.on_hold = 0\n AND bounce_d.id IS NOT NULL\n GROUP BY {$queue}.email_id";
$eq->query($query);
return $eq;
// $results = array();
// while ($eq->fetch()) {
// $results[] = array(
// 'email_id' => $eq->email_id,
// 'contact_id' => $eq->contact_id,
// );
// }
// return $results;
}
示例15: deliver
/**
* Send the mailing.
*
* @param object $mailer
* A Mail object to send the messages.
*
* @param array $testParams
*
* @return void
*/
public function deliver(&$mailer, $testParams = NULL)
{
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(TRUE);
$mailing->free();
$eq = new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$phoneTable = CRM_Core_DAO_Phone::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as phone\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$emailTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND {$contactTable}.is_opt_out = 0";
if ($mailing->sms_provider_id) {
$query = "\n SELECT {$eqTable}.id,\n {$phoneTable}.phone as phone,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as email\n FROM {$eqTable}\n INNER JOIN {$phoneTable}\n ON {$eqTable}.phone_id = {$phoneTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$phoneTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND ( {$contactTable}.is_opt_out = 0\n OR {$contactTable}.do_not_sms = 0 )";
}
$eq->query($query);
$config = NULL;
if ($config == NULL) {
$config = CRM_Core_Config::singleton();
}
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
if (!empty($testParams)) {
$mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject;
}
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
CRM_Core_Smarty::registerStringResource();
}
// CRM-12376
// This handles the edge case scenario where all the mails
// have been delivered in prior jobs
$isDelivered = TRUE;
// make sure that there's no more than $config->mailerBatchLimit mails processed in a run
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
if ($config->mailerBatchLimit > 0 && self::$mailsProcessed >= $config->mailerBatchLimit) {
if (!empty($fields)) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
$eq->free();
return FALSE;
}
self::$mailsProcessed++;
$fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email, 'phone' => $eq->phone);
if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
if (!$isDelivered) {
$eq->free();
return $isDelivered;
}
$fields = array();
}
}
$eq->free();
if (!empty($fields)) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
return $isDelivered;
}