Commit bc0d4036 authored by mattwire's avatar mattwire
Browse files

Support smartgroups

parent 8746f3d1
......@@ -3,25 +3,6 @@ use CRM_Groupadmin_ExtensionUtil as E;
class CRM_Groupadmin_BAO_GroupAdminContact extends CRM_Groupadmin_DAO_GroupAdminContact {
/**
* Create a new GroupAdminContact based on array-data
*
* @param array $params key-value pairs
* @return CRM_Groupadmin_DAO_GroupAdminContact|NULL
*
public static function create($params) {
$className = 'CRM_Groupadmin_DAO_GroupAdminContact';
$entityName = 'GroupAdminContact';
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
$instance = new $className();
$instance->copyValues($params);
$instance->save();
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
return $instance;
} */
/**
* @param $contactID
......@@ -43,13 +24,34 @@ class CRM_Groupadmin_BAO_GroupAdminContact extends CRM_Groupadmin_DAO_GroupAdmin
public static function getGroupAdminPermissionedWhereClause($contactID) {
$groups = self::getGroupAdminList($contactID);
$where = [];
if (!empty($groups)) {
return 'contact_a.id IN (
$where[] = 'contact_a.id IN (
SELECT contact_id FROM civicrm_group_contact WHERE group_id IN ('
. implode(',', self::getGroupAdminList($contactID)) . ')
)';
}
return NULL;
$smartGroups = \Civi\Api4\Group::get()
->addSelect('id')
->addWhere('saved_search_id', 'IS NOT NULL')
->addWhere('id', 'IN', $groups)
->setCheckPermissions(FALSE)
->execute()
->indexBy('id');
if ($smartGroups->count() > 0) {
$smartGroupIDs = array_keys($smartGroups->getArrayCopy());
// Check and refresh smartgroup cache
\CRM_Contact_BAO_GroupContactCache::check($smartGroupIDs);
$where[] = 'contact_a.id IN (
SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id IN ('
. implode(',', $smartGroupIDs) . ')
)';
}
return implode(' OR ', $where);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment