From: Coleman Watts Date: Fri, 15 Jan 2016 01:30:44 +0000 (-0500) Subject: CRM-17645 - add hook_civicrm_selectWhereClause X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=032346cc1a138b1c2316f561260bbf79593fd319;p=civicrm-core.git CRM-17645 - add hook_civicrm_selectWhereClause --- 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. *