Esempio n. 1
0
/**
 * This function was totally rewritten in 2.1.0 for the new field settings structure. The ft_form_fields table
 * stores all the main settings for form fields which are shared across all fields, regardless of their
 * type. But some field types have "extended" settings, i.e. settings that only relate to that field type;
 * e.g. file upload fields allow for custom file upload URL & folders. Extended settings can now be created
 * by the administrator for any form field type through the Custom Fields module.
 *
 * Inheritance
 * -----------
 * When editing a field, the user has the option of checking the "Use Default" option for each field. If that's
 * checked, it will always inherit the setting value from the "default_value" setting value, defined in the
 * Custom Fields field type setting. Database-wise, if that value is checked, nothing is stored in the database:
 * this keeps the DB size as trim as possible.
 *
 * This function always returns all extended settings for a field, even those that use the default. The format
 * is:
 *
 *   array(
 *     array(
 *       "setting_id"    => X,
 *       "setting_value" => "...",
 *       "uses_default"  => true/false
 *     ),
 *     ...
 *   );
 *
 * @param integer $field_id
 * @param string $setting_id (optional)
 * @param boolean $convert_dynamic_values defaults to false just in case...
 * @return array an array of hashes
 */
function ft_get_extended_field_settings($field_id, $setting_id = "", $convert_dynamic_values = false)
{
    // get whatever custom settings are defined for this field
    $custom_settings = ft_get_form_field_settings($field_id);
    // now get a list of all available settings for this field type
    $field_type_id = ft_get_field_type_id($field_id);
    $field_type_settings = ft_get_field_type_settings($field_type_id);
    $settings = array();
    foreach ($field_type_settings as $curr_setting) {
        $curr_setting_id = $curr_setting["setting_id"];
        if (!empty($setting_id) && $setting_id != $curr_setting_id) {
            continue;
        }
        $uses_default = true;
        $setting_value_type = $curr_setting["default_value_type"];
        $setting_value = $curr_setting["default_value"];
        if (array_key_exists($curr_setting_id, $custom_settings)) {
            $uses_default = false;
            $setting_value = $custom_settings[$curr_setting_id];
        }
        if ($convert_dynamic_values && $setting_value_type == "dynamic") {
            $parts = explode(",", $setting_value);
            if (count($parts) == 2) {
                $setting_value = ft_get_settings($parts[0], $parts[1]);
            }
        }
        $settings[] = array("setting_id" => $curr_setting_id, "setting_value" => $setting_value, "uses_default" => $uses_default);
    }
    extract(ft_process_hook_calls("end", compact("field_id", "setting_name"), array("settings")), EXTR_OVERWRITE);
    return $settings;
}
Esempio n. 2
0
/**
 * Returns the View field values from the view_fields table, as well as a few values
 * from the corresponding form_fields table.
 *
 * @param integer $view_id the unique View ID
 * @param integer $field_id the unique field ID
 * @return array a hash containing the various view field values
 */
function ft_get_view_field($view_id, $field_id, $custom_params = array())
{
    global $g_table_prefix;
    $params = array("include_field_settings" => isset($custom_params["include_field_settings"]) ? $custom_params["include_field_settings"] : false);
    $query = mysql_query("\r\n    SELECT vf.*, ft.field_title, ft.col_name, ft.field_type_id, ft.field_name\r\n    FROM   {$g_table_prefix}view_fields vf, {$g_table_prefix}form_fields ft\r\n    WHERE  view_id = {$view_id} AND\r\n           vf.field_id = ft.field_id AND\r\n           vf.field_id = {$field_id}\r\n      ");
    $result = mysql_fetch_assoc($query);
    if ($params["include_field_settings"]) {
        $result["field_settings"] = ft_get_form_field_settings($field_id);
    }
    return $result;
}