BP_Document_Template::__construct( array $args )

Constructor method.

Description

The arguments passed to this class constructor are of the same format as BP_Document::get().

See also

  • BP_Document::get(): for a description of the argument structure, as well as default values.

Parameters

$args

(Required) Array of arguments. Supports all arguments from BP_Document::get(), as well as 'page_arg' and 'include'. Default values for 'per_page' differ from the originating function, and are described below

Source

File: bp-document/classes/class-bp-document-template.php

	public function __construct( $args ) {

		$defaults = array(
			'page'                => 1,
			'per_page'            => 20,
			'page_arg'            => 'acpage',
			'max'                 => false,
			'fields'              => 'all',
			'count_total'         => false,
			'sort'                => false,
			'order_by'            => false,
			'include'             => false,
			'exclude'             => false,
			'search_terms'        => false,
			'scope'               => false,
			'user_id'             => false,
			'folder_id'           => false,
			'group_id'            => false,
			'privacy'             => false,
			'folder'              => true,
			'user_directory'      => true,
			'meta_query_document' => false,
			'meta_query_folder'   => false,
			'meta_query'          => false
		);

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

		$this->pag_arg  = sanitize_key( $r['page_arg'] );
		$this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
		$this->pag_num  = bp_sanitize_pagination_arg( 'num', $r['per_page'] );

		// Get an array of the logged in user's favorite document.
		$this->my_favs = bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_document', true );

		// Fetch specific document items based on ID's.
		if ( ! empty( $include ) ) {

			$this->documents = bp_document_get_specific(
				array(
					'document_ids'   => ( ! is_array( $include ) ? explode( ',', $include ) : $include ),
					'max'            => $max,
					'count_total'    => $count_total,
					'page'           => $this->pag_page,
					'per_page'       => $this->pag_num,
					'sort'           => $sort,
					'order_by'       => $order_by,
					'user_id'        => $user_id,
					'folder_id'      => $folder_id,
					'folder'         => $folder,
					'user_directory' => $user_directory,
					'meta_query'     => $meta_query,
				)
			);

			// Fetch all activity items.
		} else {
			$this->documents = bp_document_get(
				array(
					'max'                 => $max,
					'count_total'         => $count_total,
					'per_page'            => $this->pag_num,
					'page'                => $this->pag_page,
					'sort'                => $sort,
					'order_by'            => $order_by,
					'search_terms'        => $search_terms,
					'scope'               => $scope,
					'user_id'             => $user_id,
					'folder_id'           => $folder_id,
					'group_id'            => $group_id,
					'exclude'             => $exclude,
					'privacy'             => $privacy,
					'folder'              => $folder,
					'user_directory'      => $user_directory,
					'meta_query_document' => $meta_query_document,
					'meta_query_folder'   => $meta_query_folder
				)
			);
		}

		// The total_document_count property will be set only if a
		// 'count_total' query has taken place.
		if ( ! is_null( $this->documents['total'] ) ) {
			if ( ! $max || $max >= (int) $this->documents['total'] ) {
				$this->total_document_count = (int) $this->documents['total'];
			} else {
				$this->total_document_count = (int) $max;
			}
		}

		$this->has_more_items = $this->documents['has_more_items'];

		$this->documents = $this->documents['documents'];

		if ( $max ) {
			if ( $max >= count( $this->documents ) ) {
				$this->document_count = count( $this->documents );
			} else {
				$this->document_count = (int) $max;
			}
		} else {
			$this->document_count = count( $this->documents );
		}

		if ( (int) $this->total_document_count && (int) $this->pag_num ) {
			$this->pag_links = paginate_links(
				array(
					'base'      => add_query_arg( $this->pag_arg, '%#%' ),
					'format'    => '',
					'total'     => ceil( (int) $this->total_document_count / (int) $this->pag_num ),
					'current'   => (int) $this->pag_page,
					'prev_text' => __( '←', 'buddyboss' ),
					'next_text' => __( '→', 'buddyboss' ),
					'mid_size'  => 1,
					'add_args'  => array(),
				)
			);
		}
	}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.