function _civicrm_api3_pcpteams_custom_get(&$params)
{
    foreach ($params as $rid => $rval) {
        _civicrm_api3_custom_data_get($params[$rid], 'PCP', $rid);
        // FIXME: we should at some point replace "custom_xy_" with column-names
    }
}
Beispiel #2
0
/**
 * Internal function to retrieve a case.
 *
 * @param int $caseId
 *
 * @param array $options
 *
 * @param bool $checkPermission
 *
 * @return array
 *   case object
 */
function _civicrm_api3_case_read($caseId, $options, $checkPermission)
{
    $return = CRM_Utils_Array::value('return', $options, array());
    $dao = new CRM_Case_BAO_Case();
    $dao->id = $caseId;
    if ($dao->find(TRUE)) {
        $case = array();
        _civicrm_api3_object_to_array($dao, $case);
        _civicrm_api3_custom_data_get($case, $checkPermission, 'Case', $caseId);
        // Legacy support for client_id - TODO: in apiv4 remove 'client_id'
        $case['client_id'] = $case['contact_id'] = $dao->retrieveContactIdsByCaseId($caseId);
        if (!empty($return['contacts'])) {
            //get case contacts
            $contacts = CRM_Case_BAO_Case::getcontactNames($caseId);
            $relations = CRM_Case_BAO_Case::getRelatedContacts($caseId);
            $case['contacts'] = array_merge($contacts, $relations);
        }
        if (!empty($return['activities'])) {
            //get case activities
            $case['activities'] = array();
            $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = {$caseId}";
            $dao = CRM_Core_DAO::executeQuery($query);
            while ($dao->fetch()) {
                $case['activities'][] = $dao->activity_id;
            }
        }
        return $case;
    }
}
Beispiel #3
0
/**
 * Get Event record.
 *
 *
 * @param  array  $params     an associative array of name/value property values of civicrm_event
 * {@getfields event_get}
 *
 * @return  Array of all found event property values.
 * @access public
 *
 */
function civicrm_api3_event_get($params)
{
    //legacy support for $params['return.sort']
    if (!empty($params['return.sort'])) {
        $params['options']['sort'] = $params['return.sort'];
        unset($params['return.sort']);
    }
    //legacy support for $params['return.offset']
    if (!empty($params['return.offset'])) {
        $params['options']['offset'] = $params['return.offset'];
        unset($params['return.offset']);
    }
    //legacy support for $params['return.max_results']
    if (!empty($params['return.max_results'])) {
        $params['options']['limit'] = $params['return.max_results'];
        unset($params['return.max_results']);
    }
    $eventDAO = new CRM_Event_BAO_Event();
    _civicrm_api3_dao_set_filter($eventDAO, $params, TRUE, 'Event');
    if (!empty($params['is_template'])) {
        $eventDAO->whereAdd('( is_template = 1 )');
    } elseif (empty($eventDAO->id)) {
        $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
    }
    if (!empty($params['isCurrent'])) {
        $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
    }
    // @todo should replace all this with _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity) - but we still have
    // the return.is_full to deal with.
    // NB the std dao_to_array function should only return custom if required.
    $event = array();
    $eventDAO->find();
    while ($eventDAO->fetch()) {
        $event[$eventDAO->id] = array();
        CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
        if (!empty($params['return.is_full'])) {
            _civicrm_api3_event_getisfull($event, $eventDAO->id);
        }
        _civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id);
        _civicrm_api3_custom_data_get($event[$eventDAO->id], 'Event', $eventDAO->id, NULL, $eventDAO->event_type_id);
    }
    //end of the loop
    return civicrm_api3_create_success($event, $params, 'event', 'get', $eventDAO);
}
/**
 * Converts an DAO object to an array
 *
 * @param  object   $dao           (reference )object to convert
 * @params array of arrays (key = id) of array of fields
 * @static void
 * @access public
 */
