Automator_DB_Handler_Triggers::is_completed( int|null $user_id = null, int|null $trigger_id = null, int|null $recipe_id = null, int|null $recipe_log_id = null, bool $process_recipe = false, array $args = array() )


Parameters Parameters

$user_id

(int|null) (Optional)

Default value: null

$trigger_id

(int|null) (Optional)

Default value: null

$recipe_id

(int|null) (Optional)

Default value: null

$recipe_log_id

(int|null) (Optional)

Default value: null

$process_recipe

(bool) (Optional)

Default value: false

$args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(bool|null)


Source Source

File: src/core/lib/utilities/db/class-automator-db-handler-triggers.php

	public function is_completed( int $user_id = null, int $trigger_id = null, int $recipe_id = null, int $recipe_log_id = null, bool $process_recipe = false, array $args = array() ) {
		// Set user ID
		if ( is_null( $user_id ) ) {
			$user_id = get_current_user_id();
		}

		if ( null === $trigger_id || ! is_numeric( $trigger_id ) ) {
			Automator()->error->add_error( 'is_trigger_completed', 'ERROR: You are trying to check if a trigger is completed without providing a trigger_id', $this );

			return null;
		}

		if ( null === $recipe_id || ! is_numeric( $recipe_id ) ) {
			Automator()->error->add_error( 'is_trigger_completed', 'ERROR: You are trying to check if a trigger is completed without providing a recipe_id', $this );

			return null;
		}

		global $wpdb;
		$table_name = $wpdb->prefix . Automator()->db->tables->trigger;
		if ( $process_recipe ) {
			$q = "SELECT completed FROM $table_name
						WHERE user_id = %d
						AND automator_trigger_id = %d
						AND automator_recipe_id = %d
						AND automator_recipe_log_id = %d";
		} else {
			$q = "SELECT t.completed AS trigger_completed
							FROM $table_name t
							LEFT JOIN {$wpdb->prefix}uap_recipe_log r
							ON t.automator_recipe_log_id = r.ID
							LEFT JOIN {$wpdb->prefix}uap_action_log a
							ON t.automator_recipe_log_id = a.automator_recipe_log_id
							WHERE 1=1
							AND t.user_id = %d
							AND t.automator_trigger_id = %d
							AND t.automator_recipe_id = %d
							AND t.automator_recipe_log_id = %d
							AND r.completed = 1
							AND a.completed = 1";
		}
		$results = $wpdb->get_var( $wpdb->prepare( $q, $user_id, $trigger_id, $recipe_id, $recipe_log_id ) ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

		if ( ! empty( $results ) ) {
			return true;
		}

		return false;
	}