_plugin_constants = $dependencies[ 'ASS_Constants' ]; } /** * Ensure that only one instance of ASS_Survey is loaded or can be loaded (Singleton Pattern). * * @since 1.0.0 * @access public * * @param array $dependencies Array of instance objects of all dependencies of ASS_Survey model. * @return ASS_Survey */ public static function instance( $dependencies ) { if ( !self::$_instance instanceof self ) self::$_instance = new self( $dependencies ); return self::$_instance; } /** * Get survey ids to load. * * @since 1.0.1 * @access public * * @param $order_id WC_Order Order Id. * @return array Array of stdClass objects. */ public function get_surveys_to_load( $order_id ) { $number_of_surveys_to_load = apply_filters( 'as_survey_number_of_surveys_to_load' , 1 ); $order = wc_get_order( $order_id ); $customer = $order->get_user(); if ( !$customer ) { $customer = new stdClass(); $customer->ID = 0; $customer->first_name = ASS_Helper::get_order_data( $order , 'billing_first_name' ); $customer->last_name = ASS_Helper::get_order_data( $order , 'billing_last_name' ); $customer->user_email = ASS_Helper::get_order_data( $order , 'billing_email' ); $customer->roles = array( 'guest' ); } $surveys = ASS_Helper::get_all_surveys( $number_of_surveys_to_load ); $surveys = apply_filters( 'as_survey_filter_surveys' , $surveys , $order , $customer ); return $surveys; } /** * Render survey cta. * * @since 1.0.0 * @access public */ public function render_survey_cta( $survey_id , $order_id ) { $survey_cta_title = get_post_meta( $survey_id , $this->_plugin_constants->POST_META_SURVEY_CTA_TITLE() , true ); $survey_cta_content = get_post_meta( $survey_id , $this->_plugin_constants->POST_META_SURVEY_CTA_CONTENT() , true ); include ( $this->_plugin_constants->VIEWS_ROOT_PATH() . 'survey/cta/survey-popup-cta.php' ); } /** * Render after sale survey pop up. * This includes the pop up itself, hooks and the survey from. * Note: hooks are used in order to add the survey cta and thank you as well. * * @since 1.0.0 * @access public * * @param $order_id * @return string */ public function render_survey_popup( $order_id ) { $surveys = $this->get_surveys_to_load( $order_id ); foreach ( $surveys as $survey ) { $survey_id = $survey->ID; $survey_post = get_post( $survey_id ); $survey_questions = get_post_meta( $survey_id , $this->_plugin_constants->POST_META_SURVEY_QUESTIONS() , true ); if ( !is_array( $survey_questions ) ) $survey_questions = array(); $survey_submission_controls = ''; // Construct survey heading ob_start(); wc_get_template( 'survey/survey-heading.php' , array( 'survey_post' => $survey_post ) , $this->_plugin_constants->THEME_TEMPLATE_PATH() , $this->_plugin_constants->TEMPLATES_ROOT_PATH() ); $survey_heading_markup = ob_get_clean(); if ( empty( $survey_questions ) || ( isset( $survey_questions[1] ) && empty( $survey_questions[1] ) ) ) { // TODO: Log errors $survey_questions_markup = '

' . __( 'This survey has no registered questions' , 'after-sale-surveys' ) . '

'; } else { // Construct survey questions $survey_questions = get_post_meta( $survey_id , $this->_plugin_constants->POST_META_SURVEY_QUESTIONS() , true ); if ( !is_array( $survey_questions ) ) $survey_questions = array(); ob_start(); ?>
$question_data ) { foreach( $question_data as $order_number => $question ) { $located = wc_locate_template( 'question-types/' . $question[ 'question-type' ] . '.php' , $this->_plugin_constants->THEME_TEMPLATE_PATH() , $this->_plugin_constants->TEMPLATES_ROOT_PATH() ); if ( file_exists( $located ) ) wc_get_template( 'question-types/' . $question[ 'question-type' ] . '.php' , array( 'survey_id' => $survey_id , 'page_number' => $page_number ,'order_number' => $order_number , 'question' => $question ) , $this->_plugin_constants->THEME_TEMPLATE_PATH() , $this->_plugin_constants->TEMPLATES_ROOT_PATH() ); else do_action( 'as_survey_load_question_template' , $question , $survey_id , $page_number , $order_number ); } break; // Only iterate once. ASS only has the notion of 1 paged survey } ?>
_plugin_constants->THEME_TEMPLATE_PATH() , $this->_plugin_constants->TEMPLATES_ROOT_PATH() ); $survey_submission_controls = ob_get_clean(); } ob_start(); ?>
data-survey-id="">
_plugin_constants->POST_META_SURVEY_THANK_YOU_TITLE() , true ); $survey_thank_you_content = get_post_meta( $survey_id , $this->_plugin_constants->POST_META_SURVEY_THANK_YOU_CONTENT() , true ); include ( $this->_plugin_constants->VIEWS_ROOT_PATH() . 'survey/thank-you/survey-thank-you.php' ); } } }