UNCANNYCEUS_AWARDCEUS::award_ceus( $user_id,  $action_data,  $recipe_id,  $args )

Validation function when the trigger action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)


Source Source

File: src/integrations/uncanny-ceus/actions/uncannyceus-awardceus.php

	public function award_ceus( $user_id, $action_data, $recipe_id, $args ) {

		$date   = Automator()->parse->text( $action_data['meta']['AWARDCEUSDATE'], $recipe_id, $user_id, $args );
		$course = Automator()->parse->text( $action_data['meta']['AWARDCEUSCOURSE'], $recipe_id, $user_id, $args );
		$ceus   = absint( Automator()->parse->text( $action_data['meta']['AWARDCEUS'], $recipe_id, $user_id, $args ) );
		// convert date from user input to accepted input
		$date = date( "F d Y, g:i:s a", strtotime( $date ) );
		$data = [
			'course'       => 0, // It is not a real course
			'customCourse' => $course, // The fake course to save data against
			'date'         => $date, // date to store CEU fon in format F d Y, g:i:s a
			'ceus'         => $ceus // the amount of CEUs
		];
		// The class contains all ceu creation code
		$award_cert_class = \uncanny_ceu\Utilities::get_class_instance( 'AwardCertificate' );
		$version = \uncanny_ceu\Utilities::get_version();
		if ( version_compare( $version, '3.0.7', '>' ) ) {
			$course_data   = $data = [
				'user'             => new \WP_User( $user_id ),
				'course'           => null,
				'course_completed' => 0,
				'custom_course'    => $course,
				'custom_date'      => $date,
				'custom_ceus'      => $ceus,
				'custom_creation'  => true,
			];
			$returned_data = $award_cert_class->learndash_course_completed( $course_data );
		} else {
			//* @deprecated CEUs 3.1
			$returned_data = $award_cert_class->learndash_before_course_completed( $user_id, 'manual-ceu', true, $data );
		}

		$error = '';
		if ( isset( $returned_data->success ) && false === $returned_data->success ) {
			$error = $returned_data->error;
		}
		Automator()->complete_action( $user_id, $action_data, $recipe_id, $error );
		return;
	}