MASTERSTUDY_QUIZPASSED::quiz_passed( $user_id,  $quiz_id,  $user_quiz_progress )

Validation function when the trigger action is hit


Parameters Parameters

$data

(Required)


Source Source

File: src/integrations/masterstudy-lms/triggers/masterstudy-quizpassed.php

	public function quiz_passed( $user_id, $quiz_id, $user_quiz_progress ) {



		$args = [
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => $quiz_id,
			'user_id' => $user_id,
		];

		$args = Automator()->maybe_add_trigger_entry( $args, false );

		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {

					$source    = ( ! empty( $_POST['source'] ) ) ? intval( $_POST['source'] ) : '';
					$course_id = ( ! empty( $_POST['course_id'] ) ) ? intval( $_POST['course_id'] ) : '';
					$course_id = apply_filters( 'user_answers__course_id', $course_id, $source );

					Automator()->insert_trigger_meta(
						[
							'user_id'        => $user_id,
							'trigger_id'     => $result['args']['trigger_id'],
							'meta_key'       => 'MSLMSCOURSE',
							'meta_value'     => $course_id,
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						]
					);

					Automator()->insert_trigger_meta(
						[
							'user_id'        => $user_id,
							'trigger_id'     => $result['args']['trigger_id'],
							'meta_key'       => $this->trigger_meta . '_SCORE',
							'meta_value'     => $user_quiz_progress . '%',
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						]
					);

					Automator()->insert_trigger_meta(
						[
							'user_id'        => $user_id,
							'trigger_id'     => $result['args']['trigger_id'],
							'meta_key'       => $this->trigger_meta,
							'meta_value'     => $quiz_id,
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						]
					);
					Automator()->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}