本文整理汇总了PHP中CRM_Contact_DAO_Group::find方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_DAO_Group::find方法的具体用法?PHP CRM_Contact_DAO_Group::find怎么用?PHP CRM_Contact_DAO_Group::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_DAO_Group
的用法示例。
在下文中一共展示了CRM_Contact_DAO_Group::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: browse
/**
* Browse all saved searches.
*
* @return mixed
* content of the parents run method
*/
public function browse()
{
$rows = array();
$savedSearch = new CRM_Contact_DAO_SavedSearch();
$savedSearch->is_active = 1;
$savedSearch->selectAdd();
$savedSearch->selectAdd('id, form_values');
$savedSearch->find();
$properties = array('id', 'name', 'description');
while ($savedSearch->fetch()) {
// get name and description from group object
$group = new CRM_Contact_DAO_Group();
$group->saved_search_id = $savedSearch->id;
if ($group->find(TRUE)) {
$permissions = CRM_Group_Page_Group::checkPermission($group->id, $group->title);
if (!CRM_Utils_System::isNull($permissions)) {
$row = array();
$row['name'] = $group->title;
$row['description'] = $group->description;
$row['id'] = $savedSearch->id;
$formValues = unserialize($savedSearch->form_values);
$query = new CRM_Contact_BAO_Query($formValues);
$row['query_detail'] = $query->qill();
$action = array_sum(array_keys(self::links()));
$action = $action & CRM_Core_Action::mask($permissions);
$row['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $row['id']), ts('more'), FALSE, 'savedSearch.manage.action', 'SavedSearch', $row['id']);
$rows[] = $row;
}
}
}
$this->assign('rows', $rows);
return parent::run();
}
示例2: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
*
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
// before we proceed lets just check if this contact is already 'Added'
// if so, we should ignore this request and hence avoid sending multiple
// emails - CRM-11157
$details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
if ($details && $details->status == 'Added') {
// This contact is already subscribed
// lets return the group title
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
}
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(TRUE);
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
$mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
// send - ignore errors because the desired status change has already been successful
$unused_result = CRM_Utils_Mail::send($mailParams);
return $group->title;
}
示例3: civicrm_api3_mailing_event_subscribe_create
/**
* Subscribe from mailing group
*
* @param array $params Associative array of property
* name/value pairs to insert in new 'survey'
*
* @throws API_Exception
* @return array api result array
* {@getfields mailing_event_subscribe_create}
* @access public
*/
function civicrm_api3_mailing_event_subscribe_create($params)
{
$email = $params['email'];
$group_id = $params['group_id'];
$contact_id = CRM_Utils_Array::value('contact_id', $params);
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->id = (int) $group_id;
if (!$group->find(TRUE)) {
throw new API_Exception('Invalid Group id');
}
$subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id);
if ($subscribe !== NULL) {
/* Ask the contact for confirmation */
$subscribe->send_confirm_request($email);
$values = array();
$values[$subscribe->id]['contact_id'] = $subscribe->contact_id;
$values[$subscribe->id]['subscribe_id'] = $subscribe->id;
$values[$subscribe->id]['hash'] = $subscribe->hash;
return civicrm_api3_create_success($values);
}
return civicrm_api3_create_error('Subscription failed');
}
示例4: getGroups
/**
* Returns array of group object(s) matching a set of one or Group properties.
*
* @param array $params
* Limits the set of groups returned.
* @param array $returnProperties
* Which properties should be included in the returned group objects.
* (member_count should be last element.)
* @param string $sort
* @param int $offset
* @param int $rowCount
*
* @return array
* Array of group objects.
*
*
* @todo other BAO functions that use returnProperties (e.g. Query Objects) receive the array flipped & filled with 1s and
* add in essential fields (e.g. id). This should follow a regular pattern like the others
*/
public static function getGroups($params = NULL, $returnProperties = NULL, $sort = NULL, $offset = NULL, $rowCount = NULL)
{
$dao = new CRM_Contact_DAO_Group();
if (!isset($params['is_active'])) {
$dao->is_active = 1;
}
if ($params) {
foreach ($params as $k => $v) {
if ($k == 'name' || $k == 'title') {
$dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
} elseif ($k == 'group_type') {
foreach ((array) $v as $type) {
$dao->whereAdd($k . " LIKE '%" . CRM_Core_DAO::VALUE_SEPARATOR . (int) $type . CRM_Core_DAO::VALUE_SEPARATOR . "%'");
}
} elseif (is_array($v)) {
foreach ($v as &$num) {
$num = (int) $num;
}
$dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
} else {
$dao->{$k} = $v;
}
}
}
if ($offset || $rowCount) {
$offset = $offset > 0 ? $offset : 0;
$rowCount = $rowCount > 0 ? $rowCount : 25;
$dao->limit($offset, $rowCount);
}
if ($sort) {
$dao->orderBy($sort);
}
// return only specific fields if returnproperties are sent
if (!empty($returnProperties)) {
$dao->selectAdd();
$dao->selectAdd(implode(',', $returnProperties));
}
$dao->find();
$flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
$groups = array();
while ($dao->fetch()) {
$group = new CRM_Contact_DAO_Group();
if ($flag) {
$dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
}
$groups[] = clone $dao;
}
return $groups;
}
示例5: from
function from()
{
//define table name
$randomNum = md5(uniqid());
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
//block for Group search
$smartGroup = array();
if ($this->_groups || $this->_allSearch) {
require_once 'CRM/Contact/DAO/Group.php';
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->find();
while ($group->fetch()) {
$allGroups[] = $group->id;
if ($group->saved_search_id) {
$smartGroup[$group->saved_search_id] = $group->id;
}
}
$includedGroups = implode(',', $allGroups);
if (!empty($this->_includeGroups)) {
$iGroups = implode(',', $this->_includeGroups);
} else {
//if no group selected search for all groups
$iGroups = null;
}
if (is_array($this->_excludeGroups)) {
$xGroups = implode(',', $this->_excludeGroups);
} else {
$xGroups = 0;
}
$sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
CRM_Core_DAO::executeQuery($sql);
//used only when exclude group is selected
if ($xGroups != 0) {
$excludeGroup = "INSERT INTO Xg_{$this->_tableName} ( contact_id )\n SELECT DISTINCT civicrm_group_contact.contact_id\n FROM civicrm_group_contact, civicrm_contact \n WHERE \n civicrm_contact.id = civicrm_group_contact.contact_id AND \n civicrm_group_contact.status = 'Added' AND\n civicrm_group_contact.group_id IN( {$xGroups})";
CRM_Core_DAO::executeQuery($excludeGroup);
//search for smart group contacts
foreach ($this->_excludeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql = $smartSql . " AND contact_a.id NOT IN ( \n SELECT contact_id FROM civicrm_group_contact \n WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
CRM_Core_DAO::executeQuery($smartGroupQuery);
}
}
}
$sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,\n contact_id int,\n group_names varchar(64)) ENGINE=HEAP";
CRM_Core_DAO::executeQuery($sql);
if ($iGroups) {
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n SELECT civicrm_contact.id as contact_id, civicrm_group.title as group_name\n FROM civicrm_contact\n INNER JOIN civicrm_group_contact\n ON civicrm_group_contact.contact_id = civicrm_contact.id\n LEFT JOIN civicrm_group\n ON civicrm_group_contact.group_id = civicrm_group.id";
} else {
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n SELECT civicrm_contact.id as contact_id, ''\n FROM civicrm_contact";
}
//used only when exclude group is selected
if ($xGroups != 0) {
$includeGroup .= " LEFT JOIN Xg_{$this->_tableName}\n ON civicrm_contact.id = Xg_{$this->_tableName}.contact_id";
}
if ($iGroups) {
$includeGroup .= " WHERE \n civicrm_group_contact.status = 'Added' AND\n civicrm_group_contact.group_id IN({$iGroups})";
} else {
$includeGroup .= " WHERE ( 1 ) ";
}
//used only when exclude group is selected
if ($xGroups != 0) {
$includeGroup .= " AND Xg_{$this->_tableName}.contact_id IS null";
}
CRM_Core_DAO::executeQuery($includeGroup);
//search for smart group contacts
foreach ($this->_includeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql .= " AND contact_a.id NOT IN ( \n SELECT contact_id FROM civicrm_group_contact\n WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
//used only when exclude group is selected
if ($xGroups != 0) {
$smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
}
$smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id) \n {$smartSql}";
CRM_Core_DAO::executeQuery($smartGroupQuery);
$insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}\n SET group_names = (SELECT title FROM civicrm_group\n WHERE civicrm_group.id = {$values})\n WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL \n AND Ig_{$this->_tableName}.group_names IS NULL";
CRM_Core_DAO::executeQuery($insertGroupNameQuery);
}
}
}
//group contact search end here;
//block for Tags search
if ($this->_tags || $this->_allSearch) {
//find all tags
require_once 'CRM/Core/DAO/Tag.php';
$tag = new CRM_Core_DAO_Tag();
$tag->is_active = 1;
$tag->find();
while ($tag->fetch()) {
$allTags[] = $tag->id;
}
$includedTags = implode(',', $allTags);
if (!empty($this->_includeTags)) {
$iTags = implode(',', $this->_includeTags);
} else {
//.........这里部分代码省略.........
示例6: groupClause
/**
* Get group clause for this user. The group Clause filters the
* list of groups that the user is permitted to see in a group listing.
* For example it will filter both the list on the 'Manage Groups' page
* and on the contact 'Groups' tab
*
* the aclGroup hook & configured ACLs contribute to this data.
* If the contact is allowed to see all contacts the function will return ( 1 )
*
* @todo the history of this function is that there was some confusion as to
* whether it was filtering contacts or groups & some cruft may remain
*
* @param int $type
* The type of permission needed.
* @param array $tables
* (reference) add the tables that are needed for the select clause.
* @param array $whereTables
* (reference) add the tables that are needed for the where clause.
*
* @return string
* the clause to add to the query retrieving viewable groups
*/
public function groupClause($type, &$tables, &$whereTables)
{
if (!isset($this->_viewPermissionedGroups)) {
$this->group();
}
// we basically get all the groups here
$groupKey = 'all';
if ($type == CRM_Core_Permission::EDIT) {
if ($this->_editAdminUser) {
$clause = ' ( 1 ) ';
} elseif (empty($this->_editPermissionedGroups[$groupKey])) {
$clause = ' ( 0 ) ';
} else {
$clauses = array();
$groups = implode(', ', $this->_editPermissionedGroups[$groupKey]);
$clauses[] = ' ( civicrm_group_contact.group_id IN ( ' . implode(', ', array_keys($this->_editPermissionedGroups[$groupKey])) . " ) AND civicrm_group_contact.status = 'Added' ) ";
$tables['civicrm_group_contact'] = 1;
$whereTables['civicrm_group_contact'] = 1;
// foreach group that is potentially a saved search, add the saved search clause
foreach (array_keys($this->_editPermissionedGroups[$groupKey]) as $id) {
$group = new CRM_Contact_DAO_Group();
$group->id = $id;
if ($group->find(TRUE) && $group->saved_search_id) {
$clause = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, $tables, $whereTables);
if (trim($clause)) {
$clauses[] = $clause;
}
}
}
$clause = ' ( ' . implode(' OR ', $clauses) . ' ) ';
}
} else {
if ($this->_viewAdminUser) {
$clause = ' ( 1 ) ';
} elseif (empty($this->_viewPermissionedGroups[$groupKey])) {
$clause = ' ( 0 ) ';
} else {
$clauses = array();
$groups = implode(', ', $this->_viewPermissionedGroups[$groupKey]);
$clauses[] = ' civicrm_group.id IN (' . implode(', ', array_keys($this->_viewPermissionedGroups[$groupKey])) . " ) ";
$tables['civicrm_group'] = 1;
$whereTables['civicrm_group'] = 1;
$clause = ' ( ' . implode(' OR ', $clauses) . ' ) ';
}
}
return $clause;
}
示例7: getName
/**
* given an id, get the name of the saved search
*
* @param int $id the id of the saved search
*
* @return string the name of the saved search
* @access public
* @static
*/
static function getName($id, $value = 'name')
{
require_once 'CRM/Contact/DAO/Group.php';
$group = new CRM_Contact_DAO_Group();
$group->saved_search_id = $id;
if ($group->find(true)) {
return $group->{$value};
}
return null;
}
示例8: engageWhereGroupClause
function engageWhereGroupClause($clause)
{
$smartGroupQuery = "";
require_once 'CRM/Contact/DAO/Group.php';
require_once 'CRM/Contact/BAO/SavedSearch.php';
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->find();
while ($group->fetch()) {
if (in_array($group->id, $this->_params['gid_value']) && $group->saved_search_id) {
$smartGroups[] = $group->id;
}
}
if (!empty($smartGroups)) {
$smartGroups = implode(',', $smartGroups);
$smartGroupQuery = " UNION DISTINCT \n SELECT DISTINCT smartgroup_contact.contact_id \n FROM civicrm_group_contact_cache smartgroup_contact \n WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
}
if ($this->_params['gid_op'] == 'in') {
return " {$this->_aliases['civicrm_contact']}.id IN ( \n SELECT DISTINCT {$this->_aliases['civicrm_group']}.contact_id \n FROM civicrm_group_contact {$this->_aliases['civicrm_group']}\n WHERE {$clause} AND {$this->_aliases['civicrm_group']}.status = 'Added' \n {$smartGroupQuery} ) ";
} elseif ($this->_params['gid_op'] == 'mand') {
$query = " {$this->_aliases['civicrm_contact']}.id IN ( \n SELECT DISTINCT {$this->_aliases['civicrm_group']}1.contact_id \n FROM civicrm_group_contact {$this->_aliases['civicrm_group']}1\n";
for ($i = 2; $i <= count($this->_params['gid_value']); $i++) {
$j = $i - 1;
$status[] = "{$this->_aliases['civicrm_group']}{$i}.group_id != {$this->_aliases['civicrm_group']}{$j}.group_id";
$query .= " INNER JOIN civicrm_group_contact {$this->_aliases['civicrm_group']}{$i} \n ON {$this->_aliases['civicrm_group']}{$i}.contact_id = {$this->_aliases['civicrm_group']}{$j}.contact_id AND " . implode(" AND ", $status) . "\n";
}
$query .= " WHERE ";
for ($i = 1; $i <= count($this->_params['gid_value']); $i++) {
$query .= $i > 1 ? " AND " : "";
$query .= " {$this->_aliases['civicrm_group']}{$i}.group_id IN ( '" . implode("' , '", $this->_params['gid_value']) . "') AND {$this->_aliases['civicrm_group']}{$i}.status = 'Added'\n";
}
$query .= " {$smartGroupQuery} ) ";
return $query;
}
}
示例9: 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
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) {
$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);
}
$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;
}
示例10: groupClause
/**
* Get group clause for this user
*
* @param int $type the type of permission needed
* @param array $tables (reference ) add the tables that are needed for the select clause
* @param array $whereTables (reference ) add the tables that are needed for the where clause
*
* @return string the group where clause for this user
* @access public
*/
public static function groupClause($type, &$tables, &$whereTables)
{
if (!isset(self::$_viewPermissionedGroups)) {
self::group();
}
if ($type == CRM_Core_Permission::EDIT) {
if (self::$_editAdminUser) {
$clause = ' ( 1 ) ';
} else {
if (empty(self::$_editPermissionedGroups)) {
$clause = ' ( 0 ) ';
} else {
$clauses = array();
$groups = implode(', ', self::$_editPermissionedGroups);
$clauses[] = ' ( civicrm_group_contact.group_id IN ( ' . implode(', ', array_keys(self::$_editPermissionedGroups)) . " ) AND civicrm_group_contact.status = 'Added' ) ";
$tables['civicrm_group_contact'] = 1;
$whereTables['civicrm_group_contact'] = 1;
// foreach group that is potentially a saved search, add the saved search clause
foreach (array_keys(self::$_editPermissionedGroups) as $id) {
$group = new CRM_Contact_DAO_Group();
$group->id = $id;
if ($group->find(true) && $group->saved_search_id) {
require_once 'CRM/Contact/BAO/SavedSearch.php';
$clause = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, $tables, $whereTables);
if (trim($clause)) {
$clauses[] = $clause;
}
}
}
$clause = ' ( ' . implode(' OR ', $clauses) . ' ) ';
}
}
} else {
if (self::$_viewAdminUser) {
$clause = ' ( 1 ) ';
} else {
if (empty(self::$_viewPermissionedGroups)) {
$clause = ' ( 0 ) ';
} else {
$clauses = array();
$groups = implode(', ', self::$_viewPermissionedGroups);
$clauses[] = ' ( civicrm_group_contact.group_id IN (' . implode(', ', array_keys(self::$_viewPermissionedGroups)) . " ) AND civicrm_group_contact.status = 'Added' ) ";
$tables['civicrm_group_contact'] = 1;
$whereTables['civicrm_group_contact'] = 1;
// foreach group that is potentially a saved search, add the saved search clause
foreach (array_keys(self::$_viewPermissionedGroups) as $id) {
$group = new CRM_Contact_DAO_Group();
$group->id = $id;
if ($group->find(true) && $group->saved_search_id) {
require_once 'CRM/Contact/BAO/SavedSearch.php';
$clause = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, $tables, $whereTables);
if (trim($clause)) {
$clauses[] = $clause;
}
}
}
$clause = ' ( ' . implode(' OR ', $clauses) . ' ) ';
}
}
}
return $clause;
}
示例11: from
function from()
{
//define table name
$randomNum = md5(uniqid());
$this->_tableName = "civicrm_temp_custom_{$randomNum}";
//block for Group search
$smartGroup = array();
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->find();
while ($group->fetch()) {
$allGroups[] = $group->id;
if ($group->saved_search_id) {
$smartGroup[$group->saved_search_id] = $group->id;
}
}
$includedGroups = implode(',', $allGroups);
if (!empty($this->_includeGroups)) {
$iGroups = implode(',', $this->_includeGroups);
} else {
//if no group selected search for all groups
$iGroups = $includedGroups;
}
if (is_array($this->_excludeGroups)) {
$xGroups = implode(',', $this->_excludeGroups);
} else {
$xGroups = 0;
}
$sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
CRM_Core_DAO::executeQuery($sql);
$sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
CRM_Core_DAO::executeQuery($sql);
//used only when exclude group is selected
if ($xGroups != 0) {
$excludeGroup = "INSERT INTO Xg_{$this->_tableName} ( contact_id )\n SELECT DISTINCT civicrm_group_contact.contact_id\n FROM civicrm_group_contact\n WHERE \n civicrm_group_contact.status = 'Added' AND\n civicrm_group_contact.group_id IN ( {$xGroups} )";
CRM_Core_DAO::executeQuery($excludeGroup);
//search for smart group contacts
foreach ($this->_excludeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql = $smartSql . " AND contact_a.id NOT IN ( \n SELECT contact_id FROM civicrm_group_contact \n WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
CRM_Core_DAO::executeQuery($smartGroupQuery);
}
}
}
$sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
CRM_Core_DAO::executeQuery($sql);
$sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName}\n ( id int PRIMARY KEY AUTO_INCREMENT,\n contact_id int,\n group_names varchar(64)) ENGINE=HEAP";
if ($this->_debug > 0) {
print "-- Include groups query: <pre>";
print "{$sql};";
print "</pre>";
}
CRM_Core_DAO::executeQuery($sql);
$includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n SELECT civicrm_group_contact.contact_id, civicrm_group.name as group_name\n FROM civicrm_group_contact\n LEFT JOIN civicrm_group\n ON civicrm_group_contact.group_id = civicrm_group.id";
//used only when exclude group is selected
if ($xGroups != 0) {
$includeGroup .= " LEFT JOIN Xg_{$this->_tableName}\n ON civicrm_group_contact.contact_id = Xg_{$this->_tableName}.contact_id";
}
$includeGroup .= " WHERE \n civicrm_group_contact.status = 'Added' AND\n civicrm_group_contact.group_id IN({$iGroups})";
//used only when exclude group is selected
if ($xGroups != 0) {
$includeGroup .= " AND Xg_{$this->_tableName}.contact_id IS null";
}
if ($this->_debug > 0) {
print "-- Include groups query: <pre>";
print "{$includeGroup};";
print "</pre>";
}
CRM_Core_DAO::executeQuery($includeGroup);
//search for smart group contacts
foreach ($this->_includeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql .= " AND contact_a.id NOT IN ( \n SELECT contact_id FROM civicrm_group_contact\n WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
//used only when exclude group is selected
if ($xGroups != 0) {
$smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
}
$smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id) \n {$smartSql}";
CRM_Core_DAO::executeQuery($smartGroupQuery);
$insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}\n SET group_names = (SELECT title FROM civicrm_group\n WHERE civicrm_group.id = {$values})\n WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL \n AND Ig_{$this->_tableName}.group_names IS NULL";
CRM_Core_DAO::executeQuery($insertGroupNameQuery);
}
}
$from = "FROM civicrm_contact contact_a";
$fromTail = "LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )";
$fromTail .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
// now create a temp table to store the randomized contacts
$sql = "DROP TEMPORARY TABLE IF EXISTS random_{$this->_tableName}";
CRM_Core_DAO::executeQuery($sql);
$sql = "CREATE TEMPORARY TABLE random_{$this->_tableName} ( id int primary key ) ENGINE=HEAP";
CRM_Core_DAO::executeQuery($sql);
if (substr($this->_segmentSize, -1) == '%') {
$countSql = "SELECT DISTINCT contact_a.id {$from} {$fromTail}\n WHERE " . $this->where();
$dao = CRM_Core_DAO::executeQuery($countSql);
$totalSize = $dao->N;
//.........这里部分代码省略.........
示例12: getGroups
/**
* Returns array of group object(s) matching a set of one or Group properties.
*
* @param array $param Array of one or more valid property_name=>value pairs.
* Limits the set of groups returned.
* @param array $returnProperties Which properties should be included in the returned group objects.
* (member_count should be last element.)
*
* @return An array of group objects.
*
* @access public
*/
static function getGroups($params = NULL, $returnProperties = NULL)
{
$dao = new CRM_Contact_DAO_Group();
$dao->is_active = 1;
if ($params) {
foreach ($params as $k => $v) {
if ($k == 'name' || $k == 'title') {
$dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
} elseif (is_array($v)) {
$dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
} else {
$dao->{$k} = $v;
}
}
}
// return only specific fields if returnproperties are sent
if (!empty($returnProperties)) {
$dao->selectAdd();
$dao->selectAdd(implode(',', $returnProperties));
}
$dao->find();
$flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
$groups = array();
while ($dao->fetch()) {
$group = new CRM_Contact_DAO_Group();
if ($flag) {
$dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
}
$groups[] = clone $dao;
}
return $groups;
}
示例13: getGroupMemberships
/**
* Function to call syncontacts with smart groups and static groups xxx delete
*
* Returns object that can iterate over a slice of the live contacts in given group.
*/
static function getGroupMemberships($groupIDs)
{
CRM_Mailchimp_Utils::checkDebug('Start-CRM_Mailchimp_Utils getGroupMemberships $groupIDs', $groupIDs);
$group = new CRM_Contact_DAO_Group();
$group->id = $groupID;
$group->find();
if ($group->fetch()) {
//Check smart groups
if ($group->saved_search_id) {
$groupContactCache = new CRM_Contact_BAO_GroupContactCache();
$groupContactCache->group_id = $groupID;
if ($start !== null) {
$groupContactCache->limit($start, CRM_Mailchimp_Form_Sync::BATCH_COUNT);
}
$groupContactCache->find();
return $groupContactCache;
} else {
$groupContact = new CRM_Contact_BAO_GroupContact();
$groupContact->group_id = $groupID;
$groupContact->whereAdd("status = 'Added'");
if ($start !== null) {
$groupContact->limit($start, CRM_Mailchimp_Form_Sync::BATCH_COUNT);
}
$groupContact->find();
return $groupContact;
}
}
CRM_Mailchimp_Utils::checkDebug('End-CRM_Mailchimp_Utils getGroupMemberships $groupIDs', $groupIDs);
return FALSE;
}
示例14: civicrm_mailer_event_subscribe
/**
* Handle a subscription event
*
* @param array $params
*
* @return array
*/
function civicrm_mailer_event_subscribe($params)
{
$errors = _civicrm_mailer_check_params($params, array('email', 'group_id'));
if (!empty($errors)) {
return $errors;
}
$email = $params['email'];
$group_id = $params['group_id'];
$contact_id = CRM_Utils_Array::value('contact_id', $params);
$group = new CRM_Contact_DAO_Group();
$group->is_active = 1;
$group->id = (int) $group_id;
if (!$group->find(TRUE)) {
return civicrm_create_error(ts('Invalid Group id'));
}
$subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id);
if ($subscribe !== NULL) {
/* Ask the contact for confirmation */
$subscribe->send_confirm_request($email);
$values = array();
$values['contact_id'] = $subscribe->contact_id;
$values['subscribe_id'] = $subscribe->id;
$values['hash'] = $subscribe->hash;
$values['is_error'] = 0;
return $values;
}
return civicrm_create_error(ts('Subscription failed'));
}
示例15: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return false;
}
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
require_once 'CRM/Contact/BAO/GroupContact.php';
CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Contact/BAO/Contact/Location.php';
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
require_once 'CRM/Contact/DAO/Group.php';
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(true);
require_once 'CRM/Mailing/BAO/Component.php';
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(true);
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, true);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, false);
$message = new Mail_mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
require_once 'CRM/Mailing/BAO/Mailing.php';
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($email, $h, $b);
CRM_Core_Error::setCallback();
}
return $group->title;
}