Ejemplo n.º 1
0
/**
 * Use this API to create a new group. See the CRM Data Model for custom_group property definitions
 * $params['class_name'] is a required field, class being extended.
 *
 * @param $params     array   Associative array of property name/value pairs to insert in group.
 *
 *
 * @return   Newly create custom_group object
 *
 * @access public 
 */
function civicrm_custom_group_create($params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error("params is not an array");
    }
    // Require either param['class_name'] (string) - for backwards compatibility - OR parm['extends'] (array)
    // If passing extends array - set class_name (e.g. 'Contact', 'Participant'...) as extends[0]. You may optionally
    // pass an extends_entity_column_value as extends[1] (e.g. an Activity Type ID).
    if (isset($params['class_name']) && trim($params['class_name'])) {
        $params['extends'][0] = trim($params['class_name']);
    } else {
        if (!isset($params['extends']) || !is_array($params['extends'])) {
            return civicrm_create_error("Params must include either 'class_name' (string) or 'extends' (array).");
        } else {
            if (!isset($params['extends'][0]) || !trim($params['extends'][0])) {
                return civicrm_create_error("First item in params['extends'] must be a class name (e.g. 'Contact').");
            }
        }
    }
    $error = _civicrm_check_required_fields($params, 'CRM_Core_DAO_CustomGroup');
    require_once 'CRM/Utils/String.php';
    if (!isset($params['title']) || !trim($params['title'])) {
        return civicrm_create_error("Title parameter is required.");
    }
    if (!isset($params['style']) || !trim($params['style'])) {
        $params['style'] = 'Inline';
    }
    if (is_a($error, 'CRM_Core_Error')) {
        return civicrm_create_error($error->_errors[0]['message']);
    }
    require_once 'CRM/Core/BAO/CustomGroup.php';
    $customGroup = CRM_Core_BAO_CustomGroup::create($params);
    _civicrm_object_to_array($customGroup, $values);
    if (is_a($customGroup, 'CRM_Core_Error')) {
        return civicrm_create_error($customGroup->_errors[0]['message']);
    } else {
        $values['is_error'] = 0;
    }
    if (CRM_Utils_Array::value('html_type', $params)) {
        $params['custom_group_id'] = $customGroup->id;
        $fieldValues = civicrm_custom_field_create($params);
        $values = array_merge($values, $fieldValues['result']);
    }
    return $values;
}
Ejemplo n.º 2
0
 function createCustomField()
 {
     $ids = array();
     $params = array('custom_group_id' => $this->_customGroupId, 'label' => 'Enter text about relationship', 'html_type' => 'Text', 'data_type' => 'String', 'default_value' => 'xyz', 'weight' => 1, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
     $customField =& civicrm_custom_field_create($params);
     $customField = null;
     $ids[] = $customField['result']['customFieldId'];
     $optionValue[] = array('label' => 'Red', 'value' => 'R', 'weight' => 1, 'is_active' => 1);
     $optionValue[] = array('label' => 'Yellow', 'value' => 'Y', 'weight' => 2, 'is_active' => 1);
     $optionValue[] = array('label' => 'Green', 'value' => 'G', 'weight' => 3, 'is_active' => 1);
     $params = array('label' => 'Pick Color', 'html_type' => 'Select', 'data_type' => 'String', 'weight' => 2, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, 'option_values' => $optionValue, 'custom_group_id' => $this->_customGroupId);
     $customField =& civicrm_custom_field_create($params);
     $ids[] = $customField['result']['customFieldId'];
     $params = array('custom_group_id' => $this->_customGroupId, 'name' => 'test_date', 'label' => 'test_date', 'html_type' => 'Select Date', 'data_type' => 'Date', 'default_value' => '20090711', 'weight' => 3, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
     $customField =& civicrm_custom_field_create($params);
     $ids[] = $customField['result']['customFieldId'];
     $params = array('custom_group_id' => $this->_customGroupId, 'name' => 'test_link', 'label' => 'test_link', 'html_type' => 'Link', 'data_type' => 'Link', 'default_value' => 'http://civicrm.org', 'weight' => 4, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
     $customField =& civicrm_custom_field_create($params);
     $ids[] = $customField['result']['customFieldId'];
     return $ids;
 }
Ejemplo n.º 3
0
 /**
  * check with data type - Multi-Select Options array
  */
 function testCustomFieldMultiSelectOptionValueCreate()
 {
     $customGroup = $this->customGroupCreate('Contact', 'MultiSelect_test_group');
     $params = array('custom_group_id' => $customGroup['id'], 'label' => 'PriceMufdlti', 'html_type' => 'Multi-Select', 'data_type' => 'String', 'weight' => 4, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1, 'option_label' => array('MultiLabel1', 'MultiLabel2'), 'option_value' => array(10, 20), 'option_weight' => array(1, 2), 'option_status' => array(1, 1));
     $customField =& civicrm_custom_field_create($params);
     $this->assertEquals($customField['is_error'], 0);
     $this->assertNotNull($customField['result']['customFieldId']);
     $this->customFieldDelete($customField['result']['customFieldId']);
     $this->customGroupDelete($customGroup['id']);
 }
Ejemplo n.º 4
0
 /**
  * Function to create custom field with Option Values
  * 
  * @param array    $customGroup
  * @param string $name  name of custom field
  */
 function customFieldOptionValueCreate($customGroup, $name)
 {
     require_once 'api/v2/CustomGroup.php';
     $fieldParams = array('custom_group_id' => $customGroup['id'], 'name' => 'test_custom_group', 'label' => 'Country', 'html_type' => 'Select', 'data_type' => 'String', 'weight' => 4, 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1);
     $optionGroup = array('domain_id' => 1, 'name' => 'option_group1', 'label' => 'option_group_label1');
     $optionValue = array('option_label' => array('Label1', 'Label2'), 'option_value' => array('value1', 'value2'), 'option_name' => array($name . '_1', $name . '_2'), 'option_weight' => array(1, 2));
     $params = array_merge($fieldParams, $optionGroup, $optionValue);
     $result =& civicrm_custom_field_create($params);
     if (civicrm_error($result) || !CRM_Utils_Array::value('customFieldId', $result['result'])) {
         throw new Exception('Could not create Custom Field');
     }
     return $result;
 }