<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
/**
- * class constructor
+ * Class constructor
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
/**
- * takes an associative array and creates a groupContact object
+ * Takes an associative array and creates a groupContact object
*
* the function extract all the params it needs to initialize the create a
* group object. the params array could contain additional unused name/value
*
* @param array $params (reference ) an assoc array of name/value pairs
*
- * @return object CRM_Contact_BAO_Group object
- * @access public
+ * @return CRM_Contact_BAO_Group object
* @static
*/
- static function add(&$params) {
+ public static function add(&$params) {
$dataExists = self::dataExists($params);
if (!$dataExists) {
* @param array $params (reference ) an assoc array of name/value pairs
*
* @return boolean
- * @access public
* @static
*/
- static function dataExists(&$params) {
+ public static function dataExists(&$params) {
// return if no data present
if ($params['group_id'] == 0) {
return FALSE;
* @param array $params input parameters to find object
* @param array $values output values of the object
*
- * @internal param array $ids the array that holds all the db ids
- *
* @return array (reference) the values that could be potentially assigned to smarty
- * @access public
* @static
*/
- static function getValues(&$params, &$values) {
+ public static function getValues(&$params, &$values) {
if (empty($params)) {
return NULL;
}
* @param int $tracking
*
* @return array (total, added, notAdded) count of contacts added to group
- * @access public
* @static
*/
static function addContactsToGroup(
* @param null $tracking
*
* @return array (total, removed, notRemoved) count of contacts removed to group
- * @access public
* @static
*/
static function removeContactsFromGroup(
}
/**
- * Function to get list of all the groups and groups for a contact
+ * Get list of all the groups and groups for a contact
*
* @param int $contactId contact id
*
* @param bool $visibility
*
- * @access public
*
* @return array $values this array has key-> 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 = '';
}
/**
- * 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
$count = FALSE,
$ignorePermission = FALSE,
$onlyPublicGroups = FALSE,
- $excludeHidden = TRUE
+ $excludeHidden = TRUE,
+ $groupId = NULL
) {
if ($count) {
$select = 'SELECT count(DISTINCT civicrm_group_contact.id)';
$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,
* @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) {
*
*
* @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);
}
/**
- * 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;
}
}
- 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)
) {
* @return void.
* @static
*/
- static function mergeGroupContact($mainContactId, $otherContactId) {
+ public static function mergeGroupContact($mainContactId, $otherContactId) {
$params = array(1 => array($mainContactId, 'Integer'),
2 => array($otherContactId, 'Integer'),
);
/**
* 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(
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;
+ }
+}