Example #1
0
/**
 *  Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions).
 *
 * @param array $params an associative array used in construction / retrieval of the object
 * @return $tag object a new tag object
 * @access public
 */
function crm_create_tag($params)
{
    require_once 'CRM/Core/BAO/Tag.php';
    $error = _crm_check_required_fields($params, 'CRM_Core_DAO_Tag');
    if (is_a($error, 'CRM_Core_Error')) {
        return $error;
    }
    $ids = array();
    return CRM_Core_BAO_Tag::add($params, $ids);
}
Example #2
0
/**
 * Create a Event
 *  
 * This API is used for creating a Event
 * 
 * @param   array  $params  an associative array of title/value property values of civicrm_event
 * 
 * @return array of newly created event property values.
 * @access public
 */
function crm_create_event($params)
{
    _crm_initialize();
    if (!is_array($params)) {
        return _crm_error('Params is not an array.');
    }
    if (!$params["title"] || !$params['event_type_id'] || !$params['start_date']) {
        return _crm_error('Missing require fileds ( title, event type id,start date)');
    }
    $error = _crm_check_required_fields($params, 'CRM_Event_DAO_Event');
    if (is_a($error, 'CRM_Core_Error')) {
        return $error;
    }
    $ids['event'] = $params['id'];
    $ids['eventTypeId'] = $params['event_type_id'];
    $ids['startDate'] = $params['start_date'];
    require_once 'CRM/Event/BAO/Event.php';
    $eventBAO = CRM_Event_BAO_Event::add($params, $ids);
    $event = array();
    _crm_object_to_array($eventBAO, $event);
    return $event;
}
Example #3
0
/**
 * Create a Membership Type
 *  
 * This API is used for creating a Membership Type
 * 
 * @param   array  $params  an associative array of name/value property values of civicrm_membership_type
 * 
 * @return array of newly created membership type property values.
 * @access public
 */
function crm_create_membership_type($params)
{
    _crm_initialize();
    if (!is_array($params)) {
        return _crm_error('Params is not an array.');
    }
    if (!isset($params['name']) || !isset($params['duration_unit']) || !isset($params['duration_interval'])) {
        return _crm_error('Missing require fileds ( name, duration unit,duration interval)');
    }
    $error = _crm_check_required_fields($params, 'CRM_Member_DAO_MembershipType');
    if (is_a($error, 'CRM_Core_Error')) {
        return $error;
    }
    $ids['membershipType'] = CRM_Utils_Array::value('id', $params);
    $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $params);
    $ids['contributionType'] = CRM_Utils_Array::value('contribution_type_id', $params);
    require_once 'CRM/Member/BAO/MembershipType.php';
    $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($params, $ids);
    $membershipType = array();
    _crm_object_to_array($membershipTypeBAO, $membershipType);
    return $membershipType;
}
/**
 * Updating Custom Field.
 * 
 * Use this API to update the custom Field. See the CRM Data Model for custom_field property definitions.
 * Updating the html_type enum value and data_type enum value is not allowed.
 * 
 * @param $params      Array   Associative array of property name/value pairs of custom field.
 *
 * @param $customField Object  Object of (CRM_Core_BAO_CustomField) custom field to be updated.
 * 
 * @return   Updated custom_field object
 *
 * @access public 
 */
function crm_update_custom_field($params, $customField)
{
    _crm_initialize();
    if (!isset($customField->id)) {
        return _crm_error("id of the custom field is not set.");
    }
    if (!is_array($params)) {
        return _crm_error("params is not of array type");
    }
    if (isset($params['html_type']) || isset($params['data_type'])) {
        return _crm_error("Updating html_type and/or data_type is not allowed.");
    }
    $params['id'] = $customField->id;
    if (!isset($params['custom_group_id'])) {
        $params['custom_group_id'] = $customField->custom_group_id;
    }
    if (!isset($params['weight'])) {
        $params['weight'] = $customField->weight;
    }
    $checkFields = _crm_check_required_fields($params, 'CRM_Core_DAO_CustomField');
    if (is_a($checkFields, 'CRM_Core_Error')) {
        return $checkFields;
    }
    $updateObject = _crm_update_object($customField, $params);
    if (is_a($updateObject, 'CRM_Core_Error')) {
        return $updateObject;
    }
    return $customField;
    //require_once 'CRM/Core/BAO/CustomField.php';
    //return CRM_Core_BAO_CustomField::create($params);
}