*
* @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');
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()) {
'value' => $dao->id,
);
}
- }
+
return $contacts;
}