Masterstudy_Helpers::select_quiz_from_course_func()

Return all the specific fields of a form ID provided in ajax call


Parameters Parameters

$include_any

(string) (Required)


Source Source

File: src/integrations/masterstudy-lms/helpers/masterstudy-helpers.php

	public function select_quiz_from_course_func() {



		// Nonce and post object validation
		Automator()->utilities->ajax_auth_check( $_POST );

		$fields = [
			[
				'value' => '-1',
				'text'  => _x( 'Any quiz', 'MasterStudy LMS', 'uncanny-automator' ),
			],
		];

		if ( ! isset( $_POST ) ) {
			echo wp_json_encode( $fields );
			die();
		}

		$mslms_course_id = $_POST['values']['MSLMSCOURSE'];

		if ( absint( $mslms_course_id ) || '-1' === $mslms_course_id ) {
			global $wpdb;

			$course_quiz_q =
				"Select ID, post_title
				FROM $wpdb->posts
				WHERE FIND_IN_SET(
					ID,
					(SELECT meta_value FROM wp_postmeta WHERE post_id = %d AND meta_key = 'curriculum')
				)
				AND post_type = 'stm-quizzes'
				ORDER BY post_title ASC";

			$course_quiz_p = $wpdb->prepare( $course_quiz_q, absint( $mslms_course_id ) );

			if ( '-1' === $mslms_course_id ) {
				$course_quiz_p =
					"Select ID, post_title
				FROM $wpdb->posts
				WHERE post_type = 'stm-quizzes'
				ORDER BY post_title ASC";
			}

			$quizzes = $wpdb->get_results( $course_quiz_p );

			foreach ( $quizzes as $lesson ) {
				$fields[] = array(
					'value' => $lesson->ID,
					'text'  => $lesson->post_title,
				);
			}
		}

		echo wp_json_encode( $fields );
		die();
	}