Quiz::dozent_save_quiz()

Add Lecture Action


Source

File: classes/Quiz.php

	public function dozent_save_quiz() {
		$course_id    = (int) dozent_input_text( 'course_id' );
		$item_id      = (int) dozent_input_text( 'item_id' );
		$title        = dozent_input_text( 'title' );
		$quiz_content = dozent_input_array_field( 'quiz_content' );
		$section_id   = dozent_input_array_field( 'section_id' );

		$post_arr = [
			'post_type'    => 'dozent_quiz',
			'post_title'   => $title,
			'post_content' => $quiz_content,
			'post_status'  => 'publish',
			'post_author'  => get_current_user_id(),
			'post_parent'  => $section_id,
		];

		if ( $item_id ) {
			$item                   = get_post( $item_id );
			$post_arr['ID']         = $item_id;
			$post_arr['menu_order'] = $item->menu_order;
		} else {
			$menu_order_id          = dozent_get_next_curriculum_item_order_id( $course_id );
			$post_arr['menu_order'] = $menu_order_id;
		}

		$quiz_id = wp_insert_post( $post_arr );
		if ( $quiz_id ) {
			update_post_meta( $quiz_id, '_dozent_course_id', $course_id );

			//Register Action Hooks
			do_action( 'dozent/quiz/saved', $quiz_id, $course_id, $post_arr );
			if ( $item_id ) {
				do_action( 'dozent/quiz/updated', $quiz_id, $course_id, $post_arr );
			} else {
				do_action( 'dozent/quiz/created', $quiz_id, $course_id, $post_arr );
			}

			$quiz_options = dozent_input_array_field( 'quiz_option' );
			update_post_meta( $quiz_id, '_quiz_option', $quiz_options );
		}

		ob_start();
		include DOZENT_ABSPATH . 'views/course_builder/curriculum.php';
		$course_contents = ob_get_clean();

		wp_send_json_success( [ 'quiz_id' => $quiz_id, 'curriculum' => $course_contents ] );
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.