From: Eileen McNaughton Date: Tue, 12 May 2015 11:30:48 +0000 (+1200) Subject: CRM-16490 make permissioned relationship ajax call work for other permissioned relati... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b0076fe6f457f72d882f9ad42c0cb67fc210bf83;p=civicrm-core.git CRM-16490 make permissioned relationship ajax call work for other permissioned relationship types Conflicts: CRM/Core/Page/AJAX/Location.php ---------------------------------------- * CRM-16490: load org for permissioned relationships other than current employer https://issues.civicrm.org/jira/browse/CRM-16490 --- diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index e0f036e707..e40378157b 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1768,28 +1768,36 @@ WHERE id IN ( {$contacts} ) * * @param int $contactID * contact id whose permissioned contacts are to be found. - * @param string $relTypeId + * @param int $relTypeId * one or more relationship type id's. * @param string $name * * @return array * Array of contacts */ - public static function getPermissionedContacts($contactID, $relTypeId, $name = NULL) { + public static function getPermissionedContacts($contactID, $relTypeId = NULL, $name = NULL) { $contacts = array(); + $args = array(1 => array($contactID, 'Integer')); + $relationshipTypeClause = ''; if ($relTypeId) { + // @todo relTypeId is only ever passed in as an int. Change this to reflect that - + // probably being overly conservative by not doing so but working on stable release. + $relationshipTypeClause = 'AND cr.relationship_type_id IN (%2) '; + $args[2] = array($relTypeId, 'String'); + } $query = " SELECT cc.id as id, cc.sort_name as name FROM civicrm_relationship cr, civicrm_contact cc WHERE cr.contact_id_a = %1 AND -cr.relationship_type_id IN (%2) AND cr.is_permission_a_b = 1 AND IF(cr.end_date IS NULL, 1, (DATEDIFF( CURDATE( ), cr.end_date ) <= 0)) AND cr.is_active = 1 AND cc.id = cr.contact_id_b AND -cc.is_deleted = 0"; +cc.is_deleted = 0 +$relationshipTypeClause +"; if (!empty($name)) { $name = CRM_Utils_Type::escape($name, 'String'); @@ -1797,7 +1805,6 @@ cc.is_deleted = 0"; AND cc.sort_name LIKE '%$name%'"; } - $args = array(1 => array($contactID, 'Integer'), 2 => array($relTypeId, 'String')); $dao = CRM_Core_DAO::executeQuery($query, $args); while ($dao->fetch()) { @@ -1806,7 +1813,7 @@ AND cc.sort_name LIKE '%$name%'"; 'value' => $dao->id, ); } - } + return $contacts; } diff --git a/CRM/Core/Page/AJAX/Location.php b/CRM/Core/Page/AJAX/Location.php index 1ef5d394db..c5a4bda341 100644 --- a/CRM/Core/Page/AJAX/Location.php +++ b/CRM/Core/Page/AJAX/Location.php @@ -58,7 +58,7 @@ class CRM_Core_Page_AJAX_Location { } // Verify user permission on related contact - $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($user); + $employers = CRM_Contact_BAO_Relationship::getPermissionedContacts($user); if (!isset($employers[$cid])) { CRM_Utils_System::civiExit(); }