Gravity_Forms_Survey_Funnel_Survey

This class prepares the html, css and javascript for displaying the survey with the correct settings.

Defined (1)

The class is defined in the following location(s).

/classes/class-gravity-forms-survey-funnel-survey.php  
  1. class Gravity_Forms_Survey_Funnel_Survey { 
  2.  
  3. /** 
  4. * Initializes the surveys 
  5. */ 
  6. static function init() { 
  7. // Check if a survey should be shown 
  8. $surveyId = get_option( 'gravity-forms-survey-funnel-survey-id' ); 
  9. if( ( ! is_numeric($surveyId) || $surveyId == -1 ) || 
  10. ( isset( $_COOKIE['gravity-forms-survey-funnel-survey-id-' . $surveyId ] ) ) ) 
  11. return; 
  12.  
  13. // Prepare scripts and styles 
  14. add_action( 'init', array( __CLASS__, 'prepare_dependencies' ) ); 
  15.  
  16. // Prepare html 
  17. add_action( 'wp_footer', array( __CLASS__, 'prepare_form') ); 
  18.  
  19. /** 
  20. * Prepares the scripts and styles of the form 
  21. */ 
  22. static function prepare_dependencies() { 
  23. // Enqueue cookie script 
  24. wp_enqueue_script( 
  25. 'gravity-forms-survey-funnel-jquery-cookies',  
  26. Gravity_Forms_Survey_Funnel::getPluginUrl() . '/js/jquery-cookie.js',  
  27. array('jquery') 
  28. ); 
  29.  
  30. // Pick the styles and scripts depending on what survey position is set. 
  31. if( get_option('gravity-forms-survey-funnel-survey-position') == 'popup' ) { 
  32. $script = 'survey-popup.js'; 
  33. $style = 'survey-popup.css'; 
  34. } else { 
  35. $script = 'survey-bottomleft.js'; 
  36. $style = 'survey-bottomleft.css'; 
  37.  
  38. // Enqueue survey script 
  39. wp_enqueue_script( 
  40. 'gravity-forms-survey-funnel-survey-script',  
  41. Gravity_Forms_Survey_Funnel::getPluginUrl() . '/js/' . $script,  
  42. array('jquery', 'gravity-forms-survey-funnel-jquery-cookies') 
  43. ); 
  44.  
  45. // Enqueue survey style 
  46. wp_enqueue_style( 
  47. 'gravity-forms-survey-funnel-survey-style',  
  48. Gravity_Forms_Survey_Funnel::getPluginUrl() . '/css/' . $style 
  49. ); 
  50.  
  51. /** 
  52. * Outputs the html of the form 
  53. */ 
  54. static function prepare_form() { 
  55. $surveyId = get_option('gravity-forms-survey-funnel-survey-id'); 
  56.  
  57. $minimalized = get_option('gravity-forms-survey-funnel-survey-minimalized'); 
  58.  
  59. // Get form object 
  60. $form = self::get_form( get_option('gravity-forms-survey-funnel-survey-id') ); 
  61.  
  62. // Get correct file by survey position 
  63. if( get_option('gravity-forms-survey-funnel-survey-position') == 'popup' ) 
  64. $file = 'survey-popup.php'; 
  65. else 
  66. $file = 'survey-bottomleft.php'; 
  67.  
  68. // Include the survey screen 
  69. include_once( Gravity_Forms_Survey_Funnel::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $file ); 
  70.  
  71. /** 
  72. * Get form 
  73. *  
  74. * @param int $survey_id 
  75. * @return stdObject $form 
  76. */ 
  77. static function get_form( $survey_id ) { 
  78. $not_available_message = '<p>' . __('We\'re sorry, the survey is not available at the moment.', 'gravity-forms-survey-funnel') . '</p>';  
  79. if( ! is_numeric( $survey_id ) ) 
  80. return $not_available_message; 
  81.  
  82. // Get form object 
  83. $form = RGFormsModel::get_form( $survey_id ); 
  84.  
  85. // Get form content 
  86. ob_start(); 
  87. gravity_form( 
  88. $survey_id,  
  89. $display_title = false,  
  90. $display_description = true,  
  91. $display_inactive = false,  
  92. $field_values = null,  
  93. $ajax = true 
  94. ); 
  95. $form->content = ob_get_clean(); 
  96.  
  97. if( ! empty( $form ) ) 
  98. return $form; 
  99. return $not_available_message;