X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroupContact.php;h=505f92cf2379415b345cb124e6f60a781c337306;hb=bdd49e3826fad29cc02081b07a81eda3455d126a;hp=0c1425ca060e353c580e69c09007cafd67373216;hpb=a335f6b228626e3e1b2f1549c8ddcbb9232b3c6b;p=civicrm-core.git diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 0c1425ca06..505f92cf23 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -1,7 +1,7 @@ group id and value group title * @static */ - static function getGroupList($contactId = 0, $visibility = FALSE) { + public static function getGroupList($contactId = 0, $visibility = FALSE) { $group = new CRM_Contact_DAO_Group(); $select = $from = $where = ''; @@ -334,7 +328,8 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { $count = FALSE, $ignorePermission = FALSE, $onlyPublicGroups = FALSE, - $excludeHidden = TRUE + $excludeHidden = TRUE, + $groupId = NULL ) { if ($count) { $select = 'SELECT count(DISTINCT civicrm_group_contact.id)'; @@ -362,6 +357,10 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { $where .= ' AND civicrm_group_contact.status = %2'; $params[2] = array($status, 'String'); } + if (!empty($groupId)) { + $where .= " AND civicrm_group.id = %3 "; + $params[3] = array($groupId, 'Integer'); + } $tables = array( 'civicrm_group_contact' => 1, 'civicrm_group' => 1, @@ -442,10 +441,9 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @param string $method If we want the subscription history details for a specific method * * @return object of group contact - * @access public * @static */ - static function getMembershipDetail($contactId, $groupID, $method = 'Email') { + public static function getMembershipDetail($contactId, $groupID, $method = 'Email') { $leftJoin = $where = $orderBy = null; if ($method) { @@ -483,10 +481,9 @@ SELECT * * * * @return groupID - * @access public * @static */ - static function getGroupId($groupContactID) { + public static function getGroupId($groupContactID) { $dao = new CRM_Contact_DAO_GroupContact(); $dao->id = $groupContactID; $dao->find(TRUE); @@ -505,10 +502,9 @@ SELECT * * @param string $method * * @return void - * @access public * @static */ - static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') { + public static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') { $contactIds = array(); $contactIds[] = $contactId; @@ -562,7 +558,7 @@ SELECT * * * @return bool */ - static function isContactInGroup($contactID, $groupID) { + public static function isContactInGroup($contactID, $groupID) { if (!CRM_Utils_Rule::positiveInteger($contactID) || !CRM_Utils_Rule::positiveInteger($groupID) ) { @@ -595,7 +591,7 @@ SELECT * * @return void. * @static */ - static function mergeGroupContact($mainContactId, $otherContactId) { + public static function mergeGroupContact($mainContactId, $otherContactId) { $params = array(1 => array($mainContactId, 'Integer'), 2 => array($otherContactId, 'Integer'), ); @@ -699,7 +695,6 @@ AND group_id IN ( $groupIDString ) * @param null $tracking * * @return array (total, added, notAdded) count of contacts added to group - * @access public * @static */ static function bulkAddContactsToGroup( @@ -771,5 +766,28 @@ AND contact_id IN ( $contactStr ) return array($numContactsAdded, $numContactsNotAdded); } -} + /** + * Get options for a given field. + * @see CRM_Core_DAO::buildOptions + * + * @param String $fieldName + * @param String $context : @see CRM_Core_DAO::buildOptionsContext + * @param Array $props : whatever is known about this dao object + * + * @return Array|bool + */ + public static function buildOptions($fieldName, $context = NULL, $props = array()) { + $params = array(); + + $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); + + // Sort group list by hierarchy + // TODO: This will only work when api.entity is "group_contact". What about others? + if (($fieldName == 'group' || $fieldName == 'group_id') && ($context == 'search' || $context == 'create')) { + $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE); + } + + return $options; + } +}