Example #1
0
/**
 * Gets a CiviCRM Dashlets according to parameters.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_dashboard_get($params)
{
    $bao = new CRM_Core_BAO_Dashboard();
    _civicrm_api3_dao_set_filter($bao, $params, TRUE);
    $dashlets = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'Dashboard');
    return civicrm_api3_create_success($dashlets, $params, 'Dashboard', 'get', $bao);
}
/**
 * Get CiviCRM domain details
 * {@getfields domain_create}
 * @example DomainGet.php
 */
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 (CRM_Utils_Array::value('current_domain', $params)) {
        $domainBAO = CRM_Core_Config::domainID();
        $params['id'] = $domainBAO;
    }
    _civicrm_api3_dao_set_filter($bao, $params, true, 'domain');
    $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);
            $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain);
        }
    }
    return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao);
}
/**
 * Get CiviCRM Action Schedule details
 * {@getfields action_schedule_create}
 *
 */
function civicrm_api3_action_schedule_get($params)
{
    $bao = new CRM_Core_BAO_ActionSchedule();
    _civicrm_api3_dao_set_filter($bao, $params, true, 'ActionSchedule');
    $actionSchedules = _civicrm_api3_dao_to_array($bao, $params, true, 'ActionSchedule');
    return civicrm_api3_create_success($actionSchedules, $params, 'action_schedule', 'get', $bao);
}
/**
 * Get CiviCRM Word Replacement details
 * {@getfields word_replacement_create}
 * 
 */
function civicrm_api3_word_replacement_get($params)
{
    $bao = new CRM_Core_BAO_WordReplacement();
    _civicrm_api3_dao_set_filter($bao, $params, true, 'WordReplacement');
    $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, true, 'WordReplacement');
    return civicrm_api3_create_success($wordReplacements, $params, 'word_replacement', 'get', $bao);
}
Example #5
0
/**
 * Gets a CiviCRM Dashlets according to parameters.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_dashboard_get($params)
{
    // NEVER COPY THIS. No idea why a newish api would not use basic_get.
    $bao = new CRM_Core_BAO_Dashboard();
    _civicrm_api3_dao_set_filter($bao, $params, TRUE);
    $dashlets = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'Dashboard');
    return civicrm_api3_create_success($dashlets, $params, 'Dashboard', 'get', $bao);
}
/**
 * Get CiviCRM Word Replacement details.
 *
 * @param array $params
 *
 * @return array
 * @throws \API_Exception
 */
