PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

count of approved entries with get_lead_count ??

  1. How show count of just approved entries with get_lead_count ??
    i tried this :

    $entry_count = RGFormsModel::get_lead_count(1, "", null, null, null, null);

    but it's all the entries (approved and not approved)

    and if i try

    $entry_count = RGFormsModel::get_lead_count(1, "", null, null, null, true);

    but it's return 0 entry

    what's the solution???

    Posted 13 years ago on Tuesday July 24, 2012 | Permalink
  2. What is an "approved" entry? I'm familiar with read, unread, starred, maybe spam and trash. What do you consider approved? Is that an additional field you're added to your entries?

    Posted 13 years ago on Tuesday July 24, 2012 | Permalink
  3. when you install gravity forms addons, you'll get a function 'get_lead_count' that is defined in the gravity-forms-addons.php:
    function get_lead_count($form_id, $search, $star=null, $read=null, $column, $approved = false, $leads = array(), $start_date = null, $end_date = null, $limituser = false){.....}

    with GF addons you can approve or not an entries to show or not it in your website.

    Posted 13 years ago on Wednesday July 25, 2012 | Permalink
  4. the complete function is :

    function get_lead_count($form_id, $search, $star=null, $read=null, $column, $approved = false, $leads = array(), $start_date = null, $end_date = null, $limituser = false){
    global $wpdb, $current_user;

    if(!is_numeric($form_id))
    return "";

    $detail_table_name = RGFormsModel::get_lead_details_table_name();
    $lead_table_name = RGFormsModel::get_lead_table_name();

    $star_filter = $star !== null ? $wpdb->prepare("AND is_starred=%d ", $star) : "";
    $read_filter = $read !== null ? $wpdb->prepare("AND is_read=%d ", $read) : "";
    if(function_exists('gform_get_meta')) {
    $status_filter = $wpdb->prepare(" AND status=%s ", 'active');
    } else {
    $status_filter = '';
    }
    $start_date_filter = empty($start_date) ? "" : " AND datediff(date_created, '$start_date') >=0";
    $end_date_filter = empty($end_date) ? "" : " AND datediff(date_created, '$end_date') <=0";

    $search_term = "%$search%";
    $search_filter = empty($search) ? "" : $wpdb->prepare("AND ld.value LIKE %s", $search_term);

    $user_filter = '';
    if($limituser) {
    get_currentuserinfo();
    if((int)$current_user->ID !== 0 || ($current_user->ID === 0 && apply_filters('kws_gf_show_entries_if_not_logged_in', apply_filters('kws_gf_treat_not_logged_in_as_user', true)))) {
    if(!empty($current_user->ID)) {
    $user_filter = $wpdb->prepare(" AND l.created_by=%d ", $current_user->ID);
    } else {
    $user_filter = $wpdb->prepare(" AND (created_by IS NULL OR created_by=%d)", $current_user->ID);
    }
    } else {
    return false;
    }

    }

    $in_filter = "";
    if($approved) {
    $in_filter = $wpdb->prepare("l.id IN (SELECT lead_id from $detail_table_name WHERE field_number BETWEEN %f AND %f) AND", $column - 0.001, $column + 0.001);
    // This will work once all the fields are converted to the meta_key after 1.6
    #$search_filter .= $wpdb->prepare(" AND m.meta_key = 'is_approved' AND m.meta_value = %s", 1);
    }

    $sql = "SELECT count(distinct l.id) FROM $lead_table_name as l,
    $detail_table_name as ld";
    # $sql .= function_exists('gform_get_meta') ? " INNER JOIN wp_rg_lead_meta m ON l.id = m.lead_id " : ""; // After 1.6
    $sql .= "
    WHERE $in_filter
    l.form_id=$form_id
    AND ld.form_id=$form_id
    AND l.id = ld.lead_id
    $star_filter
    $read_filter
    $status_filter
    $user_filter
    $start_date_filter
    $end_date_filter
    $search_filter";

    return $wpdb->get_var($sql);
    }

    Posted 13 years ago on Wednesday July 25, 2012 | Permalink