Submissions_List_Table::build_query_params( int $number, int $offset )

Builds query parameters for the current request.

Description

Parameters

$number

(int) (Required) Maximum number of models to query.

$offset

(int) (Required) Offset to query models.

Return

(array) Associative array of query parameters.

Source

File: src/db-objects/submissions/submissions-list-table.php

	protected function build_query_params( $number, $offset ) {
		$query_params = parent::build_query_params( $number, $offset );

		$capabilities = $this->manager->capabilities();

		if ( isset( $_REQUEST['form_id'] ) ) {
			$query_params['form_id'] = absint( $_REQUEST['form_id'] );
		}

		if ( ! $capabilities || ! $capabilities->current_user_can( 'edit_others_items' ) || ! $capabilities->current_user_can( 'read_others_items' ) ) {
			$query_params['user_id'] = get_current_user_id();
		} elseif ( isset( $_REQUEST['user_id'] ) ) {
			$query_params['user_id'] = absint( $_REQUEST['user_id'] );
		}

		if ( ! empty( $_REQUEST['status'] ) ) {
			$query_params['status'] = array_map( 'sanitize_key', (array) $_REQUEST['status'] );
		}

		if ( ! empty( $_REQUEST['m'] ) ) {
			$year =  (int) substr( $_REQUEST['m'], 0, 4 );
			$month = (int) substr( $_REQUEST['m'], 4, 2 );

			$yearmonth = '' . $year . '-' . $month;
			if ( 12 === $month ) {
				$next_yearmonth = '' . ( $year + 1 ) . '-01';
			} else {
				$next_yearmonth = '' . $year . '-' . ( $month + 1 );
			}

			$query_params['timestamp'] = array(
				'greater_than' => (int) strtotime( $yearmonth . '-01' ),
				'lower_than'   => (int) strtotime( $next_yearmonth . '-01' ) - 1,
				'inclusive'    => true,
			);
		}

		$default_orderby = 'timestamp';
		$default_order = 'DESC';
		if ( isset( $_REQUEST['orderby'] ) && isset( $_REQUEST['order'] ) ) {
			$query_params['orderby'] = array( $_REQUEST['orderby'] => $_REQUEST['order'] );
		} elseif ( isset( $_REQUEST['orderby'] ) ) {
			$query_params['orderby'] = array( $_REQUEST['orderby'] => $default_order );
		} elseif ( isset( $_REQUEST['order'] ) ) {
			$query_params['orderby'] = array( $default_orderby => $_REQUEST['order'] );
		} else {
			$query_params['orderby'] = array( $default_orderby => $default_order );
		}

		return $query_params;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.