function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "")
{
    $result = array();
    if (empty($dao) || !$dao->find()) {
        return array();
    }
    //if custom fields are required we will endeavour to set them . NB passing $entity in might be a bit clunky / unrequired
    if (!empty($entity) && CRM_Utils_Array::value('return', $params) && is_array($params['return'])) {
        foreach ($params['return'] as $return) {
            if (substr($return, 0, 6) == 'custom') {
                $custom = TRUE;
            }
        }
    }
    $fields = array_keys(_civicrm_api3_build_fields_array($dao, $uniqueFields));
    while ($dao->fetch()) {
        $tmp = array();
        foreach ($fields as $key) {
            if (array_key_exists($key, $dao)) {
                // not sure on that one
                if ($dao->{$key} !== NULL) {
                    $tmp[$key] = $dao->{$key};
                }
            }
        }
        $result[$dao->id] = $tmp;
        if (!empty($custom)) {
            _civicrm_api3_custom_data_get($result[$dao->id], $entity, $dao->id);
        }
    }
    return $result;
}
Beispiel #5
0
/**
 * Converts an DAO object to an array.
 *
 * @param CRM_Core_DAO $dao
 *   Object to convert.
 * @param array $params
 * @param bool $uniqueFields
 * @param string $entity
 * @param bool $autoFind
 *
 * @return array
 */
function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "", $autoFind = TRUE)
{
    $result = array();
    if (isset($params['options']) && !empty($params['options']['is_count'])) {
        return $dao->count();
    }
    if (empty($dao)) {
        return array();
    }
    if ($autoFind && !$dao->find()) {
        return array();
    }
    if (isset($dao->count)) {
        return $dao->count;
    }
    $fields = array_keys(_civicrm_api3_build_fields_array($dao, $uniqueFields));
    while ($dao->fetch()) {
        $tmp = array();
        foreach ($fields as $key) {
            if (array_key_exists($key, $dao)) {
                // not sure on that one
                if ($dao->{$key} !== NULL) {
                    $tmp[$key] = $dao->{$key};
                }
            }
        }
        $result[$dao->id] = $tmp;
        if (_civicrm_api3_custom_fields_are_required($entity, $params)) {
            _civicrm_api3_custom_data_get($result[$dao->id], $entity, $dao->id);
        }
    }
    return $result;
}
/**
 * Function to get the relationship
 *
 * @param array   $params input parameters.
 * @todo  Result is inconsistent depending on whether contact_id is passed in :
 * -  if you pass in contact_id - it just returns all relationships for 'contact_id'
 * -  if you don't pass in contact_id then it does a filter on the relationship table (DAO based search)
 *
 * @return  Array API Result Array
 * {@getfields relationship_get}
 * @example RelationshipGet.php
 * @access  public
 */
function civicrm_api3_relationship_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params);
    if (empty($params['contact_id'])) {
        if (!empty($params['membership_type_id']) && empty($params['relationship_type_id'])) {
            CRM_Contact_BAO_Relationship::membershipTypeToRelationshipTypes($params);
        }
        $relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    } else {
        $relationships = array();
        $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], CRM_Utils_Array::value('status_id', $params), 0, CRM_Utils_Array::value('is_count', $options), CRM_Utils_Array::value('id', $params), NULL, NULL, FALSE, $params);
    }
    //perhaps we should add a 'getcount' but at this stage lets just handle getcount output
    if ($options['is_count']) {
        return array('count' => $relationships);
    }
    foreach ($relationships as $relationshipId => $values) {
        _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id', $values));
    }
    return civicrm_api3_create_success($relationships, $params);
}
/**
 * non-standard behaviour inherited from v2
* @param array $params parameters passed into get function
* @return array result for calling function
*/
function _civicrm_api3_membership_relationsship_get_customv2behaviour(&$params, $membershipValues, $contactID)
{
    $relationships = array();
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        if (!empty($membershipType['relationship_type_id'])) {
            $relationships[$membershipType['relationship_type_id']] = $membershipId;
        }
        // populating relationship type name.
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
        if ($relationshipType->find(TRUE)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
        _civicrm_api3_custom_data_get($membershipValues[$membershipId], 'Membership', $membershipId, NULL, $values['membership_type_id']);
    }
    $members = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    if (!empty($relationships)) {
        foreach ($relationships as $relTypeId => $membershipId) {
            // As members are not direct members, there should not be
            // membership id in the result array.
            unset($membershipValues[$membershipId]['id']);
            $relationship = new CRM_Contact_BAO_Relationship();
            $relationship->contact_id_b = $contactID;
            $relationship->relationship_type_id = $relTypeId;
            if ($relationship->find()) {
                while ($relationship->fetch()) {
                    clone $relationship;
                    $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                    $members[$membershipId]['related_contact_id'] = $relationship->contact_id_a;
                }
            }
        }
    }
    return $members;
}
/**
 * Retrieve a specific participant, given a set of input params.
 *
 * @param array $params
 *   input parameters.
 *
 * @return array
 *   array of properties, if error an array with an error id and error message
 */
