From 032346cc1a138b1c2316f561260bbf79593fd319 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 14 Jan 2016 20:30:44 -0500 Subject: [PATCH] CRM-17645 - add hook_civicrm_selectWhereClause --- CRM/Case/BAO/CaseContact.php | 1 + CRM/Contact/BAO/Contact.php | 4 +++- CRM/Contact/BAO/Relationship.php | 4 +++- CRM/Core/BAO/UFMatch.php | 4 +++- CRM/Core/DAO.php | 8 ++++---- CRM/Utils/Hook.php | 13 +++++++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CRM/Case/BAO/CaseContact.php b/CRM/Case/BAO/CaseContact.php index 3329017ff6..dbb50a0287 100644 --- a/CRM/Case/BAO/CaseContact.php +++ b/CRM/Case/BAO/CaseContact.php @@ -101,6 +101,7 @@ class CRM_Case_BAO_CaseContact extends CRM_Case_DAO_CaseContact { if ($caseSubclauses) { $clauses['case_id'][] = 'IN (SELECT id FROM civicrm_case WHERE ' . implode(' AND ', $caseSubclauses) . ')'; } + CRM_Utils_Hook::selectWhereClause($this, $clauses); return $clauses; } diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 45d7c01fd4..5d7819955d 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3429,9 +3429,11 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) * @inheritDoc */ public function apiWhereClause() { - return array( + $clauses = array( 'id' => CRM_Contact_BAO_Contact_Permission::cacheSubquery(), ); + CRM_Utils_Hook::selectWhereClause($this, $clauses); + return $clauses; } } diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 0d0dad70a9..cf5b940251 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -2106,10 +2106,12 @@ AND cc.sort_name LIKE '%$name%'"; */ public function apiWhereClause() { // Generate an acl clause for both contacts in the relationship - return array( + $clauses = array( 'contact_id_a' => CRM_Contact_BAO_Contact_Permission::cacheSubquery(), 'contact_id_b' => CRM_Contact_BAO_Contact_Permission::cacheSubquery(), ); + CRM_Utils_Hook::selectWhereClause($this, $clauses); + return $clauses; } } diff --git a/CRM/Core/BAO/UFMatch.php b/CRM/Core/BAO/UFMatch.php index bd837e81b7..af8d7f3513 100644 --- a/CRM/Core/BAO/UFMatch.php +++ b/CRM/Core/BAO/UFMatch.php @@ -638,7 +638,9 @@ AND domain_id = %4 */ public function apiWhereClause() { // Prevent default behavior of joining ACLs onto the contact_id field - return array(); + $clauses = array(); + CRM_Utils_Hook::selectWhereClause($this, $clauses); + return $clauses; } } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index abc3eecc0d..43e88b9610 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2467,14 +2467,14 @@ SELECT contact_id * @return array */ public function apiWhereClause() { + $clauses = array(); $fields = $this->fields(); $cidField = CRM_Utils_Array::value('contact_id', $fields); if (CRM_Utils_Array::value('FKClassName', $cidField) == 'CRM_Contact_DAO_Contact') { - return array( - 'contact_id' => CRM_Contact_BAO_Contact_Permission::cacheSubquery(), - ); + $clauses['contact_id'] = CRM_Contact_BAO_Contact_Permission::cacheSubquery(); } - return array(); + CRM_Utils_Hook::selectWhereClause($this, $clauses); + return $clauses; } /** diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index ced92c3d6d..243f04d430 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -489,6 +489,19 @@ abstract class CRM_Utils_Hook { ->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup'); } + /** + * @param string|CRM_Core_DAO $entity + * @param array $clauses + * @return mixed + */ + public static function selectWhereClause($entity, &$clauses) { + $entityName = is_object($entity) ? _civicrm_api_get_entity_name_from_dao($entity) : $entity; + return self::singleton()->invoke(2, $entityName, $clauses, + self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_selectWhereClause' + ); + } + /** * This hook is called when building the menu table. * -- 2.25.1