dozent_get_statements( int $user_id, array $filter_data = array() )

Get the earning statements by calling this funcitons


Description

$statements = dozent_get_statements( $user_id, [ ‘year’ => 2020, ‘dataFor’ => ‘yearly’, ‘per_page’ => 10, ‘offset’ => 0 ] ); $statements = dozent_get_statements( $user_id, [ ‘start_date’ => ‘2020-01-01’, ‘start_date’ => ‘2020-01-31’, ‘per_page’ => 10, ‘offset’ => 0 ] );


Parameters

$user_id

(int) (Required)

$filter_data

(array) (Optional)

Default value: array()


Return

(object)


Source

File: includes/user-functions.php

	function dozent_get_statements( $user_id = 0, $filter_data = [] ) {
		global $wpdb;

		$user_sql = "";
		if ( $user_id ) {
			$user_sql = " AND user_id='{$user_id}' ";
		}

		$date_query       = '';
		$query_by_status  = '';
		$pagination_query = '';

		/**
		 * query statemtns by filtering date
		 */

		if ( dozent_count( $filter_data ) ) {
			extract( $filter_data );

			if ( ! empty( $dataFor ) ) {
				if ( $dataFor === 'yearly' ) {
					if ( empty( $year ) ) {
						$year = date( 'Y' );
					}
					$date_query = "AND YEAR(created_at) = {$year} ";
				}
			} else {
				$date_query = " AND (created_at BETWEEN '{$start_date}' AND '{$end_date}') ";
			}

			/**
			 * Query statements by related order status
			 */

			if ( ! empty( $statuses ) ) {
				if ( dozent_count( $statuses ) ) {
					$status          = "'" . implode( "','", $statuses ) . "'";
					$query_by_status = "AND order_status IN({$status})";
				} elseif ( $statuses === 'completed' ) {

					$get_earnings_completed_statuses = dozent_get_earnings_completed_statuses();
					if ( dozent_count( $get_earnings_completed_statuses ) ) {
						$status          = "'" . implode( "','", $get_earnings_completed_statuses ) . "'";
						$query_by_status = "AND order_status IN({$status})";
					}
				}
			}

			if ( ! empty( $per_page ) ) {
				$offset = (int) ! empty( $offset ) ? $offset : 0;

				$pagination_query = " LIMIT {$offset}, {$per_page}  ";
			}

		}

		$query = $wpdb->get_results( "SELECT earnings.*, course.post_title as course_title
					FROM {$wpdb->dozent_earnings} earnings
					LEFT JOIN {$wpdb->posts} course ON earnings.course_id = course.ID
                    WHERE 1=1 {$user_sql} {$date_query} {$query_by_status} ORDER BY created_at DESC {$pagination_query} " );

		$query_count = (int) $wpdb->get_var( "SELECT COUNT(earnings.ID)
					FROM {$wpdb->dozent_earnings} earnings
                    WHERE 1=1 {$user_sql} {$date_query} {$query_by_status} ORDER BY created_at DESC " );

		return (object) [
			'count'   => $query_count,
			'results' => $query,
		];
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.