UNCANNYCEUS_EARNSCEUS::updated_user_ceu_record( $current_user,  $is_manual_creation,  $completion_date,  $current_course_id,  $current_course_title,  $course_slug,  $ceu_value )


Parameters Parameters

$current_user

(Required)

$is_manual_creation

(Required)

$completion_date

(Required)

$current_course_id

(Required)

$current_course_title

(Required)

$course_slug

(Required)

$ceu_value

(Required)


Source Source

File: src/integrations/uncanny-ceus/triggers/uncannyceus-earnsceus.php

	public function updated_user_ceu_record( $current_user, $is_manual_creation, $completion_date, $current_course_id, $current_course_title, $course_slug, $ceu_value ) {



		// The class contains all ceu creation code
		$ceu_shortcodes = \uncanny_ceu\Utilities::get_class_instance( 'CeuShortcodes' );

		$atts       = [ 'user-id' => $current_user->ID ];
		$total_ceus = absint( $ceu_shortcodes->uo_ceu_total( $atts ) );
		$ceu_value  = absint( $ceu_value );

		if ( ! $total_ceus || ! $ceu_value ) {
			return;
		}

		// Get all recipes that have this trigger
		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
		// Get the specific WPFFORUMID meta data from the recipes
		$require_ceu_amount = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );
		$matched_recipe_ids = array();

		// Loop through recipe
		foreach ( $recipes as $recipe_id => $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {

				$trigger_id = $trigger['ID'];
				$ceu_amount = $require_ceu_amount[ $recipe_id ][ $trigger_id ];

				if ( $total_ceus >= absint( $ceu_amount ) ) {
					$matched_recipe_ids[] = [
						'recipe_id'  => $recipe_id,
						'trigger_id' => $trigger_id,
					];
				}
			}
		}

		if ( ! empty( $matched_recipe_ids ) ) {
			foreach ( $matched_recipe_ids as $matched_recipe_id ) {
				$pass_args = [
					'code'             => $this->trigger_code,
					'meta'             => $this->trigger_meta,
					'user_id'          => $current_user->ID,
					'recipe_to_match'  => $matched_recipe_id['recipe_id'],
					'trigger_to_match' => $matched_recipe_id['trigger_id'],
					'ignore_post_id'   => true,
					'is_signed_in'     => true,
				];

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

				if ( $args ) {
					foreach ( $args as $result ) {
						if ( true === $result['result'] ) {
							Automator()->maybe_trigger_complete( $result['args'] );
						}
					}
				}
			}

		}
	}