[REF] Minor cleanup on contactGroup function
authoreileen <emcnaughton@wikimedia.org>
Wed, 30 Dec 2020 03:02:56 +0000 (16:02 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 30 Dec 2020 03:02:56 +0000 (16:02 +1300)
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
CRM/Contact/Page/View/ContactSmartGroup.php

index ce082757662b4767cac5c13d81e7bb46f6a9453e..de00cfc54367bab00e3b05e1980e73bc81fb673a 100644 (file)
@@ -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;
   }
 
   /**
index 2e21781eed0032a3b848df1a7017be50b709bf53..a2481166271dc298b4c61c812cfa6cb981e2f564 100644 (file)
@@ -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);