Example #1
0
/**
 * Deletes an existing Website.
 *
 * @todo convert to using Basic delete - BAO function non standard
 *
 * @param array $params
 *
 * @return array
 *   API result array
 * @throws \API_Exception
 */
function civicrm_api3_website_delete($params)
{
    //DO NOT USE THIS FUNCTION AS THE BASIS FOR A NEW API http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
    civicrm_api3_verify_mandatory($params, NULL, array('id'));
    _civicrm_api3_check_edit_permissions('CRM_Core_BAO_Website', array('id' => $params['id']));
    $websiteDAO = new CRM_Core_DAO_Website();
    $websiteDAO->id = $params['id'];
    if ($websiteDAO->find()) {
        while ($websiteDAO->fetch()) {
            $websiteDAO->delete();
            return civicrm_api3_create_success(1, $params, 'Website', 'delete');
        }
    } else {
        throw new API_Exception('Could not delete Website with id ' . $params['id']);
    }
}
Example #2
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);
    }
}
Example #3
0
/**
 * Function to do a 'standard' api del.
 *
 * When the api is only doing a $bao::del then use this if api::del doesn't exist it will try DAO delete method.
 *
 * @param string $bao_name
 * @param array $params
 *
 * @return array
 *   API result array
 * @throws API_Exception
 * @throws \Civi\API\Exception\UnauthorizedException
 */
function _civicrm_api3_basic_delete($bao_name, &$params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('id'));
    _civicrm_api3_check_edit_permissions($bao_name, array('id' => $params['id']));
    $args = array(&$params['id']);
    if (method_exists($bao_name, 'del')) {
        $bao = call_user_func_array(array($bao_name, 'del'), $args);
        if ($bao !== FALSE) {
            return civicrm_api3_create_success(TRUE);
        }
        throw new API_Exception('Could not delete entity id ' . $params['id']);
    } elseif (method_exists($bao_name, 'delete')) {
        $dao = new $bao_name();
        $dao->id = $params['id'];
        if ($dao->find()) {
            while ($dao->fetch()) {
                $dao->delete();
                return civicrm_api3_create_success();
            }
        } else {
            throw new API_Exception('Could not delete entity id ' . $params['id']);
        }
    }
    throw new API_Exception('no delete method found');
}