function civicrm_api3_participant_get($params)
{
    $mode = CRM_Contact_BAO_Query::MODE_EVENT;
    list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, 'Participant');
    $participant = array();
    while ($dao->fetch()) {
        $query->convertToPseudoNames($dao, FALSE, TRUE);
        $participant[$dao->participant_id] = $query->store($dao);
        //@todo - is this required - contribution & pledge use the same query but don't self-retrieve custom data
        _civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);
    }
    return civicrm_api3_create_success($participant, $params, 'Participant', 'get', $dao);
}
/**
 * Function to get the relationship
 *
 * @param array   $params input parameters.
 * @todo  Result is inconsistent depending on whether contact_id is passed in :
 * -  if you pass in contact_id - it just returns all relationships for 'contact_id'
 * -  if you don't pass in contact_id then it does a filter on the relationship table (DAO based search)
 *
 * @return  Array API Result Array
 * {@getfields relationship_get}
 * @example RelationshipGet.php
 * @access  public
 */
function civicrm_api3_relationship_get($params)
{
    if (!CRM_Utils_Array::value('contact_id', $params)) {
        $relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    } else {
        $relationships = array();
        $relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'], CRM_Utils_Array::value('status_id', $params), 0, 0, CRM_Utils_Array::value('id', $params), NULL);
    }
    foreach ($relationships as $relationshipId => $values) {
        _civicrm_api3_custom_data_get($relationships[$relationshipId], 'Relationship', $relationshipId, NULL, CRM_Utils_Array::value('relationship_type_id', $values));
    }
    return civicrm_api3_create_success($relationships, $params);
}
/**
 * Gets a CiviCRM activity according to parameters
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs for the activity.
 *
 * @return array
 *
 * {@getfields activity_get}
 * @example ActivityGet.php Basic example
 * @example Activity/DateTimeHigh.php Example get with date filtering
 * {@example ActivityGet.php 0}
 */
