dozent_get_withdrawals( int $user_id, array $args = array() )

Get all withdrawals requested by user


Description

This function returns all withdrawals data from the database. By passing status as array as second param, you can filter the data more specifically If no $user_id as first param, it will show all users withdrawals

Example usage:

 $args = array(
     'status'      => [ 'pending', 'completed', 'rejected' ],
     'start'         => 0,
     'per_page'      => 10,
 )

$withdrawals = dozent_get_withdrawals( $user_id, $args );

See also


Parameters

$user_id

(int) (Required) User or Instructor ID

$args

(array) (Optional)

Default value: array()


Return

(object)


Source

File: includes/earning-functions.php

	function dozent_get_withdrawals( $user_id = 0, $args = [] ) {
		global $wpdb;

		$default_per_page = dozent_show_per_page();
		$current_page     = (int) dozent_input_text( 'current_page' );
		$page             = max( 1, $current_page );
		$start            = ( $page - 1 ) * $default_per_page;

		$defaults = apply_filters( 'dozent_get_withdrawals_default_args', [
			'status'   => [ 'pending', 'completed', 'rejected' ],
			'start'    => $start,
			'per_page' => $default_per_page,
		] );

		$r = wp_parse_args( $args, $defaults );
		extract( $r, EXTR_SKIP );

		$query_by_status_sql = "";
		$query_by_user_sql   = "";
		$query_by_pagination = "";

		if ( ! empty( $status ) ) {
			$status = (array) $status;
			$status = "'" . implode( "','", $status ) . "'";

			$query_by_status_sql = " AND status IN({$status}) ";
		}

		if ( ! empty( $per_page ) ) {
			if ( empty( $start ) ) {
				$start = 0;
			}

			$query_by_pagination = " LIMIT {$start}, {$per_page} ";
		}

		if ( $user_id ) {
			$query_by_user_sql = " AND user_id = {$user_id} ";
		}

		$search_term_sql = '';
		if ( ! empty( $search_term ) ){
			$search_term_sql = " AND ( user_tbl.display_name LIKE '%{$search_term}%' OR user_tbl.user_email LIKE '%{$search_term}%' ) ";
		}

		$count = (int) $wpdb->get_var( "SELECT COUNT(withdraw_id) 
		FROM {$wpdb->dozent_withdrawal} withdraw_tbl 
		INNER JOIN {$wpdb->users} user_tbl ON withdraw_tbl.user_id = user_tbl.ID
		WHERE 1=1 $search_term_sql {$query_by_user_sql} {$query_by_status_sql} " );

		$results = $wpdb->get_results( "SELECT withdraw_tbl.*, 
		user_tbl.display_name as user_name, 
		user_tbl.user_email 
		FROM {$wpdb->dozent_withdrawal} withdraw_tbl 
		INNER JOIN {$wpdb->users} user_tbl ON withdraw_tbl.user_id = user_tbl.ID
		WHERE 1=1 
		{$search_term_sql}
		{$query_by_user_sql} 
		{$query_by_status_sql} ORDER BY created_at DESC  {$query_by_pagination} " );

		$response = [
			'count'   => $count,
			'results' => $results,
		];

		return (object) $response;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.