From 2b549d901e9063a0ec29cad2552cc391a23d3620 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 30 Dec 2020 16:02:56 +1300 Subject: [PATCH] [REF] Minor cleanup on contactGroup function This function is only called from one place so we can be sure that contactID is an integer and showHidden is false --- CRM/Contact/BAO/GroupContactCache.php | 30 ++++----------------- CRM/Contact/Page/View/ContactSmartGroup.php | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index ce08275766..de00cfc543 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -584,38 +584,20 @@ AND civicrm_group_contact.group_id = $groupID "; * it ensure that all contact groups are loaded in the cache * * @param int $contactID - * @param bool $showHidden - * Hidden groups are shown only if this flag is set. * * @return array * an array of groups that this contact belongs to */ - public static function contactGroup($contactID, $showHidden = FALSE) { - if (empty($contactID)) { - return NULL; - } - - if (is_array($contactID)) { - $contactIDs = $contactID; - } - else { - $contactIDs = [$contactID]; - } + public static function contactGroup(int $contactID): array { self::loadAll(); - $hiddenClause = ''; - if (!$showHidden) { - $hiddenClause = ' AND (g.is_hidden = 0 OR g.is_hidden IS NULL) '; - } - - $contactIDString = CRM_Core_DAO::escapeString(implode(', ', $contactIDs)); $sql = " SELECT gc.group_id, gc.contact_id, g.title, g.children, g.description FROM civicrm_group_contact_cache gc INNER JOIN civicrm_group g ON g.id = gc.group_id -WHERE gc.contact_id IN ($contactIDString) - $hiddenClause +WHERE gc.contact_id = $contactID + AND (g.is_hidden = 0 OR g.is_hidden IS NULL) ORDER BY gc.contact_id, g.children "; @@ -649,12 +631,10 @@ ORDER BY gc.contact_id, g.children $contactGroup[$prevContactID]['groupTitle'] = implode(', ', $contactGroup[$prevContactID]['groupTitle']); } - if ((!empty($contactGroup[$contactID]) && is_numeric($contactID))) { + if ((!empty($contactGroup[$contactID]))) { return $contactGroup[$contactID]; } - else { - return $contactGroup; - } + return $contactGroup; } /** diff --git a/CRM/Contact/Page/View/ContactSmartGroup.php b/CRM/Contact/Page/View/ContactSmartGroup.php index 2e21781eed..a248116627 100644 --- a/CRM/Contact/Page/View/ContactSmartGroup.php +++ b/CRM/Contact/Page/View/ContactSmartGroup.php @@ -67,7 +67,7 @@ class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page { } public function preProcess() { - $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); + $this->_contactId = (int) CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $this->assign('contactId', $this->_contactId); $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); -- 2.25.1