Beispiel #1
0
 public function add_view($view, $form_id)
 {
     if ($view == 'gf_results_' . $this->_slug) {
         GFResults::results_page($form_id, $this->_title, 'gf_entries', $view);
     }
 }
Beispiel #2
0
 public function get_results($form_id)
 {
     $this->authorize("gravityforms_view_entries");
     $s = rgget("s");
     // search criteria
     $search_criteria = false === empty($s) && is_array($s) ? $s : array();
     $form = GFAPI::get_form($form_id);
     if (!$form) {
         self::die_not_found();
     }
     // for the Web API return all fields
     $fields = rgar($form, "fields");
     $form_id = $form["id"];
     $key = $this->get_results_cache_key($form_id, $fields, $search_criteria);
     $key_tmp = "tmp" . $key;
     $data = get_option($key, array());
     $cache_meta = $this->get_results_cache_meta($form_id);
     // add the cache meta early so form editor updates can test for valid field hash
     if (empty($cache_meta)) {
         $this->update_results_cache_meta($form_id, $fields, 0);
     }
     $cache_expiry = rgar($cache_meta, "timestamp");
     $cache_timestamp = isset($data["timestamp"]) ? $data["timestamp"] : 0;
     $cache_expired = $cache_expiry ? $cache_expiry > $cache_timestamp : false;
     // check for valid cached results first
     if (!empty($data) && "complete" == rgar($data, "status") && !$cache_expired) {
         $results = $data;
         $status = 200;
         if (isset($results["progress"])) {
             unset($results["progress"]);
         }
     } else {
         $state = get_option($key_tmp);
         if (empty($state) || "complete" == rgar($data, "status") && $cache_expired) {
             if (!class_exists("GFResults")) {
                 require_once GFCommon::get_base_path() . "/includes/addon/class-gf-results.php";
             }
             $gf_results = new GFResults($this->_slug, array());
             $max_execution_time = 5;
             $results = $gf_results->get_results_data($form, $fields, $search_criteria, $state, $max_execution_time);
             if ("complete" == $results["status"]) {
                 $status = 200;
                 if (false == empty($state)) {
                     delete_option($key_tmp);
                 }
             } else {
                 if (false === empty($data) && "complete" == rgar($data, "status") && $cache_expired) {
                     $data["status"] = "expired";
                     $data["progress"] = $results["progress"];
                     $this->update_results_cache($key, $data);
                 }
                 $this->update_results_cache($key_tmp, $results);
                 $this->schedule_results_cron($form, $fields, $search_criteria);
                 if ($data) {
                     $results = $data;
                 }
                 $status = 202;
             }
         } else {
             // The cron task is recursive, not periodic, so system restarts, script timeouts and memory issues can prevent the cron from restarting.
             // Check timestamp and kick off the cron again if it appears to have stopped
             $state_timestamp = rgar($state, "timestamp");
             $state_age = time() - $state_timestamp;
             if ($state_age > 180 && !$this->results_cron_is_scheduled($form, $fields, $search_criteria)) {
                 $this->schedule_results_cron($form, $fields, $search_criteria);
             }
             if (false === empty($data) && "expired" == rgar($data, "status")) {
                 $results = $data;
             } else {
                 $results = $state;
             }
             $status = 202;
         }
     }
     $fields = $results["field_data"];
     // add choice labels to the results so the client doesn't need to cross-reference with the form object
     $results["field_data"] = $this->results_data_add_labels($form, $fields);
     $this->end($status, $results);
 }
 /**
  * Initializes the result page functionality. To activate result page functionality, override the get_results_page_config() function.
  *
  * @param $results_page_config - configuration returned by get_results_page_config()
  */
 protected function results_page_init($results_page_config)
 {
     require_once "class-gf-results.php";
     if (isset($results_page_config["callbacks"]["filters"])) {
         add_filter("gform_filters_pre_results", $results_page_config["callbacks"]["filters"], 10, 2);
     }
     if (isset($results_page_config["callbacks"]["filter_ui"])) {
         add_filter("gform_filter_ui", $results_page_config["callbacks"]["filter_ui"], 10, 5);
     }
     $gf_results = new GFResults($this->_slug, $results_page_config);
     $gf_results->init();
 }
 /**
  * Initializes the result page functionality. To activate result page functionality, override the get_results_page_config() function.
  *
  * @param $results_page_config - configuration returned by get_results_page_config()
  */
 public function results_page_init($results_page_config)
 {
     require_once 'class-gf-results.php';
     if (isset($results_page_config['callbacks']['filters'])) {
         add_filter('gform_filters_pre_results', $results_page_config['callbacks']['filters'], 10, 2);
     }
     if (isset($results_page_config['callbacks']['filter_ui'])) {
         add_filter('gform_filter_ui', $results_page_config['callbacks']['filter_ui'], 10, 5);
     }
     $gf_results = new GFResults($this->_slug, $results_page_config);
     $gf_results->init();
 }
