WPCW_MODULECOMPLETED::wpcw_module_completed( $user_id,  $unit_id,  $parent )

Validation function when the trigger action is hit


Parameters Parameters

$user_id

(Required)

$unit_id

(Required)

$parent

(Required) AssociatedParentData


Source Source

File: src/integrations/wp-courseware/triggers/wpcw-modulecompleted.php

	public function wpcw_module_completed( $user_id, $unit_id, $parent ) {

		if ( empty( $user_id ) ) {
			return;
		}



		$module_id = $parent->parent_module_id;

		$args = [
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => intval( $module_id ),
			'user_id' => $user_id,
		];
		$args = Automator()->maybe_add_trigger_entry( $args, false );

		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {
					$trigger_meta = [
						'user_id'        => $user_id,
						'trigger_id'     => $result['args']['trigger_id'],
						'trigger_log_id' => $result['args']['get_trigger_id'],
						'run_number'     => $result['args']['run_number'],
					];

					$trigger_meta['meta_key']   = $this->trigger_meta;
					$trigger_meta['meta_value'] = $module_id;
					Automator()->insert_trigger_meta( $trigger_meta );
					Automator()->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}