/**
 * Add or remove fields from the slider widget datastore.
 *
 * @param array $params Arrays of custom field IDs which ought to be added or
 *              removed from the slider widget datastore, keyed by CRM_Core_Action::ADD for
 *              fields which should use the widget, and CRM_Core_Action::DELETE for fields which
 *              should not. If the same custom field ID appears in both the CRM_Core_Action::ADD
 *              and CRM_Core_Action::DELETE arrays, it will be removed.
 */
function _volunteer_update_slider_fields(array $params)
{
    $add = CRM_Utils_Array::value(CRM_Core_Action::ADD, $params, array());
    if (!is_array($add)) {
        $add = array($add);
    }
    $remove = CRM_Utils_Array::value(CRM_Core_Action::DELETE, $params, array());
    if (!is_array($remove)) {
        $remove = array($remove);
    }
    $widgetized_fields = _volunteer_get_slider_fields();
    foreach ($add as $custom_field_id) {
        $widgetized_fields[] = $custom_field_id;
    }
    $widgetized_fields = array_unique($widgetized_fields);
    foreach ($remove as $custom_field_id) {
        $key = array_search($custom_field_id, $widgetized_fields);
        unset($widgetized_fields[$key]);
    }
    sort($widgetized_fields);
    CRM_Core_BAO_Setting::setItem($widgetized_fields, 'CiviVolunteer Configurations', 'slider_widget_fields');
}
/**
 * Add or remove fields from the slider widget datastore.
 *
 * @param array $params Arrays of custom field IDs which ought to be added or
 *              removed from the slider widget datastore, keyed by CRM_Core_Action::ADD for
 *              fields which should use the widget, and CRM_Core_Action::DELETE for fields which
 *              should not. If the same custom field ID appears in both the CRM_Core_Action::ADD
 *              and CRM_Core_Action::DELETE arrays, it will be removed.
 */
function _volunteer_update_slider_fields(array $params)
{
    $add = CRM_Utils_Array::value(CRM_Core_Action::ADD, $params, array());
    if (!is_array($add)) {
        $add = array($add);
    }
    $remove = CRM_Utils_Array::value(CRM_Core_Action::DELETE, $params, array());
    if (!is_array($remove)) {
        $remove = array($remove);
    }
    $widgetized_fields = _volunteer_get_slider_fields();
    foreach ($add as $custom_field_id) {
        $widgetized_fields[] = $custom_field_id;
    }
    $widgetized_fields = array_unique($widgetized_fields);
    foreach ($remove as $custom_field_id) {
        $key = array_search($custom_field_id, $widgetized_fields);
        unset($widgetized_fields[$key]);
    }
    sort($widgetized_fields);
    civicrm_api3('Setting', 'create', array('slider_widget_fields' => $widgetized_fields));
}