X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroupContact.php;h=505f92cf2379415b345cb124e6f60a781c337306;hb=bdd49e3826fad29cc02081b07a81eda3455d126a;hp=ce40ccccb39df92b27b5665ffdce827088941ff4;hpb=fd31fa4c65b766d62df21f578772960955322576;p=civicrm-core.git diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index ce40ccccb3..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 = ''; @@ -309,7 +303,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { } /** - * Function to get the list of groups for contact based on status of group membership + * Get the list of groups for contact based on status of group membership * * @param int $contactId contact id * @param string $status state of membership @@ -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); @@ -494,18 +491,20 @@ SELECT * } /** - * takes an associative array and creates / removes + * Takes an associative array and creates / removes * contacts from the groups * * * @param array $params (reference ) an assoc array of name/value pairs - * @param array $contactId contact id + * @param array $contactId contact id + * + * @param bool $visibility + * @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; @@ -553,7 +552,13 @@ SELECT * } } - static function isContactInGroup($contactID, $groupID) { + /** + * @param int $contactID + * @param int $groupID + * + * @return bool + */ + public static function isContactInGroup($contactID, $groupID) { if (!CRM_Utils_Rule::positiveInteger($contactID) || !CRM_Utils_Rule::positiveInteger($groupID) ) { @@ -586,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'), ); @@ -683,11 +688,13 @@ AND group_id IN ( $groupIDString ) /** * Given an array of contact ids, add all the contacts to the group * - * @param array $contactIds (reference ) the array of contact ids to be added - * @param int $groupId the id of the group + * @param array $contactIDs the array of contact ids to be added + * @param int $groupID the id of the group + * @param string $method + * @param string $status + * @param null $tracking * * @return array (total, added, notAdded) count of contacts added to group - * @access public * @static */ static function bulkAddContactsToGroup( @@ -759,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; + } +}