示例#1
0
/**
 * Retrieves everything about a form submission. It contains a lot of meta-information about the field,
 * from the form_fields and view_tabs. If the optional view_id parameter is included, only the fields
 * in the View are returned (AND all system fields, if they're not included).
 *
 * @param integer $form_id the unique form ID
 * @param integer $submission_id the unique submission ID
 * @param integer $view_id an optional view ID parameter
 * @return array Returns an array of hashes. Each index is a separate form field and its value is
 *           a hash of information about it, such as value, field type, field size, etc.
 */
function ft_get_submission($form_id, $submission_id, $view_id = "")
{
    global $g_table_prefix;
    $return_arr = array();
    $form_fields = ft_get_form_fields($form_id);
    $submission = ft_get_submission_info($form_id, $submission_id);
    $view_fields = !empty($view_id) ? ft_get_view_fields($view_id) : array();
    if (empty($submission)) {
        return array();
    }
    $view_field_ids = array();
    foreach ($view_fields as $view_field) {
        $view_field_ids[] = $view_field["field_id"];
    }
    // for each field, combine the meta form info (like field size, type, data type etc) from $form_fields
    // with the info about the submission itself. Also, if there's a View specified, filter out any fields
    // that aren't used in the View
    foreach ($form_fields as $field_info) {
        $field_id = $field_info["field_id"];
        // if we're looking at this submission through a View,
        if (!empty($view_id) && !in_array($field_id, $view_field_ids)) {
            continue;
        }
        // if the submission contains contents for this field, add it
        if (array_key_exists($field_info['col_name'], $submission)) {
            $field_info["content"] = $submission[$field_info['col_name']];
        }
        // if a view ID is specified, return the view-specific field info as well
        if (!empty($view_id)) {
            $field_view_info = ft_get_view_field($view_id, $field_id);
            if (!empty($field_view_info)) {
                foreach ($field_view_info as $key => $value) {
                    $field_info[$key] = $value;
                }
            }
        }
        $return_arr[] = $field_info;
    }
    // finally, if a View is specified, ensure that the order in which the submission fields are returned
    // is determined by the View. [NOT efficient!]
    if (!empty($view_id)) {
        $ordered_return_arr = array();
        foreach ($view_fields as $view_field_info) {
            $field_id = $view_field_info["field_id"];
            foreach ($return_arr as $field_info) {
                if ($field_info["field_id"] == $field_id) {
                    $ordered_return_arr[] = $field_info;
                    break;
                }
            }
        }
        $return_arr = $ordered_return_arr;
    }
    extract(ft_process_hook_calls("end", compact("form_id", "submission_id", "view_id", "return_arr"), array("return_arr")), EXTR_OVERWRITE);
    return $return_arr;
}
示例#2
0
文件: views.php 项目: jdearaujo/core
/**
 * Returns all fields in a View.
 *
 * @param integer $view_id the unique View ID
 * @return array $info an array of hashes containing the various view field values.
 */
function ft_get_view_fields($view_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);
    $result = mysql_query("\r\n    SELECT vf.field_id\r\n    FROM   {$g_table_prefix}list_groups lg, {$g_table_prefix}view_fields vf\r\n    WHERE  lg.group_type = 'view_fields_{$view_id}' AND\r\n           lg.group_id = vf.group_id\r\n    ORDER BY lg.list_order ASC, vf.list_order ASC\r\n  ");
    $fields_info = array();
    while ($field_info = mysql_fetch_assoc($result)) {
        $field_id = $field_info["field_id"];
        $fields_info[] = ft_get_view_field($view_id, $field_id, $params);
    }
    return $fields_info;
}