BP_Document_Folder: get (数组args美元数组()

获取由参数指定的文件夹。

描述

参数

args美元

数组(可选)一个参数数组。所有项目都是可选的

默认值:数组()

返回

(数组)返回的数组有两个键:- 'total'是已定位文档的计数- 'folders'是已定位文档的数组

文件:bp-document /类/ class-bp-document-folder.php

公共静态函数get($ args = array()){global $ wpdb;$ bp = buddypress();$ r = wp_parse_args($ args,array('页'=> 1,//当前页面。'per_page'=> 20,//每页文件夹。'max'=> false,// max的项目数返回。“字段”=>“所有”,//字段包含。'排序'=>'desc',// ASC或DESC。'ORDER_BY'=>'date_created',//列订购。'排除'=> false,// ids数组排除。'search_terms'=> false,//按搜索的术语。'user_id'=> false,//用户标识。'group_id'=> false,//组ID.'privacy' => false, // public, loggedin, onlyme, friends, grouponly. 'count_total' => false, // Whether or not to use count_total. 'in' => false, // Array of ids to limit query by (IN). 'meta_query' => false, // Filter by foldermeta. ) ); // Select conditions. $select_sql = 'SELECT DISTINCT f.id'; $from_sql = " FROM {$bp->document->table_name_folder} f"; $join_sql = ''; // Where conditions. $where_conditions = array(); // Searching. if ( $r['search_terms'] ) { $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%'; $where_conditions['search_sql'] = $wpdb->prepare( 'f.title LIKE %s', $search_terms_like ); /** * Filters whether or not to include users for search parameters. * * @param bool $value Whether or not to include user search. Default false. * * @since BuddyBoss 1.4.0 */ if ( apply_filters( 'bp_document_folder_get_include_user_search', false ) ) { $user_search = get_user_by( 'slug', $r['search_terms'] ); if ( false !== $user_search ) { $user_id = $user_search->ID; $where_conditions['search_sql'] .= $wpdb->prepare( ' OR f.user_id = %d', $user_id ); } } } // Sorting. $sort = $r['sort']; if ( 'ASC' !== $sort && 'DESC' !== $sort ) { $sort = 'DESC'; } switch ( $r['order_by'] ) { case 'id': case 'user_id': case 'group_id': case 'title': break; default: $r['order_by'] = 'date_created'; break; } $order_by = 'f.' . $r['order_by']; // Exclude specified items. if ( ! empty( $r['exclude'] ) ) { $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) ); $where_conditions['exclude'] = "f.id NOT IN ({$exclude})"; } // The specific ids to which you want to limit the query. if ( ! empty( $r['in'] ) ) { $in = implode( ',', wp_parse_id_list( $r['in'] ) ); $where_conditions['in'] = "f.id IN ({$in})"; } if ( ! empty( $r['user_id'] ) ) { $where_conditions['user'] = "f.user_id = {$r['user_id']}"; } if ( ! empty( $r['group_id'] ) ) { $where_conditions['user'] = "f.group_id = {$r['group_id']}"; } if ( ! empty( $r['privacy'] ) ) { $privacy = "'" . implode( "', '", $r['privacy'] ) . "'"; $where_conditions['privacy'] = "f.privacy IN ({$privacy})"; } // Process meta_query into SQL. $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] ); if ( ! empty( $meta_query_sql['join'] ) ) { $join_sql .= $meta_query_sql['join']; } /** * Filters the MySQL WHERE conditions for the folders get method. * * @param array $where_conditions Current conditions for MySQL WHERE statement. * @param array $r Parsed arguments passed into method. * @param string $select_sql Current SELECT MySQL statement at point of execution. * @param string $from_sql Current FROM MySQL statement at point of execution. * @param string $join_sql Current INNER JOIN MySQL statement at point of execution. * * @since BuddyBoss 1.4.0 */ $where_conditions = apply_filters( 'bp_document_folder_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql ); if ( empty( $where_conditions ) ) { $where_conditions['2'] = '2'; } // Join the where conditions together. $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); /** * Filter the MySQL JOIN clause for the main document query. * * @param string $join_sql JOIN clause. * @param array $r Method parameters. * @param string $select_sql Current SELECT MySQL statement. * @param string $from_sql Current FROM MySQL statement. * @param string $where_sql Current WHERE MySQL statement. * * @since BuddyBoss 1.4.0 */ $join_sql = apply_filters( 'bp_document_folder_get_join_sql', $join_sql, $r, $select_sql, $from_sql, $where_sql ); // Sanitize page and per_page parameters. $page = absint( $r['page'] ); $per_page = absint( $r['per_page'] ); $retval = array( 'folders' => null, 'total' => null, 'has_more_items' => null, ); // Query first for folder IDs. $folder_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY {$order_by} {$sort}, f.id {$sort}"; if ( ! empty( $per_page ) && ! empty( $page ) ) { // We query for $per_page + 1 items in order to // populate the has_more_items flag. $folder_ids_sql .= $wpdb->prepare( ' LIMIT %d, %d', absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); } /** * Filters the paged document MySQL statement. * * @param string $folder_ids_sql MySQL statement used to query for Document IDs. * @param array $r Array of arguments passed into method. * * @since BuddyBoss 1.4.0 */ $folder_ids_sql = apply_filters( 'bp_document_folder_paged_activities_sql', $folder_ids_sql, $r ); $cache_group = 'bp_document_folder'; $cached = bp_core_get_incremented_cache( $folder_ids_sql, $cache_group ); if ( false === $cached ) { $folder_ids = $wpdb->get_col( $folder_ids_sql ); // db call ok; no-cache ok; bp_core_set_incremented_cache( $folder_ids_sql, $cache_group, $folder_ids ); } else { $folder_ids = $cached; } $retval['has_more_items'] = ! empty( $per_page ) && count( $folder_ids ) > $per_page; // If we've fetched more than the $per_page value, we // can discard the extra now. if ( ! empty( $per_page ) && count( $folder_ids ) === $per_page + 1 ) { array_pop( $folder_ids ); } if ( 'ids' === $r['fields'] ) { $folders = array_map( 'intval', $folder_ids ); } else { $folders = self::get_folder_data( $folder_ids ); } if ( 'ids' !== $r['fields'] ) { // Get the fullnames of users so we don't have to query in the loop. // $albums = self::append_user_fullnames( $albums ); // Pre-fetch data associated with document users and other objects. $folders = self::prefetch_object_data( $folders ); } $retval['folders'] = $folders; // If $max is set, only return up to the max results. if ( ! empty( $r['count_total'] ) ) { /** * Filters the total document MySQL statement. * * @param string $value MySQL statement used to query for total documents. * @param string $where_sql MySQL WHERE statement portion. * @param string $sort Sort direction for query. * * @since BuddyBoss 1.4.0 */ $total_folders_sql = apply_filters( 'bp_document_folder_total_documents_sql', "SELECT count(DISTINCT f.id) FROM {$bp->document->table_name_folder} f {$join_sql} {$where_sql}", $where_sql, $sort ); $cached = bp_core_get_incremented_cache( $total_folders_sql, $cache_group ); if ( false === $cached ) { $total_folders = $wpdb->get_var( $total_folders_sql ); // db call ok; no-cache ok; bp_core_set_incremented_cache( $total_folders_sql, $cache_group, $total_folders ); } else { $total_folders = $cached; } if ( ! empty( $r['max'] ) ) { if ( (int) $total_folders > (int) $r['max'] ) { $total_folders = $r['max']; } } $retval['total'] = $total_folders; } return $retval; }

更新日志

更新日志
版本 描述
BuddyBoss 1.4.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队