function civicrm_api3_word_replacement_get($params)
{
    // NEVER COPY THIS. No idea why a newish api would not use basic_get.
    $bao = new CRM_Core_BAO_WordReplacement();
    _civicrm_api3_dao_set_filter($bao, $params, TRUE);
    $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'WordReplacement');
    return civicrm_api3_create_success($wordReplacements, $params, 'WordReplacement', 'get', $bao);
}
Example #7
0
/**
 * Activity.GetAbsences API
 *
 * This is a variation on Activity.get with additional filtering behavior suitable for activities.
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_activity_getabsences($params)
{
    // activity_type_id: int|string|array(int|string)
    // period_id: int|array(int)
    // target_contact_id: int
    $activityTypes = CRM_Core_PseudoConstant::activityType();
    // ****** Defaults ******
    if (!isset($params['activity_type_id'])) {
        $params['activity_type_id'] = CRM_HRAbsence_BAO_HRAbsenceType::getActivityTypes();
    }
    // ****** Build query ******
    $select = new CRM_HRAbsence_DGWDIHTWT('civicrm_activity request');
    $select->select('request.*')->groupBy('request.id')->join('absence', 'INNER JOIN civicrm_activity absence ON (absence.source_record_id = request.id AND absence.activity_type_id = #typeId)', array('#typeId' => array_search('Absence', $activityTypes)));
    if (!empty($params['period_id'])) {
        $periodIds = (array) $params['period_id'];
        $dateExprs = array();
        // array(string $sqlExpression)
        foreach ($periodIds as $periodId) {
            $period = civicrm_api3('HRAbsencePeriod', 'getsingle', array('id' => $periodId));
            $dateExprs[] = $select->interpolate('min(absence.activity_date_time) between @start and @end', array('@start' => $period['start_date'], '@end' => $period['end_date']));
        }
        $select->having(implode(' or ', $dateExprs));
    }
    if (!empty($params['activity_type_id'])) {
        $typeIds = (array) $params['activity_type_id'];
        foreach (array_keys($typeIds) as $key) {
            if (!is_numeric($typeIds[$key])) {
                $typeIds[$key] = array_search($typeIds[$key], $activityTypes);
                if ($typeIds[$key] === FALSE) {
                    throw new API_Exception("Invalid activity type");
                }
            }
        }
        $select->where('request.activity_type_id IN (#typeIds)', array('#typeIds' => $typeIds));
    }
    if (!empty($params['target_contact_id'])) {
        $activityContactTypes = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
        $select->join('tgt', 'INNER JOIN civicrm_activity_contact tgt
        ON tgt.activity_id = request.id
        AND tgt.record_type_id = #tgt
        AND tgt.contact_id IN (#targetIds)', array('#tgt' => CRM_Utils_Array::key('Activity Targets', $activityContactTypes), '#targetIds' => (array) $params['target_contact_id']));
    }
    // ****** Execute query ******
    $entity = _civicrm_api3_get_BAO(__FUNCTION__);
    $bao = CRM_Core_DAO::executeQuery($select->toSQL(), array(), TRUE, 'CRM_Activity_BAO_Activity');
    $activities = _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity, FALSE);
    $activities = _civicrm_api3_activity_get_formatResult($params, $activities);
    return civicrm_api3_create_success($activities, $params, $entity, 'getAbsences');
}
Example #8
0
/**
 * Add an Address for a contact.
 *
 * FIXME: Should be using basic_create util
 *
 * @param array $params
 *   Array per getfields metadata.
 *
 * @return array
 *   API result array
 */
