Skip to content

Commit

Permalink
Merge pull request #19286 from eileenmcnaughton/group
Browse files Browse the repository at this point in the history
[REF] Minor cleanup on contactGroup function
  • Loading branch information
mattwire authored Jan 7, 2021
2 parents 6b90f7f + 2b549d9 commit 7b1c1d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
30 changes: 5 additions & 25 deletions CRM/Contact/BAO/GroupContactCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,38 +579,20 @@ public static function smartGroupCacheTimeout() {
* 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
";

Expand Down Expand Up @@ -644,12 +626,10 @@ public static function contactGroup($contactID, $showHidden = FALSE) {
$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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Page/View/ContactSmartGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function browse() {
}

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);
Expand Down

0 comments on commit 7b1c1d6

Please sign in to comment.