function civicrm_api3_activity_get($params)
{
    if (!empty($params['contact_id'])) {
        $activities = CRM_Activity_BAO_Activity::getContactActivity($params['contact_id']);
        //BAO function doesn't actually return a contact ID - hack api for now & add to test so when api re-write happens it won't get missed
        foreach ($activities as $key => $activityArray) {
            $activities[$key]['id'] = $key;
        }
    } else {
        $activities = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    }
    $returns = CRM_Utils_Array::value('return', $params, array());
    if (!is_array($returns)) {
        $returns = str_replace(' ', '', $returns);
        $returns = explode(',', $returns);
    }
    $returns = array_fill_keys($returns, 1);
    foreach ($params as $n => $v) {
        if (substr($n, 0, 7) == 'return.') {
            $returnkey = substr($n, 7);
            $returns[$returnkey] = $v;
        }
    }
    $returns['source_contact_id'] = 1;
    foreach ($returns as $n => $v) {
        switch ($n) {
            case 'assignee_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['assignee_contact_id'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activityArray['id']);
                }
                break;
            case 'target_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['target_contact_id'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityArray['id']);
                }
                break;
            case 'source_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['source_contact_id'] = CRM_Activity_BAO_Activity::getSourceContactID($activityArray['id']);
                }
                break;
            default:
                if (substr($n, 0, 6) == 'custom') {
                    $returnProperties[$n] = $v;
                }
        }
    }
    if (!empty($activities) && (!empty($returnProperties) || !empty($params['contact_id']))) {
        foreach ($activities as $activityId => $values) {
            _civicrm_api3_custom_data_get($activities[$activityId], 'Activity', $activityId, NULL, $values['activity_type_id']);
        }
    }
    //legacy custom data get - so previous formatted response is still returned too
    return civicrm_api3_create_success($activities, $params, 'activity', 'get');
}
Beispiel #11
0
/**
 * Given a list of activities, append any extra data requested about the activities.
 *
 * @note Called by civicrm-core and CiviHR
 *
 * @param array $params
 *   API request parameters.
 * @param array $activities
 *
 * @return array
 *   new activities list
 */
function _civicrm_api3_activity_get_formatResult($params, $activities)
{
    $returns = CRM_Utils_Array::value('return', $params, array());
    if (!is_array($returns)) {
        $returns = str_replace(' ', '', $returns);
        $returns = explode(',', $returns);
    }
    $returns = array_fill_keys($returns, 1);
    foreach ($params as $n => $v) {
        if (substr($n, 0, 7) == 'return.') {
            $returnkey = substr($n, 7);
            $returns[$returnkey] = $v;
        }
    }
    $returns['source_contact_id'] = 1;
    foreach ($returns as $n => $v) {
        switch ($n) {
            case 'assignee_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['assignee_contact_id'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activityArray['id']);
                }
                break;
            case 'target_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['target_contact_id'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityArray['id']);
                }
                break;
            case 'source_contact_id':
                foreach ($activities as $key => $activityArray) {
                    $activities[$key]['source_contact_id'] = CRM_Activity_BAO_Activity::getSourceContactID($activityArray['id']);
                }
                break;
            default:
                if (substr($n, 0, 6) == 'custom') {
                    $returnProperties[$n] = $v;
                }
        }
    }
    if (!empty($activities) && (!empty($returnProperties) || !empty($params['contact_id']))) {
        foreach ($activities as $activityId => $values) {
            //@todo - should possibly load activity type id if not loaded (update with id)
            _civicrm_api3_custom_data_get($activities[$activityId], CRM_Utils_Array::value('check_permissions', $params), 'Activity', $activityId, NULL, CRM_Utils_Array::value('activity_type_id', $values));
        }
    }
    return $activities;
}
/**
 * Gets a CiviCRM activity according to parameters
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs for the activity.
 *
 * @return array
 *
 * {@getfields activity_get}
 * @example ActivityGet.php Basic example
 * @example Activity/DateTimeHigh.php Example get with date filtering
 * {@example ActivityGet.php 0}
 */