function civicrm_api3_address_create(&$params)
{
    _civicrm_api3_check_edit_permissions('CRM_Core_BAO_Address', $params);
    /**
     * If street_parsing, street_address has to be parsed into
     * separate parts
     */
    if (array_key_exists('street_parsing', $params)) {
        if ($params['street_parsing'] == 1) {
            if (array_key_exists('street_address', $params)) {
                if (!empty($params['street_address'])) {
                    $parsedItems = CRM_Core_BAO_Address::parseStreetAddress($params['street_address']);
                    if (array_key_exists('street_name', $parsedItems)) {
                        $params['street_name'] = $parsedItems['street_name'];
                    }
                    if (array_key_exists('street_unit', $parsedItems)) {
                        $params['street_unit'] = $parsedItems['street_unit'];
                    }
                    if (array_key_exists('street_number', $parsedItems)) {
                        $params['street_number'] = $parsedItems['street_number'];
                    }
                    if (array_key_exists('street_number_suffix', $parsedItems)) {
                        $params['street_number_suffix'] = $parsedItems['street_number_suffix'];
                    }
                }
            }
        }
    }
    if (!isset($params['check_permissions'])) {
        $params['check_permissions'] = 0;
    }
    /**
     * Create array for BAO (expects address params in as an
     * element in array 'address'
     */
    $addressBAO = CRM_Core_BAO_Address::add($params, TRUE);
    if (empty($addressBAO)) {
        return civicrm_api3_create_error("Address is not created or updated ");
    } else {
        $values = _civicrm_api3_dao_to_array($addressBAO, $params);
        return civicrm_api3_create_success($values, $params, 'Address', $addressBAO);
    }
}
function civicrm_api3_pcpteams_getRank($params)
{
    $result = CRM_Core_DAO::$_nullArray;
    //check the hasPermission to view details
    $permParams = array('pcp_id' => $params['pcp_id']);
    if (!_civicrm_pcpteams_permission_check($permParams, CRM_Core_Permission::VIEW)) {
        return civicrm_api3_create_error('insufficient permission to view this record');
    }
    $dao = new CRM_PCP_DAO_PCP();
    $dao->page_id = $params['page_id'];
    //dao result
    $result = @_civicrm_api3_dao_to_array($dao);
    $pcpAmounts = array();
    foreach ($result as $pcps) {
        $pcpAmounts[$pcps['id']] = civicrm_api3_pcpteams_getAmountRaised(array('pcp_id' => $pcps['id'], 'version' => 3));
    }
    //remove pcps doesn't have donations
    arsort($pcpAmounts);
    //get count the pages has donations
    $hasDonations = count(array_filter($pcpAmounts));
    //check this pcp has some donations
    if ($pcpAmounts[$params['pcp_id']] == null) {
        $rank = $hasDonations + 1;
    } else {
        $rank = array_search($params['pcp_id'], array_keys($pcpAmounts)) + 1;
    }
    switch ($rank % 10) {
        // Handle 1st, 2nd, 3rd
        case 1:
            $suffix = 'st';
            break;
        case 2:
            $suffix = 'nd';
            break;
        case 3:
            $suffix = 'rd';
            break;
        default:
            $suffix = 'th';
            break;
    }
    $rankResult[$params['page_id']]['rank'] = $rank;
    $rankResult[$params['page_id']]['suffix'] = $suffix;
    $rankResult[$params['page_id']]['pcp_id'] = $params['pcp_id'];
    $rankResult[$params['page_id']]['rankHolder'] = $result[$params['pcp_id']]['title'];
    $rankResult[$params['page_id']]['pageCount'] = count($result);
    $rankResult[$params['page_id']]['hasDonations'] = $hasDonations;
    $rankResult[$params['page_id']]['noDonations'] = count($result) - $hasDonations;
    $result = $rankResult;
    return civicrm_api3_create_success($result, $params);
}
Example #10
0
/**
 * Function to do a 'custom' api get
 *
 * @param string $bao_name name of BAO
 * @param array $params params from api
 * @param bool $returnAsSuccess return in api success format
 * @param string $entity
 *
 * @return array
 */
function _civicrm_hrjobcontract_api3_custom_get($bao_name, &$params, $returnAsSuccess = TRUE, $entity = "")
{
    $bao = new $bao_name();
    $callbacks = array();
    $fields = $bao::fields();
    foreach ($fields as $field) {
        if (!empty($field['callback'])) {
            $callback = $field['callback'];
            if (CRM_Utils_System::validCallback($callback)) {
                list($className, $fnName) = explode('::', $callback);
                if (method_exists($className, $fnName)) {
                    $callbacks[$field['name']] = array('className' => $className, 'fnName' => $fnName);
                }
            }
        }
    }
    _civicrm_api3_dao_set_filter($bao, $params, TRUE, $entity);
    if ($returnAsSuccess) {
        $daoToArray = _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity);
        if (!empty($callbacks)) {
            foreach ($daoToArray as $entryKey => $entryValue) {
                foreach ($callbacks as $callbackKey => $callbackValue) {
                    $daoToArray[$entryKey][$callbackKey] = call_user_func(array($callbackValue['className'], $callbackValue['fnName']), $entryValue[$callbackKey]);
                }
            }
        }
        return civicrm_api3_create_success($daoToArray, $params, $entity, 'get');
    } else {
        return _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity, 'get');
    }
}
Example #11
0
/**
 * Function to do a 'standard' api get - when the api is only doing a $bao->find then use this.
 *
 * @param string $bao_name
 *   Name of BAO.
 * @param array $params
 *   Params from api.
 * @param bool $returnAsSuccess
 *   Return in api success format.
 * @param string $entity
 *
 * @return array
 */
function _civicrm_api3_basic_get($bao_name, &$params, $returnAsSuccess = TRUE, $entity = "")
{
    $bao = new $bao_name();
    _civicrm_api3_dao_set_filter($bao, $params, TRUE);
    if ($returnAsSuccess) {
        return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity, 'get');
    } else {
        return _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity, 'get');
    }
}