本文整理汇总了PHP中CRM_Contact_DAO_Group::query方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_DAO_Group::query方法的具体用法?PHP CRM_Contact_DAO_Group::query怎么用?PHP CRM_Contact_DAO_Group::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_DAO_Group
的用法示例。
在下文中一共展示了CRM_Contact_DAO_Group::query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGroupList
/**
* Get list of all the groups and groups for a contact.
*
* @param int $contactId
* Contact id.
*
* @param bool $visibility
*
*
* @return array
* this array has key-> group id and value group title
*/
public static function getGroupList($contactId = 0, $visibility = FALSE)
{
$group = new CRM_Contact_DAO_Group();
$select = $from = $where = '';
$select = 'SELECT DISTINCT civicrm_group.id, civicrm_group.title ';
$from = ' FROM civicrm_group ';
$where = " WHERE civicrm_group.is_active = 1 ";
if ($contactId) {
$from .= ' , civicrm_group_contact ';
$where .= " AND civicrm_group.id = civicrm_group_contact.group_id\n AND civicrm_group_contact.contact_id = " . CRM_Utils_Type::escape($contactId, 'Integer');
}
if ($visibility) {
$where .= " AND civicrm_group.visibility != 'User and User Admin Only'";
}
$orderby = " ORDER BY civicrm_group.name";
$sql = $select . $from . $where . $orderby;
$group->query($sql);
$values = array();
while ($group->fetch()) {
$values[$group->id] = $group->title;
}
return $values;
}