function civicrm_api3_activity_get($params)
{
    if (!empty($params['contact_id'])) {
        $activities = CRM_Activity_BAO_Activity::getContactActivity($params['contact_id']);
        //BAO function doesn't actually return a contact ID - hack api for now & add to test so when api re-write happens it won't get missed
        foreach ($activities as $key => $activityArray) {
            $activities[$key]['id'] = $key;
        }
    } else {
        $activities = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    }
    if (CRM_Utils_Array::value('return.assignee_contact_id', $params)) {
        foreach ($activities as $key => $activityArray) {
            $activities[$key]['assignee_contact_id'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activityArray['id']);
        }
    }
    if (CRM_Utils_Array::value('return.target_contact_id', $params)) {
        foreach ($activities as $key => $activityArray) {
            $activities[$key]['target_contact_id'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityArray['id']);
        }
    }
    foreach ($params as $n => $v) {
        // handle the format return.sort_name=1,return.display_name=1
        if (substr($n, 0, 13) == 'return.custom') {
            $returnProperties[substr($n, 7)] = $v;
        }
    }
    if (!empty($activities) && (!empty($returnProperties) || !empty($params['contact_id']))) {
        foreach ($activities as $activityId => $values) {
            _civicrm_api3_custom_data_get($activities[$activityId], 'Activity', $activityId, NULL, $values['activity_type_id']);
        }
    }
    //legacy custom data get - so previous formatted response is still returned too
    return civicrm_api3_create_success($activities, $params, 'activity', 'get');
}
/**
 * Retrieve a specific participant, given a set of input params
 * If more than one matching participant exists, return an error, unless
 * the client has requested to return the first found contact
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        array of properties, if error an array with an error id and error message
 * {@getfields participant_get}
 * @access public
 */
function civicrm_api3_participant_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'participant', 'get');
    $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $rowCount = CRM_Utils_Array::value('limit', $options);
    $smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
    $inputParams = CRM_Utils_Array::value('input_params', $options, array());
    $returnProperties = CRM_Utils_Array::value('return', $options, NULL);
    if (empty($returnProperties)) {
        $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
    $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT);
    list($select, $from, $where, $having) = $query->query();
    $sql = "{$select} {$from} {$where} {$having}";
    if (!empty($sort)) {
        $sql .= " ORDER BY {$sort} ";
    }
    $sql .= " LIMIT {$offset}, {$rowCount} ";
    $dao = CRM_Core_DAO::executeQuery($sql);
    $participant = array();
    while ($dao->fetch()) {
        $participant[$dao->participant_id] = $query->store($dao);
        _civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);
    }
    return civicrm_api3_create_success($participant, $params, 'participant', 'get', $dao);
}
/**
 * Get contact membership record.
 *
 * This api will return the membership records for the contacts
 * having membership based on the relationship with the direct members.
 *
 * @param  Array $params key/value pairs for contact_id and some
 *          options affecting the desired results; has legacy support
 *          for just passing the contact_id itself as the argument
 *
 * @return  Array of all found membership property values.
 * @access public
 * @todo needs some love - basically only a get for a given contact right now
 * {@getfields membership_get}
 */
