Example #1
0
 /**
  * Get submissions based on specific critera.
  * 
  * @since 2.7
  * @param array $args
  * @return array $sub_ids
  */
 public function get($args = array())
 {
     $query_args = array('post_type' => 'nf_sub', 'posts_per_page' => -1, 'date_query' => array('inclusive' => true));
     if (isset($args['form_id'])) {
         $query_args['meta_query'][] = array('key' => '_form_id', 'value' => $args['form_id']);
     }
     if (isset($args['seq_num'])) {
         $query_args['meta_query'][] = array('key' => '_seq_num', 'value' => $args['seq_num']);
     }
     if (isset($args['user_id'])) {
         $query_args['author'] = $args['user_id'];
     }
     if (isset($args['action'])) {
         $query_args['meta_query'][] = array('key' => '_action', 'value' => $args['action']);
     }
     if (isset($args['meta'])) {
         foreach ($args['meta'] as $key => $value) {
             $query_args['meta_query'][] = array('key' => $key, 'value' => $value);
         }
     }
     if (isset($args['fields'])) {
         foreach ($args['fields'] as $field_id => $value) {
             $query_args['meta_query'][] = array('key' => '_field_' . $field_id, 'value' => $value);
         }
     }
     if (isset($args['begin_date']) and $args['begin_date'] != '') {
         $query_args['date_query']['after'] = nf_get_begin_date($args['begin_date'])->format("Y-m-d G:i:s");
     }
     if (isset($args['end_date']) and $args['end_date'] != '') {
         $query_args['date_query']['before'] = nf_get_end_date($args['end_date'])->format("Y-m-d G:i:s");
     }
     $subs = new WP_Query($query_args);
     $sub_objects = array();
     if (is_array($subs->posts) && !empty($subs->posts)) {
         foreach ($subs->posts as $sub) {
             $sub_objects[] = Ninja_Forms()->sub($sub->ID);
         }
     }
     wp_reset_postdata();
     return $sub_objects;
 }
Example #2
0
 /**
  * Filter our submission list by form_id
  * 
  * @access public
  * @since 2.7
  * @return void
  */
 public function table_filter($query)
 {
     global $pagenow;
     if ($pagenow == 'edit.php' && is_admin() && (isset($query->query['post_type']) && $query->query['post_type'] == 'nf_sub') && is_main_query()) {
         $qv =& $query->query_vars;
         if (!empty($_GET['form_id'])) {
             $form_id = $_GET['form_id'];
         } else {
             $form_id = 0;
         }
         $plugin_settings = nf_get_settings();
         $date_format = $plugin_settings['date_format'];
         if (!empty($_GET['begin_date'])) {
             $begin_date = nf_get_begin_date($_GET['begin_date'])->format("Y-m-d G:i:s");
         } else {
             $begin_date = '';
         }
         if (!empty($_GET['end_date'])) {
             $end_date = nf_get_end_date($_GET['end_date'])->format("Y-m-d G:i:s");
         } else {
             $end_date = '';
         }
         if ($begin_date > $end_date) {
             $begin_date = new DateTime($begin_date);
             $end_date = new DateTime($end_date);
             $end_date_temp = $begin_date;
             $begin_date_temp = $end_date;
             $begin_date = $begin_date_temp;
             $end_date = $end_date_temp;
             $_GET['begin_date'] = $begin_date->format('m/d/Y');
             $_GET['end_date'] = $end_date->format('m/d/Y');
             $begin_date = $begin_date->format("Y-m-d G:i:s");
             $end_date = $end_date->format("Y-m-d G:i:s");
         }
         if (!isset($qv['date_query'])) {
             $qv['date_query'] = array('after' => $begin_date, 'before' => $end_date);
         }
         if (!isset($qv['meta_query'])) {
             $qv['meta_query'] = array(array('key' => '_form_id', 'value' => $form_id, 'compare' => '='));
         }
         $qv = apply_filters('nf_subs_table_qv', $qv, $form_id);
     }
 }
Example #3
0
/**
 * ninja_forms_get_subs() has been deprecated in favour of Ninja_Forms()->subs()->get( $args ) or Ninja_Forms()->form( 23 )->get_subs( $args )
 * You can also use WordPress queries ,since this is a custom post type.
 * 
 * @since 2.7
 */
function ninja_forms_get_subs($args = array())
{
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    if (is_array($args) and !empty($args)) {
        $subs_results = array();
        $meta_query = array();
        $date_query = array();
        if (isset($args['form_id'])) {
            $meta_query[] = array('key' => '_form_id', 'value' => $args['form_id']);
        }
        if (isset($args['user_id'])) {
            $query_args['author'] = $args['user_id'];
        }
        if (isset($args['action'])) {
            $meta_query[] = array('key' => '_action', 'value' => $args['action']);
        }
        if (isset($args['begin_date']) and $args['begin_date'] != '') {
            $query_args['date_query']['after'] = nf_get_begin_date($args['begin_date'])->format("Y-m-d G:i:s");
        }
        if (isset($args['end_date']) and $args['end_date'] != '') {
            $query_args['date_query']['before'] = nf_get_end_date($args['end_date'])->format("Y-m-d G:i:s");
        }
        $query_args = array('post_type' => 'nf_sub', 'date_query' => $date_query, 'meta_query' => $meta_query, 'posts_per_page' => -1);
        $subs = get_posts($query_args);
        if (is_array($subs) && !empty($subs)) {
            $x = 0;
            foreach ($subs as $sub) {
                $data = array();
                $subs_results[$x]['id'] = $sub->ID;
                $subs_results[$x]['user_id'] = $sub->post_author;
                $subs_results[$x]['form_id'] = get_post_meta($sub->ID, '_form_id');
                $subs_results[$x]['action'] = get_post_meta($sub->ID, '_action');
                $meta = get_post_custom($sub->ID);
                foreach ($meta as $key => $array) {
                    if (strpos($key, '_field_') !== false) {
                        $field_id = str_replace('_field_', '', $key);
                        $user_value = $array[0];
                        $data[] = array('field_id' => $field_id, 'user_value' => $user_value);
                    }
                }
                $subs_results[$x]['data'] = $data;
                $subs_results[$x]['date_updated'] = $sub->post_modified;
                $x++;
            }
        }
        return $subs_results;
    }
}