plugin_name = $plugin_name; $this->version = $version; add_shortcode('ays_survey_submissions_summary', array($this, 'ays_generate_submissions_summary_method')); } public function ays_survey_get_data_by_survey_id( $attr ){ global $wpdb; $surveys_table = esc_sql( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys" ); $survey_id = (isset($attr['id']) && sanitize_text_field( $attr['id'] ) != '') ? absint( sanitize_text_field( $attr['id'] ) ) : null; if ( is_null( $survey_id ) ) { return null; } $results = array(); $sql = "SELECT * FROM " . $surveys_table . " WHERE id =" . absint( $survey_id ); $survey_name = $wpdb->get_row( $sql, 'ARRAY_A' ); if ( empty( $survey_name ) || is_null( $survey_name ) ) { return null; } // // For charts in summary $survey_question_results = Survey_Maker_Data::ays_survey_question_results_for_summary( $survey_id ); $question_results = $survey_question_results['questions']; $last_submission = Survey_Maker_Data::ays_survey_get_last_submission_id_for_summary( $survey_id ); $ays_survey_individual_questions = Survey_Maker_Data::ays_survey_individual_results_for_one_submission_for_summary( $last_submission, $survey_name ); if( empty( $ays_survey_individual_questions['sections'] ) ){ $question_results = array(); } $submission_count_and_ids = Survey_Maker_Data::get_submission_count_and_ids_for_summary( $survey_id ); wp_localize_script( $this->plugin_name . 'public-charts', 'aysSurveyPublicChartLangObj', array( 'answers' => __( 'Answers' , "survey-maker" ), 'percent' => __( 'Percent' , "survey-maker" ), 'count' => __( 'Count' , "survey-maker" ), ) ); $options = array( 'perAnswerData' => $question_results, 'surveyColor' => $this->options[ $this->name_prefix . 'color' ], 'sectionDescHtml' => $this->options[ $this->name_prefix . 'allow_html_in_section_description' ], ); $script = ''; $results = array( 'ays_survey_individual_questions' => $ays_survey_individual_questions, 'submission_count_and_ids' => $submission_count_and_ids, 'question_results' => $question_results, 'script' => $script, 'options' => $options, ); return $results; } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Survey_Maker_Loader as all of the hooks are defined * in that particular class. * * The Survey_Maker_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name . "-public-submissions", SURVEY_MAKER_PUBLIC_URL . '/css/partials/survey-maker-public-submissions.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts(){ /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Survey_Maker_Loader as all of the hooks are defined * in that particular class. * * The Survey_Maker_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name . 'public-charts-google', SURVEY_MAKER_ADMIN_URL . '/js/google-chart.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . 'public-charts', SURVEY_MAKER_PUBLIC_URL . '/js/partials/survey-maker-public-submissions-charts.js', array('jquery'), $this->version, true); } public function ays_submissions_summary_html( $attr ){ $content = array(); $results = $this->ays_survey_get_data_by_survey_id( $attr ); if( $results === null ){ $content = "
" . __( "There are no questions atteched yet.", "survey-maker" ) . "
"; return $content; } $ays_survey_individual_questions = $results['ays_survey_individual_questions']; $submission_count_and_ids = $results['submission_count_and_ids']; $question_results = $results['question_results']; $script = $results['script']; // Allow HTML in description $survey_allow_html_in_section_description = (isset($results['options'][ 'sectionDescHtml' ]) && $results['options'][ 'sectionDescHtml' ] == 'on') ? true : false; $text_types = array( 'text', 'short_text', 'number', 'phone', 'name', 'email', 'date', 'time', ); $content[] = '" . $this->default_texts['wrongShortcode'] . "
"; return str_replace(array("\r\n", "\n", "\r"), '', $content); } $this->enqueue_styles(); $this->enqueue_scripts(); $unique_id = uniqid(); $this->unique_id = $unique_id; $this->unique_id_in_class = $id . "-" . $unique_id; $survey = Survey_Maker_Data::get_survey_by_id( $id ); $this->options = Survey_Maker_Data::get_survey_validated_data_from_array( $survey, $attr ); $content = $this->ays_submissions_summary_html( $attr ); return str_replace(array("\r\n", "\n", "\r"), "\n", $content); } }