function civicrm_api3_membership_get($params)
{
    $contactID = $activeOnly = $membershipTypeId = $membershipType = NULL;
    $contactID = CRM_Utils_Array::value('contact_id', $params);
    if (is_array(CRM_Utils_Array::value('filters', $params)) && !empty($params['filters'])) {
        $activeOnly = CRM_Utils_Array::value('is_current', $params['filters'], FALSE);
    }
    $activeOnly = CRM_Utils_Array::value('active_only', $params, $activeOnly);
    //@todo replace this by handling in API layer - we should have enough info to do this
    // between pseudoconstant & fk - see comments in format_params
    $membershipTypeId = CRM_Utils_Array::value('membership_type_id', $params);
    if (!$membershipTypeId) {
        $membershipType = CRM_Utils_Array::value('membership_type', $params);
        if ($membershipType) {
            $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $membershipType, 'id', 'name');
        }
    }
    if (CRM_Utils_Array::value('contact_id', $params)) {
        $membershipValues = _civicrm_api3_membership_get_customv2behaviour($params, $contactID, $membershipTypeId, $activeOnly);
    } else {
        //legacy behaviour only ever worked when contact_id passed in - use standard api function otherwise
        $membershipValues = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
    }
    if (empty($membershipValues)) {
        # No results is NOT an error!
        return civicrm_api3_create_success($membershipValues, $params);
    }
    $relationships = array();
    foreach ($membershipValues as $membershipId => $values) {
        // populate the membership type name for the membership type id
        $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
        $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
        if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
            $relationships[$membershipType['relationship_type_id']] = $membershipId;
        }
        // populating relationship type name.
        $relationshipType = new CRM_Contact_BAO_RelationshipType();
        $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
        if ($relationshipType->find(TRUE)) {
            $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
        }
        _civicrm_api3_custom_data_get($membershipValues[$membershipId], 'Membership', $membershipId, NULL, $values['membership_type_id']);
    }
    $members = $membershipValues;
    // populating contacts in members array based on their relationship with direct members.
    if (!empty($relationships)) {
        foreach ($relationships as $relTypeId => $membershipId) {
            // As members are not direct members, there should not be
            // membership id in the result array.
            unset($membershipValues[$membershipId]['id']);
            $relationship = new CRM_Contact_BAO_Relationship();
            $relationship->contact_id_b = $contactID;
            $relationship->relationship_type_id = $relTypeId;
            if ($relationship->find()) {
                while ($relationship->fetch()) {
                    clone $relationship;
                    $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
                    $members[$membershipId]['related_contact_id'] = $relationship->contact_id_a;
                }
            }
        }
    }
    return civicrm_api3_create_success($members, $params, 'membership', 'get');
}
Beispiel #15
0
/**
 * Returns array of groups  matching a set of one or more group properties
 *
 * @param array $params  (referance) Array of one or more valid
 *                       property_name=>value pairs. If $params is set
 *                       as null, all groups will be returned
 *
 * @return array  Array of matching groups
 * @example GroupGet.php
 * {@getfields group_get}
 * @access public
 */
function civicrm_api3_group_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'group', 'get');
    $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $rowCount = CRM_Utils_Array::value('limit', $options);
    $returnProperties = CRM_Utils_Array::value('return', $options, NULL);
    $inputParams = CRM_Utils_Array::value('input_params', $options, array());
    if (is_array($returnProperties) && !empty($returnProperties)) {
        // group function takes $returnProperties in non standard format & doesn't add id
        unset($returnProperties['group_id']);
        $returnProperties['id'] = 1;
        $returnProperties = array_keys($returnProperties);
    }
    if (!empty($inputParams['group_id'])) {
        $inputParams['id'] = $inputParams['group_id'];
    }
    $groupObjects = CRM_Contact_BAO_Group::getGroups($inputParams, $returnProperties, $sort, $offset, $rowCount);
    if (empty($groupObjects)) {
        return civicrm_api3_create_success(FALSE);
    }
    $groups = array();
    foreach ($groupObjects as $group) {
        _civicrm_api3_object_to_array($group, $groups[$group->id]);
        _civicrm_api3_custom_data_get($groups[$group->id], 'Group', $group->id);
    }
    return civicrm_api3_create_success($groups, $params, 'group', 'create');
}
/**
 * Returns array of groups  matching a set of one or more group properties
 *
 * @param array $params  (referance) Array of one or more valid
 *                       property_name=>value pairs. If $params is set
 *                       as null, all groups will be returned
 *
 * @return array  Array of matching groups
 * @example GroupGet.php
 * {@getfields group_get}
 * @access public
 */
function civicrm_api3_group_get($params)
{
    $returnProperties = array();
    foreach ($params as $n => $v) {
        if (substr($n, 0, 7) == 'return.') {
            $returnProperties[] = substr($n, 7);
        }
    }
    if (!empty($returnProperties)) {
        $returnProperties[] = 'id';
    }
    $groupObjects = CRM_Contact_BAO_Group::getGroups($params, $returnProperties);
    if (empty($groupObjects)) {
        return civicrm_api3_create_success(FALSE);
    }
    $groups = array();
    foreach ($groupObjects as $group) {
        _civicrm_api3_object_to_array($group, $groups[$group->id]);
        _civicrm_api3_custom_data_get($groups[$group->id], 'Group', $group->id);
    }
    return civicrm_api3_create_success($groups, $params, 'group', 'create');
}