function get_data_set(WP_REST_Request $request)
 {
     // Build the response
     $response = null;
     switch ($request['set']) {
         case 'no-of-interested':
             $response = wpcampus_get_interested_count();
             break;
         case 'affiliation':
             $response = array('work_in_higher_ed' => wpcampus_get_work_in_higher_ed_count(), 'work_for_company' => wpcampus_get_work_for_company_count(), 'work_outside_higher_ed' => wpcampus_get_work_outside_higher_ed_count());
             break;
         case 'attend-preference':
             $response = array('attend_in_person' => wpcampus_get_attend_in_person_count(), 'attend_live_stream' => wpcampus_get_attend_live_stream_count());
             break;
         case 'attend-has-location':
             $response = wpcampus_get_interested_has_location_count();
             break;
         case 'attend-country':
             $response = wpcampus_get_interest_by_country();
             break;
         case 'best-time-of-year':
             $response = wpcampus_get_interest_best_time_of_year();
             break;
         case 'sessions':
             $response = wpcampus_get_interest_sessions();
             break;
         case 'universities':
             $response = wpcampus_get_interest_universities();
             break;
         case 'vote-on-new-name':
             $response = wpcampus_get_vote_on_new_name();
             break;
     }
     // If no response, return an error
     if (!$response) {
         return new WP_Error('wpcampus', 'This data set is either invalid or does not contain information.', array('status' => 404));
     } else {
         // Return a response object
         return new WP_REST_Response($response);
     }
 }
function format_wpcampus_data_set($count, $format = 'number')
{
    switch ($format) {
        case 'number':
        case 'both':
            $number = $count;
            if ('number' == $format) {
                return $number;
            }
        case 'percent':
        case 'both':
            // Get total
            $total = wpcampus_get_interested_count();
            // Add percentage
            $percent = round($count / $total * 100) . '%';
            if ('percent' == $format) {
                return $percent;
            }
            return "{$number} ({$percent})";
        default:
            return $count;
    }
}
Ejemplo n.º 3
0
function wpcampus_get_interest_sessions()
{
    // Get form in
    if ($form = GFAPI::get_form(1)) {
        // Loop through each field
        $field_id = 15;
        foreach ($form['fields'] as $field) {
            // Only for our specific field id
            if ($field['id'] != $field_id) {
                continue;
            }
            // Make sure we have choices
            if (!$field['choices']) {
                return false;
            }
            // Store counts - start with total
            $counts = array('Total' => wpcampus_get_interested_count());
            // Get by option
            $choice_index = 1;
            foreach ($field['choices'] as $choice) {
                // Setup search criteria
                $search_criteria = array('status' => 'active');
                // Setup field filters
                // Modified to match checkbox filter sample in get_entries(), per https://www.gravityhelp.com/documentation/article/api-functions/#get_entries
                $search_criteria['field_filters'][] = array('key' => "{$field_id}", 'operator' => 'in', 'value' => array($choice['value']));
                // Get the count
                $this_counts = GFAPI::count_entries(1, $search_criteria);
                // Add to counts
                $counts[$choice['value']] = $this_counts;
                $choice_index++;
            }
            return $counts;
        }
    }
    return false;
}