/** * Returns array of line_items matching a set of one or more group properties. * * @param array $params * Array of one or more valid property_name=>value pairs. If $params is set. * as null, all line_items will be returned (default limit is 25) * * @return array * Array of matching line_items */ function civicrm_api3_line_item_get($params) { if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) { CRM_Price_BAO_LineItem::getAPILineItemParams($params); } return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Get expenses * * function passed on to CRM_Financial_BAO_FinancialItem */ function civicrm_api3_campaign_expense_get($params) { $params['entity_table'] = 'civicrm_campaign'; $params['entity_id'] = $params['campaign_id']; $reply = _civicrm_api3_basic_get(CRM_Financial_BAO_FinancialItem, $params); // extract the encoded expense_type_id from description if (isset($reply['values'])) { $values = $reply['values']; // copy array so we can modify while iterating foreach ($values as $expense_id => $expense) { if (!empty($expense['description'])) { $parts = explode(":", $expense['description'], 2); if (count($parts) > 1) { $reply['values'][$expense_id]['expense_type_id'] = $parts[0]; $reply['values'][$expense_id]['description'] = $parts[1]; } else { $reply['values'][$expense_id]['expense_type_id'] = 1; // TODO: use default? $reply['values'][$expense_id]['description'] = $expense['description']; } } else { $reply['values'][$expense_id]['expense_type_id'] = 1; // TODO: use default? $reply['values'][$expense_id]['description'] = ''; } $reply['values'][$expense_id]['expense_type'] = CRM_Core_OptionGroup::getLabel('campaign_expense_types', $reply['values'][$expense_id]['expense_type_id']); } } return $reply; }
/** * HRJobContract.get API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_contract_get($params) { $returnFields = array(); if (!empty($params['return'])) { if (is_array($params['return'])) { $returnFields = $params['return']; } else { $returnFields = explode(',', $params['return']); } } $contracts = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); foreach ($contracts['values'] as $key => $contract) { $isCurrent = true; $contractDetails = civicrm_api3('HRJobDetails', 'get', array('sequential' => 1, 'jobcontract_id' => $contract['id'])); $details = CRM_Utils_Array::first($contractDetails['values']); if (!empty($details['period_end_date'])) { if ($details['period_end_date'] < date('Y-m-d')) { $isCurrent = false; } } $contracts['values'][$key]['is_current'] = (int) $isCurrent; foreach ($returnFields as $returnField) { if (!empty($details[$returnField])) { $contracts['values'][$key][$returnField] = $details[$returnField]; } } } return $contracts; }
/** * Function to retrieve case types * * @param $params * * @return array $caseTypes case types keyed by id * @access public */ function civicrm_api3_case_type_get($params) { civicrm_api3_verify_mandatory($params); $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); // format case type, to fetch xml definition return _civicrm_api3_case_type_get_formatResult($caseTypes); }
/** * Returns array of price_sets matching a set of one or more group properties * * @param array $params Array of one or more valid property_name=>value pairs. If $params is set * as null, all price_sets will be returned (default limit is 25) * * @return array Array of matching price_sets * {@getfields price_set_get} * @access public */ function civicrm_api3_price_set_get($params) { $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); // Fetch associated entities foreach ($result as &$item) { $item['entity'] = CRM_Price_BAO_Set::getUsedBy($item['id'], 'entity'); } return civicrm_api3_create_success($result, $params); }
/** * Retrieve case types. * * @param array $params * * @return array * case types keyed by id */ function civicrm_api3_case_type_get($params) { if (!empty($params['options']) && !empty($params['options']['is_count'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); // format case type, to fetch xml definition return _civicrm_api3_case_type_get_formatResult($caseTypes); }
/** * Returns array of project contacts matching a set of one or more properties * * @param array $params Array of one or more valid * property_name=>value pairs. * * @return array Array of matching project contacts * {@getfields volunteer_project_contact_get} * @access public */ function civicrm_api3_volunteer_project_contact_get($params) { $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (!empty($result['values'])) { foreach ($result['values'] as &$projectContact) { $optionValue = civicrm_api3('OptionValue', 'getsingle', array('option_group_id' => CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, 'value' => $projectContact['relationship_type_id'])); $projectContact['relationship_type_label'] = $optionValue['label']; $projectContact['relationship_type_name'] = $optionValue['name']; } } return $result; }
/** * Returns array of groups matching a set of one or more Group properties. * * @param array $params * Array of properties. If empty, all records will be returned. * * @return array * Array of matching groups */ function civicrm_api3_group_get($params) { $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get'); if (empty($options['return']) || !in_array('member_count', $options['return'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group'); } $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group'); foreach ($groups as $id => $group) { $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id); } return civicrm_api3_create_success($groups, $params, 'Group', 'get'); }
/** * Retrieve one or more OptionValues * * @param $params * * @internal param $array $ params input parameters * * {@example OptionValueGet.php 0} * @example OptionValueGet.php * * @return array details of found Option Values * {@getfields OptionValue_get} * @access public */ function civicrm_api3_option_value_get($params) { if (empty($params['option_group_id']) && !empty($params['option_group_name'])) { $opt = array('version' => 3, 'name' => $params['option_group_name']); $optionGroup = civicrm_api('OptionGroup', 'Get', $opt); if (empty($optionGroup['id'])) { return civicrm_api3_create_error("option group name does not correlate to a single option group"); } $params['option_group_id'] = $optionGroup['id']; } return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * HRJobContractRevision.get API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_contract_revision_get($params) { $revisions = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); foreach ($revisions['values'] as $key => $revision) { $editorName = ''; if (!empty($revision['editor_uid'])) { $civiUser = civicrm_custom_user_profile_get_contact($revision['editor_uid']); $editorName = $civiUser['sort_name']; } $revisions['values'][$key]['editor_name'] = $editorName; } return $revisions; }
/** * This API will give list of the groups for particular contact * Particualr status can be sent in params array * If no status mentioned in params, by default 'added' will be used * to fetch the records * * @param array $params name value pair of contact information * {@getfields GroupContact_get} * * @return array list of groups, given contact subsribed to */ function civicrm_api3_group_contact_get($params) { if (empty($params['contact_id'])) { if (empty($params['status'])) { //default to 'Added' $params['status'] = 'Added'; } //ie. id passed in so we have to return something return _civicrm_api3_basic_get('CRM_Contact_BAO_GroupContact', $params); } $status = CRM_Utils_Array::value('status', $params, 'Added'); $values =& CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], $status, NULL, FALSE, TRUE); return civicrm_api3_create_success($values, $params); }
/** * AccountContact.get API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_account_contact_get($params) { $accountContacts = _civicrm_api3_basic_get('CRM_Accountsync_BAO_AccountContact', $params); if (is_array($accountContacts['values'])) { // e.g when we are dealing with 'getcount we skip this. foreach ($accountContacts['values'] as $id => $accountContact) { if (!empty($accountContacts['values'][$id]['accounts_data'])) { $accountContacts['values'][$id]['accounts_data'] = json_decode($accountContacts['values'][$id]['accounts_data'], TRUE); CRM_Accountsync_Hook::mapAccountsData($accountContacts['values'][$id]['accounts_data'], 'contact', $params['plugin']); } } } return $accountContacts; }
/** * Get entity tags. * * @param array $params * * @return array */ function civicrm_api3_entity_tag_get($params) { if (empty($params['entity_id'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } else { //do legacy non-standard behaviour $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']); $result = array(); foreach ($values as $v) { $result[$v] = array('tag_id' => $v); } return civicrm_api3_create_success($result, $params, 'EntityTag'); } }
/** * Get a Membership Type. * * This api is used for finding an existing membership type. * * @param array $params * Array of name/value property values of civicrm_membership_type. * * @return array * API result array. */ function civicrm_api3_membership_type_get($params) { $results = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (!empty($results['values']) && is_array($results['values'])) { foreach ($results['values'] as &$item) { // Workaround for fields using nonstandard serialization foreach (array('relationship_type_id', 'relationship_direction') as $field) { if (isset($item[$field]) && !is_array($item[$field])) { $item[$field] = (array) $item[$field]; } } } } return $results; }
/** * Returns array of groups matching a set of one or more Group properties. * * @param array $params * Array of properties. If empty, all records will be returned. * * @return array * Array of matching groups */ function civicrm_api3_group_get($params) { $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get'); if ((empty($options['return']) || !in_array('member_count', $options['return'])) && empty($params['check_permissions'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group'); } $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group'); foreach ($groups as $id => $group) { if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Group::checkPermission($group['id'])) { unset($groups[$id]); } elseif (!empty($options['return']) && in_array('member_count', $options['return'])) { $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id); } } return civicrm_api3_create_success($groups, $params, 'Group', 'get'); }
/** * Returns array of needs matching a set of one or more group properties * * @param array $params Array of one or more valid * property_name=>value pairs. If $params is set * as null, all needs will be returned * * @return array (referance) Array of matching needs * {@getfields need_get} * @access public */ function civicrm_api3_volunteer_need_get($params) { $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (!empty($result['values'])) { foreach ($result['values'] as &$need) { if (!empty($need['start_time'])) { $need['display_time'] = CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need)); } else { $need['display_time'] = ts('Flexible', array('domain' => 'org.civicrm.volunteer')); } if (isset($need['role_id'])) { $need['role_label'] = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_Upgrader::customOptionGroupName, $need['role_id']); } elseif (CRM_Utils_Array::value('is_flexible', $need)) { $need['role_label'] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel(); } } } return $result; }
/** * Get CiviCRM Domain details. * * @param array $params * * @return array * @throws \API_Exception */ function civicrm_api3_domain_get($params) { $params['version'] = CRM_Utils_Array::value('domain_version', $params); unset($params['version']); $bao = new CRM_Core_BAO_Domain(); if (!empty($params['current_domain'])) { $domainBAO = CRM_Core_Config::domainID(); $params['id'] = $domainBAO; } if (!empty($params['options']) && !empty($params['options']['is_count'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } _civicrm_api3_dao_set_filter($bao, $params, TRUE); $domains = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'Domain'); foreach ($domains as $domain) { if (!empty($domain['contact_id'])) { $values = array(); $locparams = array('contact_id' => $domain['contact_id']); $values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE); $address_array = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2'); if (!empty($values['location']['email'])) { $domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]); } if (!empty($values['location']['phone'])) { $domain['domain_phone'] = array('phone_type' => CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Phone', 'phone_type_id', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])), 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1])); } if (!empty($values['location']['address'])) { foreach ($address_array as $value) { $domain['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]); } } list($domain['from_name'], $domain['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); // Rename version to domain_version, see CRM-17430. $domain['domain_version'] = $domain['version']; unset($domain['version']); $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain); } } return civicrm_api3_create_success($domains, $params, 'Domain', 'get', $bao); }
/** * Returns array of needs matching a set of one or more group properties * * @param array $params Array of one or more valid * property_name=>value pairs. If $params is set * as null, all needs will be returned * * @return array (referance) Array of matching needs * {@getfields need_get} * @access public */ function civicrm_api3_volunteer_need_get($params) { $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); if (!empty($result['values'])) { foreach ($result['values'] as &$need) { if (!empty($need['start_time'])) { $need['display_time'] = CRM_Volunteer_BAO_Need::getTimes($need['start_time'], CRM_Utils_Array::value('duration', $need), CRM_Utils_Array::value('end_time', $need)); } else { $need['display_time'] = CRM_Volunteer_BAO_Need::getFlexibleDisplayTime(); } if (isset($need['role_id'])) { $role = CRM_Core_OptionGroup::getRowValues(CRM_Volunteer_BAO_Assignment::ROLE_OPTION_GROUP, $need['role_id'], 'value'); $need['role_label'] = $role['label']; $need['role_description'] = $role['description']; } elseif (CRM_Utils_Array::value('is_flexible', $need)) { $need['role_label'] = CRM_Volunteer_BAO_Need::getFlexibleRoleLabel(); $need['role_description'] = NULL; } } } return $result; }
/** * @param $params * * @return array */ function civicrm_api3_system_log_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, True, 'SystemLog'); }
/** * Get a ActivityContact. * * @example ActivityContact.php * * @param array $params an associative array of name/value pairs. * * @return array details of found tags else error * * @access public */ function civicrm_api3_activity_contact_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Get details of a particular case, or search for cases, depending on params * * Please provide one (and only one) of the four get/search parameters: * * @param array( 'id' => if set, will get all available info about a case, including contacts and activities * * // if no case_id provided, this function will use one of the following search parameters: * 'client_id' => finds all cases with a specific client * 'activity_id' => returns the case containing a specific activity * 'contact_id' => finds all cases associated with a contact (in any role, not just client) * * {@getfields case_get} * * @return (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found * @access public * @todo Erik Hommel 16 dec 2010 check if all DB fields are returned */ function civicrm_api3_case_get($params) { $options = _civicrm_api3_get_options_from_params($params); //search by client if (!empty($params['contact_id'])) { $ids = array(); foreach ((array) $params['contact_id'] as $cid) { if (is_numeric($cid)) { $ids = array_merge($ids, CRM_Case_BAO_Case::retrieveCaseIdsByContactId($cid, TRUE)); } } $cases = array(); foreach ($ids as $id) { if ($case = _civicrm_api3_case_read($id, $options)) { $cases[$id] = $case; } } return civicrm_api3_create_success($cases, $params, 'case', 'get'); } //search by activity if (!empty($params['activity_id'])) { if (!is_numeric($params['activity_id'])) { return civicrm_api3_create_error('Invalid parameter: activity_id. Must provide a numeric value.'); } $caseId = CRM_Case_BAO_Case::getCaseIdByActivityId($params['activity_id']); if (!$caseId) { return civicrm_api3_create_success(array(), $params, 'case', 'get'); } $case = array($caseId => _civicrm_api3_case_read($caseId, $options)); return civicrm_api3_create_success($case, $params, 'case', 'get'); } //search by contacts if ($contact = CRM_Utils_Array::value('contact_id', $params)) { if (!is_numeric($contact)) { return civicrm_api3_create_error('Invalid parameter: contact_id. Must provide a numeric value.'); } $sql = "\nSELECT DISTINCT case_id\n FROM civicrm_relationship\n WHERE (contact_id_a = {$contact}\n OR contact_id_b = {$contact})\n AND case_id IS NOT NULL"; $dao =& CRM_Core_DAO::executeQuery($sql); $cases = array(); while ($dao->fetch()) { $cases[$dao->case_id] = _civicrm_api3_case_read($dao->case_id, $options); } return civicrm_api3_create_success($cases, $params, 'case', 'get'); } // For historic reasons we always return these when an id is provided $caseId = CRM_Utils_Array::value('id', $params); if ($caseId) { $options['return'] = array('contacts' => 1, 'activities' => 1); } $foundcases = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Case'); $cases = array(); foreach ($foundcases['values'] as $foundcase) { if ($case = _civicrm_api3_case_read($foundcase['id'], $options)) { $cases[$foundcase['id']] = $case; } } return civicrm_api3_create_success($cases, $params, 'case', 'get'); }
/** * Returns array of price_sets matching a set of one or more group properties. * * @param array $params * Array of one or more valid property_name=>value pairs. If $params is set. * as null, all price_sets will be returned (default limit is 25) * * @return array * Array of matching price_sets */ function civicrm_api3_price_set_get($params) { // hack to make getcount work. - not sure the best approach here // as creating an alternate getcount function also feels a bit hacky if (isset($params['options']) && isset($params['options']['is_count'])) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); // Fetch associated entities foreach ($result as &$item) { $item['entity'] = CRM_Price_BAO_PriceSet::getUsedBy($item['id'], 'entity'); } return civicrm_api3_create_success($result, $params); }
/** * Get a membership status. * * This api is used for finding an existing membership status. * * @param array $params an associative array of name/value property values of civicrm_membership_status * * @return Array of all found membership status property values. * {@getfields MembershipStatus_get} * @access public */ function civicrm_api3_membership_status_get($params) { return _civicrm_api3_basic_get('CRM_Member_BAO_MembershipStatus', $params); }
/** * Retrieve one or more Location Types * * @param array input parameters * * * @example LocationTypeGet.php Standard Get Example * * @param array $params an associative array of name/value pairs. * * @return array api result * {@getfields LocationType_get} * @access public */ function civicrm_api3_location_type_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * HRJobPension.get API * * @param array $params * @return array API result descriptor * @throws API_Exception */ function civicrm_api3_h_r_job_pension_get($params) { _civicrm_hrjobcontract_api3_set_current_revision($params, _civicrm_get_table_name(_civicrm_api3_get_BAO(__FUNCTION__))); return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Retrieve one or more PaymentProcessor. * * @param array $params * Array of name/value pairs. * * @return array * API result array */ function civicrm_api3_payment_processor_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Add contact(s) to group(s). * * This api has a legacy/nonstandard signature. * On success, the return array will be structured as follows: * @code * array( * "is_error" => 0, * "version" => 3, * "count" => 3, * "values" => array( * "not_added" => integer, * "added" => integer, * "total_count" => integer * ) * ) * @endcode * * On failure, the return array will be structured as follows: * @code * array( * 'is_error' => 1, * 'error_message' = string, * 'error_data' = mixed or undefined * ) * @endcode * * @param array $params * Input parameters: * - "contact_id" (required): First contact to add, or array of Contact IDs * - "group_id" (required): First group to add contact(s) to, or array of Group IDs * - "status" (optional): "Added" (default), "Pending" or "Removed" * Legacy input parameters (will be deprecated): * - "contact_id.1" etc. (optional): Additional contact_id to add to group(s) * - "group_id.1" etc. (optional): Additional groups to add contact(s) to * * @return array * Information about operation results */ function civicrm_api3_group_contact_create($params) { // Nonstandard bao - doesn't accept ID as a param, so convert id to group_id + contact_id if (!empty($params['id'])) { $getParams = array('id' => $params['id']); $info = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $getParams); if (!empty($info['values'][$params['id']])) { $params['group_id'] = $info['values'][$params['id']]['group_id']; $params['contact_id'] = $info['values'][$params['id']]['contact_id']; } } $action = CRM_Utils_Array::value('status', $params, 'Added'); return _civicrm_api3_group_contact_common($params, $action); }
/** * Retrieve one or more message_template. * * @param array $params * Array of name/value pairs. * * @return array * API result array. */ function civicrm_api3_message_template_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }
/** * Returns array of uf groups (profiles) matching a set of one or more group properties. * * @param array $params * Array per getfields metadata. * * @return array */ function civicrm_api3_uf_field_get($params) { return _civicrm_api3_basic_get('CRM_Core_BAO_UFField', $params); }
/** * Get a mailing_component * * Allowed @params array keys are: * {@getfields mailing_component_get} * @example mailing_componentCreate.php * * @return array of retrieved mailing_component property values. * @access public */ function civicrm_api3_mailing_component_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); }