Beispiel #5
0
 public function get_results($form_id)
 {
     $this->log_debug(__METHOD__ . '(): Running.');
     $capability = apply_filters('gform_web_api_capability_get_results', 'gravityforms_view_entries');
     $this->authorize($capability);
     $s = rgget('s');
     // search criteria
     $search_criteria = false === empty($s) && is_array($s) ? $s : array();
     $form = GFAPI::get_form($form_id);
     if (!$form) {
         self::die_not_found();
     }
     // for the Web API return all fields
     $fields = rgar($form, 'fields');
     $form_id = $form['id'];
     $key = $this->get_results_cache_key($form_id, $fields, $search_criteria);
     $key_tmp = 'tmp' . $key;
     $data = get_option($key, array());
     $cache_meta = $this->get_results_cache_meta($form_id);
     // add the cache meta early so form editor updates can test for valid field hash
     if (empty($cache_meta)) {
         $this->update_results_cache_meta($form_id, $fields, 0);
     }
     $cache_expiry = rgar($cache_meta, 'timestamp');
     $cache_timestamp = isset($data['timestamp']) ? $data['timestamp'] : 0;
     $cache_expired = $cache_expiry ? $cache_expiry > $cache_timestamp : false;
     // check for valid cached results first
     if (!empty($data) && 'complete' == rgar($data, 'status') && !$cache_expired) {
         $results = $data;
         $status = 200;
         if (isset($results['progress'])) {
             unset($results['progress']);
         }
     } else {
         $state = get_option($key_tmp);
         if (empty($state) || 'complete' == rgar($data, 'status') && $cache_expired) {
             if (!class_exists('GFResults')) {
                 require_once GFCommon::get_base_path() . '/includes/addon/class-gf-results.php';
             }
             $gf_results = new GFResults($this->_slug, array());
             $max_execution_time = 5;
             $results = $gf_results->get_results_data($form, $fields, $search_criteria, $state, $max_execution_time);
             if ('complete' == rgar($data, 'status')) {
                 $status = 200;
                 if (false == empty($state)) {
                     delete_option($key_tmp);
                 }
             } else {
                 if (false === empty($data) && 'complete' == rgar($data, 'status') && $cache_expired) {
                     $data['status'] = 'expired';
                     $data['progress'] = $results['progress'];
                     $this->update_results_cache($key, $data);
                 }
                 $this->update_results_cache($key_tmp, $results);
                 $this->schedule_results_cron($form, $fields, $search_criteria);
                 if ($data) {
                     $results = $data;
                 }
                 $status = 202;
             }
         } else {
             // The cron task is recursive, not periodic, so system restarts, script timeouts and memory issues can prevent the cron from restarting.
             // Check timestamp and kick off the cron again if it appears to have stopped
             $state_timestamp = rgar($state, 'timestamp');
             $state_age = time() - $state_timestamp;
             if ($state_age > 180 && !$this->results_cron_is_scheduled($form, $fields, $search_criteria)) {
                 $this->schedule_results_cron($form, $fields, $search_criteria);
             }
             if (false === empty($data) && 'expired' == rgar($data, 'status')) {
                 $results = $data;
             } else {
                 $results = $state;
             }
             $status = 202;
         }
     }
     $fields = rgar($results, 'field_data');
     if (!empty($fields)) {
         // add choice labels to the results so the client doesn't need to cross-reference with the form object
         $results['field_data'] = $this->results_data_add_labels($form, $fields);
     }
     $this->end($status, $results);
 }
Beispiel #6
0
 private static function get_addon_global_data($form, $options, $fields)
 {
     /* if the results class isn't loaded, load it */
     if (!class_exists("GFResults")) {
         require_once GFCommon::get_base_path() . "/includes/addon/class-gf-results.php";
     }
     $form_id = $form['id'];
     /* add form filter to keep in line with GF standard */
     $form = apply_filters("gform_form_pre_results_{$form_id}", apply_filters('gform_form_pre_results', $form));
     /* initiat the results class */
     $gf_results = new GFResults('', $options);
     /* ensure that only active leads are queried */
     $search = array('field_filters' => array('mode' => ''), 'status' => 'active');
     /* get the results */
     $data = $gf_results->get_results_data($form, $fields, $search);
     /* unset some array keys we don't need */
     unset($data['status']);
     unset($data['timestamp']);
     return $data;
 }
Beispiel #7
0
 public function add_view($view, $form_id)
 {
     if ($view == "gf_results_" . $this->_slug) {
         $form = GFFormsModel::get_form_meta($form_id);
         $filters = array();
         GFResults::results_page($form_id, $this->_field_types, $this->_title, "gf_edit_forms", $view, $filters);
     }
 }
Beispiel #8
0
 protected function results_page_init($results_page_config)
 {
     require_once "class-gf-results.php";
     $this->register_script("gaddon_results_js", GFAddOn::get_gfaddon_base_url() . "/js/gaddon_results.js", array("jquery", "sack"), GFCommon::$version, true);
     $this->register_script('jquery-ui-resizable', false, array('jquery'), false, false);
     $this->register_script('jquery-ui-datepicker', false, array('jquery'), false, false);
     $this->register_script('google_charts', "https://www.google.com/jsapi", array('jquery'), false, false);
     $this->register_style("gaddon_results_css", GFAddOn::get_gfaddon_base_url() . "/css/gaddon_results.css", null, GFCommon::$version);
     $gf_results = new GFResults($this->_slug, $results_page_config);
     $gf_results->init();
 }