Пример #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 array of newly created tag property values.
 * @access public
 */
function civicrm_tag_create(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array'));
    }
    if (empty($params)) {
        return civicrm_create_error(ts('No input parameters present'));
    }
    $error = _civicrm_check_required_fields($params, 'CRM_Core_DAO_Tag');
    if ($error['is_error']) {
        return civicrm_create_error($error['error_message']);
    }
    require_once 'CRM/Core/BAO/Tag.php';
    $ids = array('tag' => CRM_Utils_Array::value('tag', $params));
    if (CRM_Utils_Array::value('tag', $params)) {
        $ids['tag'] = $params['tag'];
    }
    $tagBAO = CRM_Core_BAO_Tag::add($params, $ids);
    if (is_a($tagBAO, 'CRM_Core_Error')) {
        return civicrm_create_error("Tag is not created");
    } else {
        $values = array();
        _civicrm_object_to_array($tagBAO, $values);
        $tag = array();
        $tag['tag_id'] = $values['id'];
        $tag['is_error'] = 0;
    }
    return $tag;
}
Пример #2
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 civicrm_membership_type_create(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params need to be of type array!');
    }
    if (empty($params)) {
        return civicrm_create_error('No input parameters present');
    }
    if (!isset($params['name']) || !isset($params['duration_unit']) || !isset($params['duration_interval'])) {
        return civicrm_create_error('Missing require fileds ( name, duration unit,duration interval)');
    }
    $error = _civicrm_check_required_fields($params, 'CRM_Member_DAO_MembershipType');
    if ($error['is_error']) {
        return civicrm_create_error($error['error_message']);
    }
    $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);
    if (is_a($membershipTypeBAO, 'CRM_Core_Error')) {
        return civicrm_create_error("Membership is not created");
    } else {
        $membershipType = array();
        _civicrm_object_to_array($membershipTypeBAO, $membershipType);
        $values = array();
        $values['id'] = $membershipType['id'];
        $values['is_error'] = 0;
    }
    return $values;
}
Пример #3
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 civicrm_event_create(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array');
    }
    if (!isset($params['title']) || !isset($params['event_type_id']) || !isset($params['start_date'])) {
        return civicrm_create_error('Missing require fields ( title, event type id,start date)');
    }
    $error = _civicrm_check_required_fields($params, 'CRM_Event_DAO_Event');
    if ($error['is_error']) {
        return civicrm_create_error($error['error_message']);
    }
    // Do we really want $params[id], even if we have
    // $params[event_id]? if yes then please uncomment the below line
    //$ids['event'      ] = $params['id'];
    $ids['eventTypeId'] = $params['event_type_id'];
    $ids['startDate'] = $params['start_date'];
    $ids['event_id'] = CRM_Utils_Array::value('event_id', $params);
    require_once 'CRM/Event/BAO/Event.php';
    $eventBAO = CRM_Event_BAO_Event::create($params, $ids);
    if (is_a($eventBAO, 'CRM_Core_Error')) {
        return civicrm_create_error("Event is not created");
    } else {
        $event = array();
        _civicrm_object_to_array($eventBAO, $event);
        $values = array();
        $values['event_id'] = $event['id'];
        $values['is_error'] = 0;
    }
    return $values;
}
Пример #4
0
function civicrm_verify_mandatory(&$params, $daoName = null, $keys = array())
{
    if (!is_array($params)) {
        throw new Exception('Input parameters is not an array');
    }
    if ($daoName != null) {
        _civicrm_check_required_fields($params, $daoName, true);
    }
    foreach ($keys as $key) {
        if (!array_key_exists($key, $params)) {
            throw new Exception("Mandatory param missing: " . $key);
        }
    }
}
Пример #5
0
/**
 * Defines 'custom field' within a group.
 *
 *
 * @param $params       array  Associative array of property name/value pairs to create new custom field.
 *
 * @return Newly created custom_field id array
 *
 * @access public 
 *
 */
function civicrm_custom_field_create($params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error("params is not an array ");
    }
    if (!CRM_Utils_Array::value('custom_group_id', $params)) {
        return civicrm_create_error("Missing Required field :custom_group_id");
    }
    if (!CRM_Utils_Array::value('label', $params)) {
        return civicrm_create_error("Missing Required field :label");
    }
    if (!CRM_Utils_Array::value('option_type', $params)) {
        if (CRM_Utils_Array::value('id', $params)) {
            $params['option_type'] = 2;
        } else {
            $params['option_type'] = 1;
        }
    }
    $error = _civicrm_check_required_fields($params, 'CRM_Core_DAO_CustomField');
    if (is_a($error, 'CRM_Core_Error')) {
        return civicrm_create_error($error->_errors[0]['message']);
    }
    // Array created for passing options in params
    if (isset($params['option_values']) && is_array($params['option_values'])) {
        foreach ($params['option_values'] as $key => $value) {
            $params['option_label'][$value['weight']] = $value['label'];
            $params['option_value'][$value['weight']] = $value['value'];
            $params['option_status'][$value['weight']] = $value['is_active'];
            $params['option_weight'][$value['weight']] = $value['weight'];
        }
    }
    require_once 'CRM/Core/BAO/CustomField.php';
    $customField = CRM_Core_BAO_CustomField::create($params);
    $values['customFieldId'] = $customField->id;
    if (is_a($customField, 'CRM_Core_Error') && is_a($column, 'CRM_Core_Error')) {
        return civicrm_create_error($customField->_errors[0]['message']);
    } else {
        return civicrm_create_success($values);
    }
}